View Source Guesswork.Answer (Guesswork v0.8.0)

Answers are maps of variable id to bindings as well as any tests that must be checked.

Summary

Functions

Takes an answer set and removes any binding not passed to the function.

Takes an answer set and removes any constraint with inputs not passed to the function.

Extracts the displayable information from the answer set, returning a simple map.

Pulls all bound, concrete values from the answer set.

Removes all internal variables that are not currently in use by the constraint store.

Removes all constraints for which the inputs are in the bindings. No constraints are resolved, only removed.

Resolves both tests and computations as well as checking if the stop conditions have been met and the answer stream should halt.

Replaces all bound variables using the variable id to variable map.

Takes an answer and traverses all entities, looking for specific solutions.

Takes an answer and traverses the entities stored in the supplied variables, looking for specific solutions.

Takes two answer sets and attempts to take the union of them. If any variables point to contradicting values the process will fail and return nil.

Types

bindings()

@type bindings() :: %{required(String.t()) => Guesswork.Answer.Binding.t()}

t()

@type t() :: %Guesswork.Answer{
  bindings: bindings(),
  constraints: Guesswork.Constraint.Store.t(),
  query_id: String.t() | nil
}

Functions

filter_bindings(answer, kept_ids)

@spec filter_bindings(t() | :halt, MapSet.t(String.t())) :: t() | :halt

Takes an answer set and removes any binding not passed to the function.

:halts are passed through to facilitate stop conditions.

filter_constraints(answer, kept_ids)

@spec filter_constraints(t() | :halt, MapSet.t(Guesswork.Ast.Variable.t())) ::
  t() | :halt

Takes an answer set and removes any constraint with inputs not passed to the function.

:halts are passed through to facilitate stop conditions.

flatten(answer)

@spec flatten(t()) :: %{required(String.t()) => Guesswork.Answer.Result.value()}

Extracts the displayable information from the answer set, returning a simple map.

get_env(answer)

@spec get_env(t()) :: Guesswork.Ast.Statement.env()

Pulls all bound, concrete values from the answer set.

new(query_id \\ nil)

@spec new(String.t() | nil) :: t()

put_binding(answer, variable, value, negated)

@spec put_binding(
  t(),
  Guesswork.Ast.Variable.t(),
  Guesswork.Ast.Entity.t(),
  boolean()
) ::
  {:ok, t()} | :error

put_constraint(answer, constraint, bool)

@spec put_constraint(t(), Guesswork.Constraint.t(), boolean()) :: t()

remove_internal_variables(answer)

@spec remove_internal_variables(t()) :: t()

Removes all internal variables that are not currently in use by the constraint store.

remove_resolvable_constraints(answer)

@spec remove_resolvable_constraints(t()) :: t()

Removes all constraints for which the inputs are in the bindings. No constraints are resolved, only removed.

resolve(answer)

@spec resolve(t() | :halt) :: t() | :halt | nil

Resolves both tests and computations as well as checking if the stop conditions have been met and the answer stream should halt.

:halts are passed through to facilitate stop conditions.

resolve_constraints(answer, env)

@spec resolve_constraints(t(), Guesswork.Ast.Statement.env()) :: t() | nil | :halt

substitue_variables(answer, var_map)

@spec substitue_variables(t() | :halt, %{
  required(String.t()) => Guesswork.Ast.Variable.t()
}) ::
  t() | :halt

Replaces all bound variables using the variable id to variable map.

:halts are passed through to facilitate stop conditions.

traverse_entities(answer)

@spec traverse_entities(t()) :: Enumerable.t(t())

Takes an answer and traverses all entities, looking for specific solutions.

Note that this is very similar to labeling.

traverse_entities(answer, variables)

@spec traverse_entities(t(), MapSet.t(String.t())) :: Enumerable.t(t())

Takes an answer and traverses the entities stored in the supplied variables, looking for specific solutions.

Note that this is very similar to labeling.

union(arg1, arg2)

@spec union(t() | :halt, t() | :halt) :: t() | nil | :halt

Takes two answer sets and attempts to take the union of them. If any variables point to contradicting values the process will fail and return nil.

:halts are passed through to facilitate stop conditions.