RDF Model#
Oxigraph provides python classes to represents basic RDF concepts:
IRIs#
- class pyoxigraph.NamedNode(value)#
An RDF node identified by an IRI.
- Parameters:
value (str) – the IRI as a string.
- Raises:
ValueError – if the IRI is not valid according to RFC 3987.
The
str()
function provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(NamedNode('http://example.com')) '<http://example.com>'
Blank Nodes#
- class pyoxigraph.BlankNode(value=None)#
An RDF blank node.
- Parameters:
value (str or None, optional) – the blank node ID (if not present, a random blank node ID is automatically generated).
- Raises:
ValueError – if the blank node ID is invalid according to NTriples, Turtle, and SPARQL grammars.
The
str()
function provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(BlankNode('ex')) '_:ex'
- value#
- Returns:
the blank node ID.
- Return type:
>>> BlankNode("ex").value 'ex'
Literals#
- class pyoxigraph.Literal(value, *, datatype=None, language=None)#
An RDF literal.
- Parameters:
value (str) – the literal value or lexical form.
datatype (NamedNode or None, optional) – the literal datatype IRI.
language (str or None, optional) – the literal language tag.
- Raises:
ValueError – if the language tag is not valid according to RFC 5646 (BCP 47).
The
str()
function provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Literal('example')) '"example"' >>> str(Literal('example', language='en')) '"example"@en' >>> str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer'))) '"11"^^<http://www.w3.org/2001/XMLSchema#integer>'
- datatype#
- Returns:
the literal datatype IRI.
- Return type:
>>> Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer')).datatype <NamedNode value=http://www.w3.org/2001/XMLSchema#integer> >>> Literal('example').datatype <NamedNode value=http://www.w3.org/2001/XMLSchema#string> >>> Literal('example', language='en').datatype <NamedNode value=http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>
- language#
- Returns:
the literal language tag.
- Return type:
str or None
>>> Literal('example', language='en').language 'en' >>> Literal('example').language
- value#
- Returns:
the literal value or lexical form.
- Return type:
>>> Literal("example").value 'example'
Triples#
- class pyoxigraph.Triple(subject, predicate, object)#
An RDF triple.
- Parameters:
The
str()
function provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) '<http://example.com> <http://example.com/p> "1"'
A triple could also be easily destructed into its components:
>>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))
- object#
-
>>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).object <Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>
- predicate#
- Returns:
the triple predicate.
- Return type:
>>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).predicate <NamedNode value=http://example.com/p>
Quads (triples in a RDF dataset)#
- class pyoxigraph.Quad(subject, predicate, object, graph_name=None)#
An RDF triple. in a RDF dataset.
- Parameters:
subject (NamedNode or BlankNode or Triple) – the quad subject.
predicate (NamedNode) – the quad predicate.
object (NamedNode or BlankNode or Literal or Triple) – the quad object.
graph_name (NamedNode or BlankNode or DefaultGraph or None, optional) – the quad graph name. If not present, the default graph is assumed.
The
str()
function provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) '<http://example.com> <http://example.com/p> "1" <http://example.com/g>'
>>> str(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), DefaultGraph())) '<http://example.com> <http://example.com/p> "1"'
A quad could also be easily destructed into its components:
>>> (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))
- graph_name#
- Returns:
the quad graph name.
- Return type:
NamedNode or BlankNode or DefaultGraph
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).graph_name <NamedNode value=http://example.com/g>
- object#
-
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).object <Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>
- predicate#
- Returns:
the quad predicate.
- Return type:
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).predicate <NamedNode value=http://example.com/p>
- subject#
-
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject <NamedNode value=http://example.com>
- triple#
- Returns:
the quad underlying triple.
- Return type:
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).triple <Triple subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>>
- class pyoxigraph.DefaultGraph#
The RDF default graph name.