Skip to content

Compiler

Compiler

Bases: ABC

Abstract base class for compilers.

context property

The current KIF context.

Error

Bases: Error

Base class for compiler errors.

compile() abstractmethod

Runs the compiler.

Returns:

  • Self

    Compiler.

get_context(context=None)

Gets the current KIF context.

If context is not None, returns context.

Parameters:

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

    Context.

Returns:

SPARQL_Compiler

Bases: Compiler

Abstract base class for SPARQL compilers.

debug property

Whether debugging is enabled.

default_options property

The default options of compiler.

omega property

The maximum number of disjoint queries to generate.

q property

The current query (top of query stack).

query property

The current query (top of query stack).

query_stack property

The compiled query stack.

Query

Bases: SelectQuery

The type of queries generated by the SPARQL compiler.

as_qvar(var) classmethod

Constructs query variable from variable.

Parameters:

Returns:

  • Variable

    Query variable.

as_qvars(var, *vars) classmethod

Constructs one or more query variables from variables.

Parameters:

Returns:

  • Iterator[Variable]

    Iterator of query variables.

as_safe_qvar(var) classmethod

Constructs query variable from variable (safe).

If variable is not of a primitive type, raises an error.

Returns:

  • Variable

    Query variable.

as_safe_qvars(var, *vars) classmethod

Constructs one or more query variables from variables (safe).

If one of the variables is not of a primitive type, raises an error.

Parameters:

Returns:

  • Iterator[Variable]

    Iterator of query variables.

bnode() classmethod

Alias of :meth:Query.bnode.

fresh_data_value_var()

Constructs a fresh data-value variable.

Returns:

  • DataValueVariable

    Data-value variable.

fresh_deep_data_value_var()

Constructs a fresh deep data-value variable.

Returns:

  • DeepDataValueVariable

    Deep data-value variable.

fresh_entity_var()

Constructs a fresh entity variable.

Returns:

  • EntityVariable

    Entity variable.

fresh_external_id_var()

Constructs a fresh external-id variable.

Returns:

  • ExternalIdVariable

    External id variable.

fresh_iri_var()

Constructs a fresh IRI variable.

Returns:

  • IRI_Variable

    IRI variable.

fresh_item_var()

Constructs a fresh item variable.

Returns:

  • ItemVariable

    Item variable.

fresh_lexeme_var()

Constructs a fresh lexeme variable.

Returns:

  • LexemeVariable

    Lexeme variable.

fresh_property_var()

Constructs a fresh property variable.

Returns:

  • PropertyVariable

    Property variable.

fresh_qualifier_record_var()

Constructs a fresh qualifier record variable.

Returns:

  • QualifierRecordVariable

    Qualifier record variable.

fresh_quantity_var()

Constructs a fresh quantity variable.

Returns:

  • QuantityVariable

    Quantity variable.

fresh_qvar()

Constructs a fresh query variable.

Returns:

  • Variable

    Query variable.

fresh_qvars(n)

Constructs one or more fresh query variables.

Returns:

  • Iterator[Variable]

    Iterator of variables.

fresh_rank_var()

Constructs a fresh rank variable.

Returns:

  • RankVariable

    Rank variable.

fresh_reference_record_set_var()

Constructs a fresh reference record set variable.

Returns:

  • ReferenceRecordSetVariable

    Reference record set variable.

fresh_shallow_data_value_var()

Constructs a fresh shallow data-value variable.

Returns:

  • ShallowDataValueVariable

    Shallow data-value variable.

fresh_string_var()

Constructs a fresh string variable.

Returns:

  • StringVariable

    String variable.

fresh_text_var()

Constructs a fresh text variable.

Returns:

  • TextVariable

    Text variable.

fresh_time_var()

Constructs a fresh time variable.

Returns:

  • TimeVariable

    Time variable.

fresh_var(variable_class)

Constructs a fresh variable of the given class.

Parameters:

Returns:

fresh_vars(variable_class, n)

Constructs one or more fresh variables of the given class.

Parameters:

Returns:

  • Iterator[Variable]

    Iterator of variables.

get_debug()

Gets the debug flag.

Returns:

  • bool

    Debug flag.

get_default_options(context=None)

Gets the default options of compiler.

Parameters:

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

    Context.

Returns:

  • SPARQL_CompilerOptions

    Compiler options.

get_omega()

Gets the maximum number of disjoint queries to generate.

Returns:

  • int

    Maximum number of disjoint queries.

get_query()

Gets the current query (top of query stack).

Returns:

get_query_stack()

Get the compiled query stack.

Returns:

  • Sequence[Query]

    Query stack.

literal(content, language=None, datatype=None) classmethod

Alias of :meth:Query.literal.

pop_query()

Pops query from query stack.

Returns:

  • Query

    The popped query.

push_query(query=None)

Pushes query onto query stack.

If query is None, pushes an empty query.

Returns:

  • Query

    The pushed query.

qvar(name) classmethod

Alias of :meth:Query.var.

qvars(var, *vars) classmethod

Alias of :meth:Query.vars.

uri(content) classmethod

Alias of :meth:Query.uri.

SPARQL_FilterCompiler

Bases: SPARQL_Compiler

SPARQL filter compiler

entry property

The entry associated with current frame.

filter property

The (normalized) source filter.

frame property

The current frame.

mapping property

The SPARQL mapping.

pattern property

The source pattern.

phase property

The compilation phase associated with the current frame.

targets property

The target patterns associated with current frame.

theta property

The substitution associated with the current frame.

Frame

Bases: TypedDict

Compilation frame (context).

Phase

Bases: Enum

Compilation phases.

Projection

Bases: Flag

Statement projection mask.

build_query(query, projection=None, distinct=None, limit=None, offset=None)

Constructs a filter query.

Parameters:

  • query (Query) –

    Query.

  • projection (Projection | None, default: None ) –

    Projection mask.

  • distinct (bool | None, default: None ) –

    Whether to enable the distinct modifier.

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

    Limit.

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

    Offset.

Returns:

  • Query

    Filter query.

build_results()

Constructs a compilation result builder.

Returns:

  • Callable[[SPARQL_ResultsBinding], Iterable[Theta] | None]

    A function to convert a binding in SPARQL results into variable

  • Callable[[SPARQL_ResultsBinding], Iterable[Theta] | None]

    instantiations (thetas).

get_entry()

Gets the entry associated with current frame.

Returns:

  • Entry

    SPARQL mapping entry.

get_filter()

Gets the (normalized) source filter.

Returns:

get_frame()

Gets the current frame.

Returns:

get_mapping()

Gets the SPARQL mapping.

Returns:

get_pattern()

Gets the source pattern.

Returns:

  • Pattern

    Pattern.

get_phase()

Gets the compilation phase associated with the current frame.

Returns:

  • Phase

    Compilation phase.

get_targets()

Gets the target patterns associated with current frame.

Returns:

  • Sequence[EntryPattern]

    Sequence of SPARQL mapping entry patterns.

get_theta()

Gets the substitution associated with the current frame.

Returns:

  • Substitution

    Substitution.

is_compiling_filter()

Tests whether compiler is in "compiling filter" phase.

Returns:

  • bool

    True if successful; False otherwise.

is_compiling_fingerprint()

Tests whether compiler is in "compiling fingerprint" phase.

Returns:

  • bool

    True if successful; False otherwise.

is_done()

Tests whether compiler is in "done" phase.

Returns:

  • bool

    True if successful; False otherwise.

is_ready()

Tests whether compiler is in "ready" phase.

Returns:

  • bool

    True if successful; False otherwise.

pop_frame()

Pops the current compilation frame.

Returns:

  • Frame

    The popped frame.

push_frame(phase, entry=None, theta=None, targets=None)

Pushes a new compilation frame making it the current frame.

phase: Compilation phase. entry: Mapping entry. theta: Substitution. targets: Mapping entry patterns.

Returns:

  • Frame

    The pushed frame.

theta_add(variable, value)

Adds variable-value pair to the current substitution.

Parameters:

  • variable (Variable) –

    Variable.

  • value (T) –

    Value.

Returns:

  • T

    Value.

theta_add_as_qvar(variable)

Adds variable-query variable to the current substitution.

Parameters:

Returns:

  • Variable

    Query variable.

theta_add_default(variable, value)

Sets default value for variable in the current substitution.

Parameters:

  • variable (Variable) –

    Variable.

  • value (Term | None) –

    Value.

Returns: