algebraixlib.util.rdf module

RDF-specific data manipulation facilities.

The code is RDF/SPARQL-inspired but does not officially implement any RDF standards.

Glossary

triple
A function with three members, with the left components 's', 'p', 'o'. A generic triple is an element of \(P(A \times M)\); an RDF triple is an element of \(P(A \times A)\). (See also set A and set M.)
graph
A clan where every relation it contains is a triple. A generic graph is an element of \(P^2(A \times M)\); an RDF graph is an element of \(P^2(A \times A)\). (See also set A and set M.)

API

algebraixlib.util.rdf.is_file_url(path_or_url: str) → bool[source]

Return True if path_or_url is a file URL, False if not.

As valid file URL we consider any URL that starts with 'file://').

algebraixlib.util.rdf.get_file_url(path: str) → str[source]

Return the file URL that corresponds to the file path path.

If path is relative, it is converted into an absolute path before being converted into a file URL.

algebraixlib.util.rdf.is_triple(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a valid triple, False if not.

algebraixlib.util.rdf.is_absolute_triple(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is an absolute triple, False if not.

algebraixlib.util.rdf.make_triple()[source]

Return an RDF triple, created from subject, predicate and object_.

Each of the arguments must be an instance of MathObject or a Python type that automatically converts to an Atom in the Couplet constructor.

algebraixlib.util.rdf.is_graph(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a graph, False if not.

algebraixlib.util.rdf.is_absolute_graph(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is an absolute graph, False if not.

algebraixlib.util.rdf.triple_match()[source]

Evaluate SPARQL-like triple pattern matches.

Treat string values for subject, predicate, object that begin with '?' or '$' similarly to SPARQL variables; they define the projection (output) lefts. Other values are used for matching.

Parameters:
  • rdf_graph – The graph on which to operate.
  • subject – Handle the subjects in rdf_graph: a variable name (create output), a value that’s not a variable name (match) or None (ignore).
  • predicate – Handle the predicates in rdf_graph: a variable name (create output), a value that’s not a variable name (match) or None (ignore).
  • object – Handle the objects in rdf_graph: a variable name (create output), a value that’s not a variable name (match) or None (ignore).
Returns:

A clan with the matches.

algebraixlib.util.rdf.join(rdf_solution1, rdf_solution2, *rdf_solutions)[source]

Return the cross-functional union of all arguments.

This is a thin wrapper around clans.cross_functional_union().

algebraixlib.util.rdf.match_and_project()[source]

Return all relations in graph that contain all members of pattern. Rename their lefts according to the members of projection.

Parameters:
  • graph – An absolute clan.
  • pattern – A dictionary where the keys are the lefts and the values the rights that will be matched.
  • projection – A dictionary where the values are the new names and the keys the existing names of the lefts to be renamed.
algebraixlib.util.rdf.pattern_match()[source]

Return all relations in graph that contain all members of pattern.

Parameters:
  • graph – An absolute clan.
  • pattern – A dictionary where the keys are the lefts and the values the rights that will be matched.