May 02, 2015

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 and type.

Types are U for a Graph, F for a QuotedGraph and B for a ConjunctiveGraph

>>> 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:

>>> 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'>)

triplePattern2termCombinations()

rdfextras.utils.termutils.triplePattern2termCombinations((s, p, o))[source]

Maps a triple pattern to term combinations (non-functioning)

type2TermCombination()

rdfextras.utils.termutils.type2TermCombination(member, klass, context)[source]

Maps a type to a TermCombo

statement2TermCombination()

rdfextras.utils.termutils.statement2TermCombination(subject, predicate, obj, context)[source]

Maps a statement to a Term Combo

Table Of Contents

Previous topic

Utilities

Next topic

graphutils