March 16, 2016 .. currentmodule:: rdfextras.sparql.graph
graph
- SPARQL Graph¶
-
class
rdfextras.sparql.graph.
SPARQLGraph
(graph, graphVariable=None, dSCompliance=False)[source]¶ A subclass of Graph with a few extra SPARQL bits.
-
cluster
(seed)[source]¶ Cluster up and down, by summing up the forward and backward clustering
Parameters: seed – RDFLib Resource Returns: The SPARQLGraph
triple store containing the cluster
-
clusterBackward
(seed, Cluster=None)[source]¶ Cluster the triple store: from a seed, transitively get all properties and objects ‘backward’, ie, following the link back in the graph.
Parameters: - seed – RDFLib Resource
- Cluster – another sparqlGraph instance; if None, a new one will be created. The subgraph will be added to this graph.
Returns: The
SPARQLGraph
triple store containing the cluster
-
clusterForward
(seed, Cluster=None)[source]¶ Cluster the triple store: from a seed, transitively get all properties and objects in direction of the arcs.
Parameters: - seed – RDFLib Resource
- Cluster – another sparqlGraph instance; if None, a new one will be created. The subgraph will be added to this graph.
Returns: The
SPARQLGraph
triple store containing the cluster
-
-
class
rdfextras.sparql.graph.
GraphPattern
(patterns=[])[source]¶ Storage of one Graph Pattern, ie, the pattern tuples and the possible (functional) constraints (filters)
-
addConstraint
(func)[source]¶ Add a global filter constraint to the graph pattern. ‘func’ must be a method with a single input parameter (a dictionary) returning a boolean. This method is I{added} to previously added methods, ie, I{all} methods must return True to accept a binding.
Parameters: func – filter function
-
addConstraints
(lst)[source]¶ Add a list of global filter constraints to the graph pattern. Each function in the list must be a method with a single input parameter (a dictionary) returning a boolean. These methods are I{added} to previously added methods, ie, I{all} methods must return True to accept a binding.
Parameters: lst – list of functions
-
addPattern
(tupl)[source]¶ Append a tuple to the local patterns. Possible type literals are converted to real literals on the fly. Each tuple should be contain either 3 elements (for an RDF Triplet pattern) or four, where the fourth element is a per-pattern constraint (filter). (The general constraint of SPARQL can be optimized by assigning a constraint to a specific pattern; because it stops the graph expansion, its usage might be much more optimal than the the ‘global’ constraint).
Parameters: tupl – either a three- or four-element tuple
-
addPatterns
(lst)[source]¶ Append a list of tuples to the local patterns. Possible type literals are converted to real literals on the fly. Each tuple should be contain either three elements (for an RDF Triplet pattern) or four, where the fourth element is a per-pattern constraint. (The general constraint of SPARQL can be optimized by assigning a constraint to a specific pattern; because it stops the graph expansion, its usage might be much more optimal than the the ‘global’ constraint).
Parameters: lst – list consisting of either a three- or four-element tuples
-
construct
(tripleStore, bindings)[source]¶ Add triples to a tripleStore based on a variable bindings of the patterns stored locally. The triples are patterned by the current Graph Pattern. The method is used to construct a graph after a successful querying.
Parameters: - tripleStore – an (rdflib) Triple Store
- bindings – dictionary
-
insertPattern
(tupl)[source]¶ Insert a tuple to to the start of local patterns. Possible type literals are converted to real literals on the fly. Each tuple should be contain either 3 elements (for an RDF Triplet pattern) or four, where the fourth element is a per-pattern constraint (filter). (The general constraint of SPARQL can be optimized by assigning a constraint to a specific pattern; because it stops the graph expansion, its usage might be much more optimal than the the ‘global’ constraint).
Semantically, the behaviour induced by a graphPattern does not depend on the order of the patterns. However, due to the behaviour of the expansion algorithm, users may control the speed somewhat by adding patterns that would ‘cut’ the expansion tree soon (ie, patterns that reduce the available triplets significantly). API users may be able to do that, hence this additional method.
Parameters: tupl – either a three- or four-element tuple
-
insertPatterns
(lst)[source]¶ Insert a list of tuples to the start of the local patterns. Possible type literals are converted to real literals on the fly. Each tuple should be contain either three elements (for an RDF Triplet pattern) or four, where the fourth element is a per-pattern constraint. (The general constraint of SPARQL can be optimized by assigning a constraint to a specific pattern; because it stops the graph expansion, its usage might be much more optimal than the the ‘global’ constraint).
Semantically, the behaviour induced by a graphPattern does not depend on the order of the patterns. However, due to the behaviour of the expansion algorithm, users may control the speed somewhat by adding patterns that would ‘cut’ the expansion tree soon (ie, patterns that reduce the available triplets significantly). API users may be able to do that, hence this additional method.
Parameters: lst – list consisting of either a three- or four-element tuples
-
-
class
rdfextras.sparql.graph.
BasicGraphPattern
(patterns=[], prolog=None)[source]¶ One justified, problem with the current definition of
GraphPattern
is that it makes it difficult for users to use a literal of the type?XXX
, because any string beginning with?
will be considered to be an unbound variable. The only way of doing this is that the user explicitly creates ardflib.term.Literal
object and uses that as part of the pattern.This class is a superclass of
GraphPattern
which does not do this, but requires the usage of a separate variable class instance