March 16, 2016
termutils
¶
Convenience functions for working with Terms and Graphs.
normalizeGraph()
¶
-
rdfextras.utils.termutils.
normalizeGraph
(graph)[source]¶ Takes an instance of a
Graph
and returns the instance’s identifier andtype
.Types are
U
for aGraph
,F
for aQuotedGraph
andB
for aConjunctiveGraph
>>> from rdflib import plugin >>> from rdflib.graph import Graph, ConjunctiveGraph, QuotedGraph >>> from rdflib.store import Store >>> from rdflib import URIRef, Namespace >>> from rdfextras.utils.termutils import normalizeGraph >>> memstore = plugin.get('IOMemory', Store)() >>> g = Graph(memstore, URIRef("http://purl.org/net/bel-epa/gjh")) >>> normalizeGraph(g) (rdflib.term.URIRef(u'http://purl.org/net/bel-epa/gjh'), 'U') >>> g = ConjunctiveGraph( ... memstore, URIRef("http://purl.org/net/bel-epa/gjh")) ... >>> normalizeGraph(g) (rdflib.term.URIRef(u'http://purl.org/net/bel-epa/gjh'), 'U') >>> g = QuotedGraph(memstore, Namespace("http://purl.org/net/bel-epa/gjh")) >>> normalizeGraph(g) (Namespace(u'http://purl.org/net/bel-epa/gjh'), 'F')
term2Letter()
¶
-
rdfextras.utils.termutils.
term2Letter
(term)[source]¶ Relate a given term to one of several key types:
BNode
,Literal
,Statement
URIRef
,Variable
Graph
QuotedGraph
>>> import rdflib >>> from rdflib import plugin >>> from rdflib import URIRef, Namespace >>> from rdflib.term import BNode, Literal, Variable, Statement >>> from rdflib.graph import Graph, ConjunctiveGraph, QuotedGraph >>> from rdflib.store import Store >>> from rdfextras.utils.termutils import term2Letter >>> term2Letter(URIRef('http://purl.org/net/bel-epa.com/')) 'U' >>> term2Letter(BNode()) 'B' >>> term2Letter(Literal(u'')) 'L' >>> term2Letter(Variable(u'x')) 'V' >>> term2Letter(Graph()) 'B' >>> term2Letter(QuotedGraph("IOMemory", None)) 'F' >>> term2Letter(None) 'L' >>> term2Letter(Statement((None, None, None), None)) 's'
constructGraph()
¶
-
rdfextras.utils.termutils.
constructGraph
(key)[source]¶ Given a key (one of ‘F’, ‘U’ or ‘B’), returns a tuple containing a
Graph
and an appropriate referent.>>> from rdfextras.utils.termutils import constructGraph >>> constructGraph('F') (<class 'rdflib.graph.QuotedGraph'>, <class 'rdflib.term.URIRef'>) >>> constructGraph('U') (<class 'rdflib.graph.Graph'>, <class 'rdflib.term.URIRef'>) >>> constructGraph('B') (<class 'rdflib.graph.Graph'>, <class 'rdflib.term.BNode'>)