View Source Guesswork.Ast.Fact (Guesswork v0.5.0)

A fact is just a relationship (string) and some entities (concrete or non-concrete) and states that the relationship hold for those values in that order.

Summary

Functions

Extracts the relationship name and arity.

Takes two facts and attempt to 'match' them by ensuring that their relationships match, all concrete terms match, and then binding any variables to the opposite entity. Returns nil if the match fails, an answer set if it succeeds.

Attempts to substitute the values in the second fact for any variables in the first. Returns nil if the relation doesn't match, any concrete entities don't match, or if the second fact attempts to substitute a variable for a concrete value.

Types

@type metadata() :: {String.t(), integer()}
@type t() :: %Guesswork.Ast.Fact{
  args: [Guesswork.Ast.Term.entity() | Guesswork.Ast.Variable.t()],
  arity: integer(),
  relationship: String.t()
}

Functions

@spec get_metadata(t()) :: metadata()

Extracts the relationship name and arity.

Link to this function

match(fact1, fact2, query_id)

View Source
@spec match(t(), t(), String.t()) :: nil | Guesswork.Answer.t()

Takes two facts and attempt to 'match' them by ensuring that their relationships match, all concrete terms match, and then binding any variables to the opposite entity. Returns nil if the match fails, an answer set if it succeeds.

Note that the same concrete fact matched on itself will result in an empty answer set, and that variables cannot match variables.

Link to this function

substitute(fact1, fact2)

View Source
@spec substitute(t(), t()) :: Guesswork.Ast.Statement.env() | nil

Attempts to substitute the values in the second fact for any variables in the first. Returns nil if the relation doesn't match, any concrete entities don't match, or if the second fact attempts to substitute a variable for a concrete value.