Skip to content

KIF Object

Object

Bases: Generic[Unpack[Ts]]

Abstract base class for syntactical objects.

args property

The arguments of object.

digest property

The digest of object.

Error

Bases: Exception

Base class for errors.

KeepType

Type for the sentinel of :meth:Object.replace.

MissingDependency

Bases: ImportError

Missing dependency.

NilType

Type for absence of value distinct from NoneType.

ShouldNotGetHere

Bases: RuntimeError

Should not get here.

check(arg, function=None, name=None, position=None) classmethod

Coerces arg into an instance of this class.

If arg cannot be coerced, raises an error.

Parameters:

  • arg (Any) –

    Value.

  • function (TLoc | None, default: None ) –

    Function or function name.

  • name (str | None, default: None ) –

    Argument name.

  • position (int | None, default: None ) –

    Argument position.

Returns:

  • Self

    Object.

check_optional(arg, default=None, function=None, name=None, position=None) classmethod

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 (Any | None) –

    Value.

  • default (Any | None, default: None ) –

    Default value.

  • function (TLoc | None, default: None ) –

    Function or function name.

  • name (str | None, default: None ) –

    Argument name.

  • position (int | None, default: None ) –

    Argument position.

Returns:

  • Self | None

    Object or default.

copy()

Makes a shallow copy of object.

Returns:

  • Self

    A shallow copy of object.

deepcopy(memo=None)

Makes a deep copy of object.

Parameters:

  • memo (dict[Any, Any] | None, default: None ) –

    Dictionary of objects already copied.

Returns:

  • Self

    A deep copy of object.

dump(stream, format=None, **kwargs)

Encodes object and writes the result to stream.

Parameters:

  • stream (IO[Any]) –

    A .write()-supporting file-like object.

  • format (str | None, default: None ) –

    Encoding format.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

dumps(format=None, **kwargs)

Encodes object and returns the resulting string.

Parameters:

  • format (str | None, default: None ) –

    Encoding format.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • str

    String.

from_ast(ast) classmethod

Converts abstract syntax tree to object.

Parameters:

  • ast (Mapping[str, Any]) –

    Abstract syntax tree.

Returns:

  • Self

    Object.

from_json(input, **kwargs) classmethod

Decodes string using JSON decoder.

Parameters:

  • input (str) –

    Input string.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • Self

    Object.

from_repr(input, **kwargs) classmethod

Decodes string using repr decoder.

Parameters:

  • input (str) –

    Input string.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • Self

    Object.

from_sexp(input, **kwargs) classmethod

Decodes string using S-expression decoder.

Parameters:

  • input (str) –

    Input string.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • Self

    Object.

get(i, default=None)

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

If argument's value is None, returns default.

Returns:

  • Any | None

    Argument's value.

get_args()

Gets the arguments of object.

Returns:

  • tuple[Unpack[Ts]]

    Arguments.

get_digest()

Gets the digest of object.

Returns:

  • str

    Digest.

load(stream, format=None, **kwargs) classmethod

Decodes stream and returns the resulting object.

Parameters:

  • stream (IO[Any]) –

    A .read()-supporting file-like object.

  • format (str | None, default: None ) –

    Decoding format.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • Self

    Object.

loads(input, format=None, **kwargs) classmethod

Decodes string and returns the resulting object.

Parameters:

  • input (str) –

    String.

  • format (str | None, default: None ) –

    Decoding format.

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • Self

    Object.

replace(*args, **kwargs)

Shallow-copies object overwriting its arguments.

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

Parameters:

  • args (Any, default: () ) –

    Arguments.

  • kwargs (Any, default: {} ) –

    Keyword arguments (ignored).

Returns:

  • Self

    A shallow copy of object.

test(arg) classmethod

Tests whether arg is an instance of this class.

Returns:

  • bool

    True if successful; False otherwise.

to_ast()

Converts object to abstract syntax tree.

Returns:

to_json(**kwargs)

Encodes object using JSON encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • str

    String.

to_repr(**kwargs)

Encodes object using repr encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • str

    String.

to_sexp(**kwargs)

Encodes object using S-expression encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Other keyword arguments.

Returns:

  • str

    String.

KIF_Object

Bases: Object[Unpack[Ts]]

Abstract base class for KIF objects.

context property

The current KIF context.

from_sparql(s, **kwargs) classmethod

Decodes string using SPARQL decoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Options to SPARQL decoder.

Returns:

  • Self

    KIF object.

Raises:

  • `DecoderError`

    Decoder error.

get_context(context=None) classmethod

Gets the current KIF context.

If context is not None, returns context.

Parameters:

  • context (Context | None, default: None ) –

    Context.

Returns:

substitute(sigma)

Applies substitution sigma to KIF object's arguments.

Parameters:

  • sigma (Mapping[Any, Any] | Callable[[Any], Any]) –

    Substitution.

Returns:

  • Self

    KIF object.

to_dot(**kwargs)

Encodes object using Dot encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Options to Dot encoder.

Returns:

  • str

    String.

Raises:

  • `EncoderError`

    Encoder error.

to_markdown(**kwargs)

Encodes object using Markdown encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Options to Markdown encoder.

Returns:

  • str

    String.

Raises:

  • `EncoderError`

    Encoder error.

to_rdf(**kwargs)

Encodes object using RDF encoder.

Parameters:

  • kwargs (Any, default: {} ) –

    Options to RDF encoder.

Returns:

  • str

    String.

Raises:

  • `EncoderError`

    Encoder error.

traverse(filter=None, visit=None)

Traverses KIF object-tree recursively.

Parameters:

  • filter (Callable[[Any], bool] | None, default: None ) –

    Predicate indicating KIF objects or values to yield.

  • visit (Callable[[Any], bool] | None, default: None ) –

    Predicate indicating KIF objects to visit.

Returns:

  • Iterator[Any]

    An iterator of KIF objects and values.

Error = object.Object.Error module-attribute