KIF_Object

class KIF_Object(*args: Any)[source]

Bases: Object

Abstract base class for KIF objects.

property context: Context

The current KIF context.

get_context(context: Context | None = None) Context[source]

Gets the current KIF context.

If context is not None, returns context.

Returns:

Context.

classmethod from_sparql(s: str, **kwargs: Any) Self[source]

Decodes string using SPARQL decoder.

Parameters:

kwargs – Options to SPARQL decoder.

Returns:

Object.

Raises:

DecoderError – Decoder error.

to_markdown(**kwargs: Any) str[source]

Encodes object using Markdown encoder.

Parameters:

kwargs – Options to Markdown encoder.

Returns:

String.

Raises:

EncoderError – Encoder error.

traverse(filter: Callable[[Any], bool] | None = None, visit: Callable[[Any], bool] | None = None) Iterator[Any][source]

Traverses KIF object-tree recursively.

Parameters:
  • filter – Predicate indicating KIF objects or values to yield.

  • visit – Predicate indicating KIF objects to visit.

Returns:

An iterator of KIF objects and values.

class Object(*args: Any)[source]

Bases: Sequence

Abstract base class for syntactical objects.

exception Error[source]

Bases: Exception

Base class for errors.

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.

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

Coerces optional arg into an instance of this class.

If arg cannot be coerced, raises an error.

If arg is None, returns default.

Parameters:
  • arg – Value.

  • default – Default value.

  • function – Function or function name.

  • name – Argument name.

  • position – Argument position.

Returns:

Object or default.

abstract __init__(*args: Any) None[source]
property args: tuple[Any, ...]

The arguments of object.

get_args() tuple[Any, ...][source]

Gets the arguments of object.

Returns:

Arguments.

get(i: int, default: Any | None = None) Any | None[source]

Gets the value of the i-th argument of object (origin 0).

If argument’s value is None, returns default.

Returns:

Argument’s value.

property digest: str

The digest of object.

get_digest() str[source]

Gets the digest of object.

Returns:

Digest.

copy() Self[source]

Makes a shallow copy of object.

Returns:

A shallow copy of object.

deepcopy(memo: dict[Any, Any] | None = None) Self[source]

Makes a deep copy of object.

Parameters:

memo – Dictionary of objects already copied.

Returns:

A deep copy of object.

class KEEP[source]

Bases: object

See Object.replace().

replace(*args: Any) Self[source]

Shallow-copies object overwriting its arguments.

If argument is Object.KEEP in args, keeps the value of the corresponding argument in the resulting object.

Parameters:

args – Arguments.

Returns:

A shallow copy of object.

to_ast() dict[str, Any][source]

Converts object to abstract syntax tree.

Returns:

Dictionary.

classmethod from_ast(ast: Mapping[str, Any]) Self[source]

Converts abstract syntax tree to object.

Parameters:

ast – Abstract syntax tree.

Returns:

Object.

dump(stream: IO[Any], format: str | None = None, **kwargs: Any) None[source]

Encodes object and writes the result to stream.

Parameters:
  • stream – A .write()-supporting file-like object.

  • format – Encoding format.

  • kwargs – Encoder options.

dumps(format: str | None = None, **kwargs: Any) str[source]

Encodes object and returns the resulting string.

Parameters:
  • format – Encoding format.

  • kwargs – Encoder options.

Returns:

String.

classmethod load(stream: IO[Any], format: str | None = None, **kwargs) Self[source]

Decodes stream and returns the resulting object.

Parameters:
  • stream – A .read()-supporting file-like object.

  • format – Decoding format.

  • kwargs – Decoder options.

Returns:

Object.

classmethod loads(input: str, format: str | None = None, **kwargs) Self[source]

Decodes string and returns the resulting object.

Parameters:
  • input – String.

  • format – Decoding format.

  • kwargs – Options to decoder.

Returns:

Object.

classmethod from_json(input: str, **kwargs: Any) Self[source]

Decodes string using JSON decoder.

Parameters:
  • input – Input string.

  • kwargs – Options to decoder.

Returns:

Object.

to_json(**kwargs: Any) str[source]

Encodes object using JSON encoder.

Parameters:

kwargs – Options to encoder.

Returns:

String.

classmethod from_repr(input: str, **kwargs: Any) Self[source]

Decodes string using repr decoder.

Parameters:
  • input – Input string.

  • kwargs – Options to decoder.

Returns:

Object.

to_repr(**kwargs: Any) str[source]

Encodes object using repr encoder.

Parameters:

kwargs – Options to encoder.

Returns:

String.

classmethod from_sexp(input: str, **kwargs: Any) Self[source]

Decodes string using S-expression decoder.

Parameters:
  • input – Input string.

  • kwargs – Options to decoder.

Returns:

Object.

to_sexp(**kwargs: Any) str[source]

Encodes object using S-expression encoder.

Parameters:

kwargs – Options to encoder.

Returns:

String.

exception ShouldNotGetHere[source]

Bases: RuntimeError

Should not get here.