franz.openrdf.model package

Submodules

franz.openrdf.model.utils module

franz.openrdf.model.utils.parse_term(string_term)

Given a string representing a term in ntriples format, return a URI, Literal, or BNode.

Module contents

class franz.openrdf.model.BNode(id=None)

Bases: Resource

A blank node.

__init__(id=None)

Create a blank node.

Parameters:

id – Node identifier, if not supplied one will be generated.

getID()

Get the identifier of this blank node.

getId()

Get the identifier of this blank node.

getValue()

Get the identifier of this blank node.

get_cmp_key()

Return a key that will be used to compare and hash this object.

id
toNTriples()

Return an NTriples representation of an open rdf term

to_json_ld()

Converts to an object to be used as a JSON-LD value.

to_json_ld_key()

Converts to a string to be used as a JSON-LD key.

class franz.openrdf.model.Literal(label, datatype=None, language=None)

Bases: Value

Implementation of the Literal class.

__init__(label, datatype=None, language=None)
booleanValue()

Convert to bool

calendarValue()

calendarValue not useful for Python.

property datatype

The URI representing the datatype for this literal, if there is one

dateValue()

Convert to date

datetimeValue()

Convert to datetime

decimalValue()

Convert to a decimal

floatValue()

Convert to float

getDatatype()

The URI representing the datatype for this literal, if there is one

getLabel()

The label/value for this Literal

getLanguage()

The language for this Literal

getValue()

The label/value

get_cmp_key()

Return a key that will be used to compare and hash this object.

intValue()

Convert to int

property label

The label/value for this Literal

property language

The language for this Literal

longValue()

Convert to long

setDatatype(datatype)

Sets the datatype of the value

setLabel(label)

Set the label for this Literal

setLanguage(language)

Set the language for this Literal

timeValue()

Convert to time

toNTriples()

Return an NTriples representation for this Literal.

toPython()

Return a Python object representation of this literal. Slightly silly implementation because we implement a conversion table and then don’t use the conversion functions.

to_json_ld()

Converts to an object to be used as a JSON-LD value.

class franz.openrdf.model.QuotedTriple(subject: Value, predicate: Value, object: Value)

Bases: Resource

RDF-star quoted triples.

__init__(subject: Value, predicate: Value, object: Value)
getObject()
getPredicate()
getSubject()
get_cmp_key()

Return a key that will be used to compare and hash this object.

toNTriples()

Return an NTriples representation of an open rdf term

class franz.openrdf.model.Statement(subject, predicate, object, context=None, id=None)

Bases: object

Wraps a triple or a quad. Might also contain an id.

__init__(subject, predicate, object, context=None, id=None)

Create a statement.

Each component can be either a Value object or a string in N-Triples format. Strings will be parsed lazily the first time a component is accessed. Accessors will always return Value objects.

Parameters:
  • subject (URI|BNode|str) – Subject component - URI, blank node, QuotedTriple or a string in N-Triples format.

  • predicate (URI|str) – Predicate component. Either a URI, QuotedTriple or a string in N-Triples format.

  • object (Value|str) – Subject component. Either a Value or a string in N-Triples format.

  • context (URI|str) – Graph component (optional). Can be a URI or a string in N-Triples format.

  • id (int|str) – Statement id (optional).

context
getContext()

Get the graph (the fourth, optional element of the statement).

Returns:

Graph URI.

Return type:

URI

getObject()

Get the object (the third element of the statement).

Returns:

Object.

Return type:

Value

getPredicate()

Get the predicate (the second element of the statement).

Returns:

Predicate.

Return type:

URI

getSubject()

Get the subject (the first element of the statement).

Returns:

Subject.

Return type:

Value

getTripleID()

Get the statement id.

Note that this field might not present, depending on the way in which the statement has been created.

Returns:

A numerical id.

Return type:

int

id
object
predicate
setContext(context)
setObject(object)
setPredicate(predicate)
setSubject(subject)
subject
class franz.openrdf.model.URI(uri=None, namespace=None, localname=None, canonical=True)

Bases: Resource

Lightweight implementation of the class ‘URI’.

__init__(uri=None, namespace=None, localname=None, canonical=False)
getLocalName()
getNamespace()
getURI()

Return the URI (string) for ‘self’. This method is typically overloaded by subclasses, which may use lazy evaluation to retrieve the string.

getValue()
get_cmp_key()

Return a key that will be used to compare and hash this object.

property localname
property namespace
split()

Split into a namespace + local name pair.

toNTriples()

Return an NTriples representation of a resource, in this case, wrap it in angle brackets.

to_json_ld()

Converts to an object to be used as a JSON-LD value.

to_json_ld_key()

Converts to a string to be used as a JSON-LD key.

property uri

Return the URI (string) for ‘self’. This method is typically overloaded by subclasses, which may use lazy evaluation to retrieve the string.

property value
class franz.openrdf.model.Value

Bases: object

Top class in the org.openrdf.model interfaces.

get_cmp_key()

Return a key that will be used to compare and hash this object.

toNTriples()

Return an NTriples representation of an open rdf term

class franz.openrdf.model.ValueFactory(store)

Bases: object

A factory for creating URIs, blank nodes, literals and statements.

BLANK_NODE_AMOUNT = 10
__init__(store)
createBNode(nodeID=None)

See RepositoryConnection.createBNode().

createLiteral(value, datatype=None, language=None)

See RepositoryConnection.createLiteral().

createQuotedTriple(subject, predicate, object)

See RepositoryConnection.createQuotedTriple()

createRange(lowerBound, upperBound)

Create a compound literal representing a range from ‘lowerBound’ to ‘upperBound’

createStatement(subject, predicate, _object, context=None)

See RepositoryConnection.createStatement().

createURI(uri=None, namespace=None, localname=None, canonical=True)

See RepositoryConnection.createURI().

getUnusedBNodeId()
namespace(prefix, canonical=True)

Create an object that allows for simple creation of URIs in given namespace. Attribute lookups on the returned object will produce URIs with the attribute name as localname. Array item access and function calls will have the same effect.

Parameters:
  • prefix (str) – Prefix prepended to URIs created by the returned object.

  • canonical (bool) – If true (default) ensure that the same URI object is returned each time when the same string is passed as the local name.

Returns:

An object that can be used to create URIs.

namespaces(prefixes, canonical=True)

Same as namespace(), but allows to create URIs in multiple namespaces from the strings of the form ‘<abbrev>:<name>’, where <abbrev> is one of the namespace abbreviations provided in the ‘prefixes’ dictionary, and <name> is the resource name.

Parameters:
  • prefixes (dict) – Dictionary mapping prefix abbreviations to prefixes to be prepended to URIs created by the returned object.

  • canonical (bool) – If true (default) ensure that the same URI object is returned each time when the same string is passed as the local name.

Returns:

An object that can be used to create URIs.

object_position_term_to_openrdf_term(term, predicate=None)

If ‘term’ is a string, integer, float, etc, convert it to a Literal term. Otherwise, if its a Value, just pass it through.

validateCompoundLiteral(term, predicate)

Check to see if range boundaries are mapped. TODO: ADD VALIDATION FOR GEO TERMS

validateRangeConstant(term, predicate)

Validate an individual range constant

franz.openrdf.model.parse_term(string_term)

Given a string representing a term in ntriples format, return a URI, Literal, or BNode.