Term

class Term(*args: Any, **kwargs: Any)[source]

Bases: KIF_Object

Abstract base class for terms.

exception InstantiationError[source]

Bases: ValueError

Bad instantiation attempt.

classmethod is_closed(arg: Any) bool[source]

Tests whether argument is a closed term.

Returns:

True if successful; False otherwise.

classmethod is_open(arg: Any) bool[source]

Tests whether argument is an open term.

Returns:

True if successful; False otherwise.

classmethod unify(*eqs: tuple[Term, Term]) Theta | None[source]

Computes an instantiation that unifies term equations.

Parameters:

eqs – Pairs of terms (potential equations).

Returns:

A variable instantiation theta if successful; None otherwise.

property variables: Set[Variable]

The set of variables occurring in term.

get_variables() Set[Variable][source]

Gets the set of variables occurring in term.

Returns:

Set of variables.

instantiate(theta: Theta, coerce: bool = True, strict: bool = False) Term | None[source]

Applies variable instantiation theta to term.

Parameters:
  • theta – Variable instantiation.

  • coerce – Whether to consider coercible variables equal.

  • strict – Whether to adopt stricter coercion rules.

Returns:

Term or None.

match(other: Term) Theta | None[source]

Tests whether term matches other.

If term matches other, returns a variable instantiation theta that can be used to unify both term and other. Otherwise, return None.

Parameters:

other – Term.

Returns:

A variable instantiation theta if successful; None otherwise.

generalize(exclude: Iterable[Term | str] = (), rename: Callable[[str], Iterator[str]] | None = None, prefix: str | None = None) Self[source]

Replaces None values occurring in term by fresh variables.

Picks name variants not occurring in exclude.

Uses rename (if given) to generate name variants.

Uses prefix (if given) as prefix for name variants.

Parameters:
  • exclude – Name variant exclusion list.

  • rename – Name variant generator.

  • prefix – Name variant prefix.

Returns:

Term.

rename(exclude: Iterable[Term | str] = (), rename: Callable[[str], Iterator[str]] | None = None) Self[source]

Renames all variables occurring in term.

Picks name variants not occurring in exclude.

Uses rename (if given) to generate name variants.

Parameters:
  • exclude – Name exclusion list.

  • rename – Name variant generator.

Returns:

Term.

class ClosedTerm(*args: Any, **kwargs: Any)[source]

Bases: Term

Abstract base class for closed (ground) terms.

template_class: ClassVar[type[Template]]

Template class associated with this closed-term class.

variable_class: ClassVar[type[Variable]]

Variable class associated with this closed-term class.

instantiate(theta: Theta, coerce: bool = True, strict: bool = False) Term[source]

Applies variable instantiation theta to term.

Parameters:
  • theta – Variable instantiation.

  • coerce – Whether to consider coercible variables equal.

  • strict – Whether to adopt stricter coercion rules.

Returns:

Term or None.

class OpenTerm(*args: Any, **kwargs: Any)[source]

Bases: Term

Abstract base class for open terms.

object_class: ClassVar[type[ClosedTerm]]

Closed-term class associated with this open-term class.

class Template(*args: Any, **kwargs: Any)[source]

Bases: OpenTerm

Abstract base class for templates.

object_class: ClassVar[type[ClosedTerm]]

Object class associated with this template class.

instantiate(theta: Mapping[Variable, Term | None], coerce: bool = True, strict: bool = False) Term[source]

Applies variable instantiation theta to term.

Parameters:
  • theta – Variable instantiation.

  • coerce – Whether to consider coercible variables equal.

  • strict – Whether to adopt stricter coercion rules.

Returns:

Term or None.

class Variable(name: str | None = None, variable_class: type[Variable] | type[Term] | None = None)[source]

Bases: OpenTerm

Base class for variables.

Parameters:
  • name – Name or None (fresh name).

  • variable_class – Variable class.

classmethod check(arg: Any, function: Callable[[...], Any] | str | None = None, name: str | None = None, position: int | None = None) Self[source]

Coerces arg into an instance of this class.

If arg cannot be coerced, raises an error.

Parameters:
  • arg – Value.

  • function – Function or function name.

  • name – Argument name.

  • position – Argument position.

Returns:

Object.

__init__(name: str | None = None, object_class: type[Term] | None = None) None[source]
property name: str

The name of variable.

get_name() str[source]

Gets the name of variable.

Returns:

Name.

coerce(variable_class: type[Variable] | type[Term] | None = None) Self[source]

Coerces variable into variable_class.

If variable cannot be coerced, raises an error.

Parameters:

variable_class – Variable class.

Returns:

Variable.