franz.openrdf.repository package¶
Submodules¶
franz.openrdf.repository.attributes module¶
Functions and structures related to triple attributes and attribute filters.
- class franz.openrdf.repository.attributes.And(*args: AttributeFilter | str)¶
Bases:
FilterOp
A conjunction of attribute filters.
- op = 'and'¶
- class franz.openrdf.repository.attributes.AttributeDefinition(name, allowed_values=None, ordered=False, minimum_number=None, maximum_number=None)¶
Bases:
object
Defines basic properties of an attribute, such as its name, cardinality and the set of allowed values.
- Variables:
name – Unique name of this attribute. Must consist only of letters, digits, underscores, dashes and non-ascii characters.
allowed_values – Either
None
or a list of strings that defines the set of legal values for this attribute.ordered – If true then values of this attribute can be compared in filters. Values are ordered by their index within the
allowed_values
list (which is required for ordered attributes).minimum_number – Defines the minimum number of values for this attribute that must be associated with each triple.
maximum_number – Defines the maximum number of values for this attribute that can be associated with each triple.
- __init__(name, allowed_values=None, ordered=False, minimum_number=None, maximum_number=None)¶
- class franz.openrdf.repository.attributes.AttributeFilter¶
Bases:
object
Superclass of objects that can be used as static attribute filters.
Note that raw strings are also accepted in this role.
Objects of this class can be combined using bitwise logical operators.
- to_expr()¶
Convert this object to an S-expression and return it as a string. :return: S-expression representing this object.
- class franz.openrdf.repository.attributes.ContextAttribute(name)¶
Bases:
object
Superclass for contextual triple attributes used in filters.
- __init__(name)¶
- context = ''¶
- class franz.openrdf.repository.attributes.ContextAttributeType¶
Bases:
type
Metaclass for ‘context’ classes that convert
Class.something
andClass['something']
toClass('something')
.
- class franz.openrdf.repository.attributes.Empty(*args)¶
Bases:
SetOp
A filter that matches if the argument is an empty attribute set.
- op = 'empty'¶
- class franz.openrdf.repository.attributes.Eq(*args)¶
Bases:
OrderedFilter
An ordered filter that matches if the first argument is equal to the second.
- op = 'attribute-set='¶
- class franz.openrdf.repository.attributes.Equal(*args)¶
Bases:
SetOp
A filter that matches if its arguments are identical attribute sets.
- op = 'equal'¶
- class franz.openrdf.repository.attributes.FilterOp(*args: AttributeFilter | str)¶
Bases:
AttributeFilter
An attribute filter created by applying an operator to other filters. Note that the arguments can be either AttributeFilter instances or strings.
- __init__(*args: AttributeFilter | str) None ¶
- op = ''¶
- to_expr()¶
Convert this object to an S-expression and return it as a string. :return: S-expression representing this object.
- class franz.openrdf.repository.attributes.Ge(*args)¶
Bases:
OrderedFilter
An ordered filter that matches if the first argument is greater than or equal to the second.
- op = 'attribute-set>='¶
- class franz.openrdf.repository.attributes.Gt(*args)¶
Bases:
OrderedFilter
An ordered filter that matches if the first argument is greater than the second.
- op = 'attribute-set>'¶
- class franz.openrdf.repository.attributes.Le(*args)¶
Bases:
OrderedFilter
An ordered filter that matches if the first argument is less than or equal to the second.
- op = 'attribute-set<='¶
- class franz.openrdf.repository.attributes.Lt(*args)¶
Bases:
OrderedFilter
An ordered filter that matches if the first argument is less than the second.
- op = 'attribute-set<'¶
- class franz.openrdf.repository.attributes.Not(*args: AttributeFilter | str)¶
Bases:
FilterOp
Inverse attribute filter (matches whatever the argument does not match).
- op = 'not'¶
- class franz.openrdf.repository.attributes.Or(*args: AttributeFilter | str)¶
Bases:
FilterOp
A disjunction of attribute filters.
- op = 'or'¶
- class franz.openrdf.repository.attributes.OrderedFilter(*args)¶
Bases:
SetOp
A filter for comparing ordered attributes. Both arguments must be either empty or singleton sets representing values of an ordered attribute.
- class franz.openrdf.repository.attributes.Overlap(*args)¶
Bases:
SetOp
A filter that matches if attribute sets given as arguments have a common value.
- op = 'overlap'¶
- class franz.openrdf.repository.attributes.SetOp(*args)¶
Bases:
AttributeFilter
An attribute filter created by applying an operator to one or more attribute sets.
- __init__(*args)¶
- op = ''¶
- to_expr()¶
Convert this object to an S-expression and return it as a string. :return: S-expression representing this object.
- class franz.openrdf.repository.attributes.Subset(*args)¶
Bases:
SetOp
A filter that matches if the first argument is a subset of the second argument (both arguments must be attribute sets).
- op = 'subset'¶
- class franz.openrdf.repository.attributes.Superset(*args)¶
Bases:
SetOp
A filter that matches if the first argument is a supersset of the second argument (both arguments must be attribute sets).
- op = 'superset'¶
- class franz.openrdf.repository.attributes.TripleAttribute(name)¶
Bases:
ContextAttribute
Triple attribute reference to be used in filters.
A triple attribute name ‘foo’ can be referenced in three ways:
TripleAttribute('foo')
TripleAttribute.foo
TripleAttribute['foo']
Filters involving objects of this class can be constructed using the following operators:
<
,<=
,==
,>=
,``>`` - note that==
is translated asequals
, notattribute=
.<<
and>>
- meaning ‘subset’ and ‘superset’.
- context = 'triple'¶
- class franz.openrdf.repository.attributes.UserAttribute(name)¶
Bases:
ContextAttribute
User attribute reference to be used in filters.
A user attribute name ‘foo’ can be referenced in three ways:
UserAttribute('foo')
UserAttribute.foo
UserAttribute['foo']
Filters involving objects of this class can be constructed using the following operators:
<
,<=
,==
,>=
,``>`` - note that==
is translated asequals
, notattribute=
.<<
and>>
- meaning ‘subset’ and ‘superset’.
- context = 'user'¶
- franz.openrdf.repository.attributes.attribute_filter_to_expr(attribute_filter: AttributeFilter | str) str ¶
Convert an attribute filter to string.
- franz.openrdf.repository.attributes.attribute_set_to_expr(attribute_set)¶
Convert an attribute set (to be used in a filter) to string.
franz.openrdf.repository.repository module¶
- class franz.openrdf.repository.repository.Repository(catalog, database_name, repository)¶
Bases:
object
A repository contains RDF data that can be queried and updated. Access to the repository can be acquired by opening a connection to it. This connection can then be used to query and/or update the contents of the repository.
Please note that a repository needs to be initialized before it can be used and that it should be shut down before it is discarded/garbage collected. Forgetting the latter can result in loss of data (depending on the Repository implementation)!
- ACCESS = 'ACCESS'¶
- CREATE = 'CREATE'¶
- OPEN = 'OPEN'¶
- RENEW = 'RENEW'¶
- REPLACE = 'REPLACE'¶
- __init__(catalog, database_name, repository)¶
Invoke through
getRepository()
.
- property bulk_mode¶
Turn BulkMode on with True or off with False.
In bulk mode, all modifications to the triple-store are made without writing to the transaction log. There is overhead to switching in and out of bulk-mode, and it is a global repository state, so all clients are affected.
- getConnection()¶
Opens a connection to this store that can be used for querying and updating the contents of the store. Created connections need to be closed to make sure that any resources they keep hold of are released. The best way to ensure this is to use a
with
statement:with repo.getConnection() as conn: ...
- Returns:
A
RepositoryConnection
object.- Return type:
- getDatabaseName()¶
Return the name of the database (remote triple store) that this repository is interfacing with.
- getSpec()¶
Return a session spec string for this repository.
See
openSession()
. :return: A session spec. :rtype: string
- getValueFactory()¶
Return a ValueFactory for this store.
This is present for RDF4J compatibility, but in the Python API all ValueFactory functionality has been duplicated or subsumed in the
RepositoryConnection
class. It isn’t necessary to manipulate theValueFactory
class at all.- Returns:
A ValueFactory instance.
- Return type:
- initialize()¶
Initializes this repository. A repository must be initialized before it can be used.
It is recommended to take advantage of the fact that repositories are context managers and use the
with
statement to ensure thatinitialize()
andshutDown()
are called:with catalog.getRepository() as repo: # No need to call initialize or shutDown inside. ...
- Returns:
self
(to allow call chaining).
- isWritable()¶
Checks whether this store is writable, i.e. if the data contained in this store can be changed. The writability of the store is determined by the writability of the Sail that this store operates on.
- registerDatatypeMapping(predicate=None, datatype=None, nativeType=None)¶
Register an inlined datatype.
This allows some literals to be stored in an optimized form on the server.
See also
- http://franz.com/agraph/support/documentation/current/lisp-reference.html#ref-type-mapping
More detailed discussion of type mappings in the Lisp API documentation.
You must supply
nativeType
and eitherpredicate
ordatatype
.If
predicate
is supplied, then object arguments to triples with that predicate will use an inlined encoding of type nativeType in their internal representation on the server.If
datatype
is supplied, then typed literal objects with a datatype matchingdatatype
will use an inlined encoding of type nativeType.Duplicated in the
RepositoryConnection
class for Python user convenience.- Parameters:
predicate – The URI of a predicate used in the triple store.
datatype – May be one of:
XMLSchema.INT
,XMLSchema.LONG
,XMLSchema.FLOAT
,XMLSchema.DATE
andXMLSchema.DATETIME
.nativeType (string|type) – may be
int
,datetime
, orfloat
.
- shutDown()¶
Shuts the store down, releasing any resources that it keeps hold of. Once shut down, the store can no longer be used.
It is recommended to take advantage of the fact that repositories are context managers and use the
with
statement to ensure thatinitialize()
andshutDown()
are called:with catalog.getRepository() as repo: # No need to call initialize or shutDown inside. ...
franz.openrdf.repository.repositoryconnection module¶
- class franz.openrdf.repository.repositoryconnection.DocumentKey(prefix=None, rename=None, rdf_type=None, lang=None, skip=None, transform=None, graph=None)¶
Bases:
DocumentKey
Describes the way in which value of a single key is translated into a triple (or triples, if the value is a list) when importing documents into AG.
See the documentation of
RepositoryConnection#addDocument()
for details.
- class franz.openrdf.repository.repositoryconnection.GeoType(system, scale=None, unit=None, xMin=None, xMax=None, yMin=None, yMax=None, latMin=None, latMax=None, longMin=None, longMax=None)¶
Bases:
object
- Cartesian = 'CARTESIAN'¶
- Spherical = 'SPHERICAL'¶
- __init__(system, scale=None, unit=None, xMin=None, xMax=None, yMin=None, yMax=None, latMin=None, latMax=None, longMin=None, longMax=None)¶
- createBox(xMin=None, xMax=None, yMin=None, yMax=None, unit=None)¶
Define a rectangular region for the current coordinate system.
- createCircle(x, y, radius, unit=None)¶
Define a circular region with vertex x,y and radius “radius”. The distance unit for the radius is either ‘unit’ or the unit specified for this GeoType. If ‘innerRadius’ is specified, the region is ring-shaped, consisting of the space between the inner and outer circles.
- createCoordinate(x=None, y=None, latitude=None, longitude=None, unit=None)¶
Create an x, y or lat, long coordinate for the system defined by this geotype.
- createPolygon(vertices, uri=None)¶
Define a polygonal region with the specified vertices. ‘vertices’ is a list of x,y pairs. The ‘uri’ is optional.
- setConnection(connection)¶
- class franz.openrdf.repository.repositoryconnection.PrefixFormat(prefix, format)¶
Bases:
EncodedIdPrefix
- class franz.openrdf.repository.repositoryconnection.RepositoryConnection(repository, close_repo=False, is_session=False)¶
Bases:
object
The RepositoryConnection class is the main interface for updating data in and performing queries on a
Repository
. By default, a RespositoryConnection is in autoCommit mode, meaning that each operation corresponds to a single transaction on the underlying triple store. autoCommit can be switched off, in which case it is up to the user to handle transaction commit/rollback. Note that care should be taken to always properly close a RepositoryConnection after one is finished with it, to free up resources and avoid unnecessary locks.Note that concurrent access to the same connection object is explicitly forbidden. The client must perform its own synchronization to ensure non-concurrent access.
Several methods take a vararg argument that optionally specifies a set of contexts on which the method should operate. (A context is the URI of a subgraph.) Note that a vararg parameter is optional, it can be completely left out of the method call, in which case a method either operates on a provided statement’s context (if one of the method parameters is a statement or collection of statements), or operates on the repository as a whole, completely ignoring context. A vararg argument may also be
None
, meaning that the method operates on those statements which have no associated context only.- RDFStarEnabled()¶
Return True if RDF-star semantics have been enabled; return False otherwise.
- __init__(repository, close_repo=False, is_session=False)¶
Call through
getConnection()
.- Parameters:
repository (Repository) – Repository to connect to.
close_repo (bool) – If
True
shutdown the repository when this connection is closed. The default isFalse
.
- add(arg0, arg1=None, arg2=None, contexts=None, base=None, format=None, serverSide=False, attributes=None)¶
Calls
addTriple()
,addStatement()
, oraddFile()
.Best practice is to avoid
add()
and useaddTriple()
,addStatement()
oraddFile()
instead.- Parameters:
arg0 (Statement|string|Value) – May be a Statement or a filepath. If so, arg1 and arg2 default to None. May also be the subject of a triple (in that case arg1 and arg2 must be the predicate and the object respectively).
arg1 (string|Value) – Predicate of the new triple.
arg2 (string|Value) – Object of the new triple.
contexts (Iterable[URI|string]) – Optional list of contexts (subgraph URIs), defaulting to None. A context is the URI of a subgraph. If None, the triple(s) will be added to the null context (the default or background graph).
base (string) – The baseURI to associate with loading a file. Defaults to
None
. IfNone
the baseURI will be chosen by the server.format (RDFFormat) – Format of the uploaded file (e.g. RDFFormat.TURTLE or RDFFormat.NQUADS). If set to
None
(default) the format will be selected based on the filename.serverSide (bool) – Indicates whether the filepath refers to a file on the client computer or on the server. Defaults to
False
(i.e. client-side).attributes (dict[str, str]) – Attributes for the new triple (a mapping from attribute names to values).
- addData(data, rdf_format=None, base_uri=None, context=None, attributes=None, json_ld_store_source=None, json_ld_context=None, allow_external_references=None, external_reference_timeout=None)¶
Adds data from a string to the repository.
- Parameters:
data (string|dict|list) – Data to be added. Can be a string, a dictionary containing a JSON-LD document or a list of such dictionaries. In addition to regular JSON-serializable values a JSON-LD document might contain URI and BNode objects as keys and all kinds of RDF terms (literals, URIs and BNodes) as values.
rdf_format (RDFFormat|str) – Data format - either a RDFFormat or a MIME type (string). Defaults to RDFFormat.TURTLE, unless the data is given as a dictionary, in which case the default is RDFFormat.JSONLD.
base_uri (string) – Base for resolving relative URIs. If None (default), the URI will be chosen by the server.
context (URI|string) – Graph to add the data to. If None (default) the default graph will be used.
attributes (dict[str, str]) – Attributes for the added triples (a mapping from attribute names to values).
json_ld_store_source (bool) – If set to true then a triple containing the whole uploaded document as a string will also be added to the store. The default is False.
json_ld_context (str|dict) – A JSON-LD context. This must be either a dictionary describing a JSON object or a string containing the address of an external context. The context can also be stored in the JSON-LD document, either inline or as a reference to an external URI. Note that a JSON-LD context is an object describing the way in which a JSON document should be represented as triples. It should not be confused with RDF contexts (i.e. graphs).
allow_external_references (bool) – If False (default) the server will refuse to retrieve external JSON-LD contexts and references from XML documents. Note that allowing untrusted documents to retrieve arbitrary URLs might have security implications.
external_reference_timeout (int) – Timeout value (in seconds) used when retrieving external JSON-LD contexts. By default there is no timeout.
- addDocumentData(doc, doc_format=DocFormat.JSON: JSON, base=None, rules=None, subject=None, keys=None, prefix=None, rename=None, rdf_type=None, lang=None, skip=None, transform=None, graph=None, json_store_source=None, csv_dialect=None, csv_columns=None, csv_separator=None, csv_quote=None, csv_whitespace=None, csv_double_quote=None, csv_escape=None, attributes=None, commit=None, context=None)¶
Convert a JSON or CSV document string into triples and add the resulting triples into the repository.
The first argument must be a string, a dict (will be converted to JSON) or a list of dicts (converted to JSON lines). The second argument describes the document format, the default is JSON. Note that if the first argument is a dict or a list the format argument will be ignored.
See
addDocument()
for the description of other parameters.
- addDocumentFile(doc, doc_format=None, base=None, rules=None, subject=None, keys=None, prefix=None, rename=None, rdf_type=None, lang=None, skip=None, transform=None, graph=None, json_store_source=None, csv_dialect=None, csv_columns=None, csv_separator=None, csv_quote=None, csv_whitespace=None, csv_double_quote=None, csv_escape=None, attributes=None, commit=None, context=None, encoding=None, content_encoding=None)¶
Convert a JSON or CSV file into triples and add the resulting triples into the repository.
Use
addDocumentData()
instead if the document is stored in a string or in a Python list or dictionary.The document will be interpreted as a set of key-value pairs and a triple will be added to the repository for each such pair. For CSV documents the keys are column names. Mapping of JSON documents is somewhat more involved:
JSON documents must be objects or lists of objects.
If the value of a key is itself an object, that object is recursively interpreted as a document. The subject of resulting triples is used as the value associated with the original key.
If a value is a list then a triple is added for each element. Note that an RDF list is not created.
Multiple objects can be passed by using DocFormat.JSON_LINES. In that case the input document should contain one JSON object per line (see http://jsonlines.org/).
The subject of added triples is computed from the subject parameter, which is a template that can refer to other keys. If the parameter is not given then the subject will be a fresh blank node.
There are multiple parameters that control the way in which values for a given key are turned into predicates and objects. These can be provided in two ways:
By passing a dictionary as the keys parameter. It must map strings (document key names) to
DocumentKey
objects.By passing dictionaries indexed by document key names in the prefix, rename, rdf_type, lang, transform and graph parameters. The skip parameter may also be used (it must be a list of key names).
If both methods are used to provide a particular setting, the value passed in the individual parameter takes precedence.
- Parameters:
doc (str) – Path to the document to be imported.
doc_format (DocFormat) – Format of the document. If not given it is guessed from the extension.
base (URI|str) – Base URI that will be prepended to key names to create predicate URIs. If not specified it is chosen by the server.
rules (str) – Subject of a set of triples that describe transformation rules to be applied during import. See server documentation for more details. This must be a string that will be interpreted as a relative URI in the http://franz.com/ns/allegrograph/6.4/load-meta# namespace.
subject (URI|str) – Template used to create the subject for added triples. The template is a string that can refer to any value in the document using the ${key} notation. A URI object can also be used as the subject. URI objects are simply converted to strings, so any dollar signs inside URIs will be interpreted as key references.
keys (dict[str,DocumentKey]) – A dictionary mapping key names to transformation settings. Settings for each key are described using
DocumentKey
objects. Each such object is a simple named tuple in which all fields are optional. The meaning of each field is the same as that of the corresponding addDocument parameter.prefix (dict[str,str|URI]) – A dictionary mapping key names to prefixes of predicates that will be used to represent those keys. By default the value of base is used.
rename – A dictionary mapping key names to local names of predicates that will be used to represent those keys. By default the local name is the same as the key name. It is also possible to pass full names here, as URI objects. In that case any ‘prefix’ setting will be ignored.
rdf_type (dict[str|URI,str]) – A dictionary mapping key names to RDF datatypes of corresponding values. The datatype can be a URI or a string. A special value ‘uri’ can be used to make the object of the produced triple be a URI rather than a literal. Other than that full URIs and qualified names (e.g. xsd:date) can be used as datatypes. The default datatype is string, except that booleans in JSON documents will be turned into xsd:booleans and integers will be xsd:integers.
lang (dict[str,str]) – A dictionary mapping key names to RDF language tags that will be associated with objects of the resulting triples.
skip (list[str]) – A list of keys for which no triple should be produced.
transform – A dictionary mapping key names to ways in which values should be transformed or computed. Values can be either template strings (using $key or ${key} to reference values of any key) or names of built-in transformation functions (e.g. ‘string-upcase’). Note that it is possible to use this argument to add a new, computed key to the dataset. In addition, keys can also be URI objects.
graph (dict[str,URI|str]) – A dictionary mapping key names to graph URIs. The triple (or triples, since values in a JSON document can be lists) generated for a key will be added to the graph specified here instead of the default graph.
json_store_source (bool) – If this flag is set to True then an additional triple which stores the whole input document as a string is created. This only works for JSON documents.
csv_dialect (str|csv.Dialect) – A dialect object that specifies the syntax used to parse CSV documents. Note that all options specified in the dialect object can be overriden by individual csv_* arguments. This can be either a csv.Dialect instance or the name of a registered dialect, such as ‘excel’.
csv_columns (list[str]) – List of column names to be used when parsing a CSV document. If not given the first row of the document will be used instead.
csv_separator (str) – Character used to separate CSV fields.
csv_quote (str) – Quote character, used around CSV fields that contain the separator character.
csv_whitespace (str|list[str]) – A string or list of characters that should be treated as whitespace when parsing CSV. Whitespace characters are stripped from the start and end of each value.
csv_double_quote (bool) – If true (default) quotes can be escaped inside quoted values by doubling the quote character.
csv_escape (str) – Character that can be used in CSV fields to escape the next character. By default there is no such character.
context (URI|string) – Graph to add the data to. If None (default) the default graph will be used.
commit (int) – If specified then a commit will occur every time the specified number of triples has been generated. This prevents excessive memory usage when importing large files, but makes the import non-transactional.
attributes (dict[str, str]) – Attributes for the added triples (a mapping from attribute names to values).
encoding (str) – Character encoding used by the input file. By default the file is interpreted as UTF-8.
content_encoding (str) – Compression format, supported values are ‘gzip’ or ‘none’. By default the format is guessed from file extension.
- addFile(filePath, base=None, format=None, context=None, serverSide=False, content_encoding=None, attributes=None, json_ld_store_source=None, json_ld_context=None, allow_external_references=None, external_reference_timeout=None)¶
Loads a file into the triple store. Note that a file can be loaded into only one context.
- Parameters:
filepath – Identifies the file to load.
context (URI|string|list[URI|string]) – An optional context URI (subgraph URI), defaulting to
None
. IfNone
, the triple(s) will be added to the null context (the default or background graph).base (string) – The baseURI to associate with loading a file. Defaults to
None
. IfNone
the baseURI will be chosen by the server.format (RDFFormat) – Format of the uploaded file (e.g. RDFFormat.TURTLE or RDFFormat.NQUADS). If set to
None
(default) the format will be selected based on the filename.serverSide (bool) – Indicates whether the filepath refers to a file on the client computer or on the server. Defaults to
False
(i.e. client-side).attributes (dict[str, str]) – Attributes for all added triples (a mapping from attribute names to values).
json_ld_store_source (bool) – If set to true then a triple containing the whole uploaded document as a string will also be added to the store. The default is False.
json_ld_context (str|dict) – A JSON-LD context. This must be either a dictionary describing a JSON object or a string containing the address of an external context. The context can also be stored in the JSON-LD document, either inline or as a reference to an external URI. Note that a JSON-LD context is an object describing the way in which a JSON document should be represented as triples. It should not be confused with RDF contexts (i.e. graphs).
allow_external_references (bool) – If False (default) the server will refuse to retrieve external JSON-LD contexts and references from XML documents. Note that allowing untrusted documents to retrieve arbitrary URLs might have security implications.
external_reference_timeout (int) – Timeout value (in seconds) used when retrieving external JSON-LD contexts. By default there is no timeout.
- addIndex(_type)¶
Add a specific type of index to the current set of triple indices.
- Parameters:
_type (string) – Index name (see
listIndices()
).
- addRules(rules, language=QueryLanguage.PROLOG)¶
Add Prolog functors to the current session.
Note that this only works with a dedicated session (See
session()
.See also
- http://franz.com/agraph/support/documentation/current/prolog-tutorial.html
Tutorial describing the syntax of Prolog rules (functors).
- Parameters:
rules (string) – A string containing Prolog rule definitions. The definitions are S-expressions using the
<-
and<--
operators (to append and overwrite rules respectively).language – Ignored.
- addStatement(statement, contexts=<object object>, attributes=None)¶
Add the supplied statement to the specified contexts in the repository.
- Parameters:
statement (Statement) – The statement to be added. Note that the
context
field is ignored (use thecontexts
parameters instead).contexts (Iterable[string|URI]) – List of contexts (graph URIs) to add the statement to. If present this overrides the context from the statement object. The default context is
None
, which adds the statement to the null context (the default or background graph).attributes (dict[str, str]) – Attributes for the added triple (a mapping from attribute names to values). If present this overrides the attributes passed in the statement object.
- addTriple(subject, predicate, object, contexts=None, attributes=None)¶
Add a single triple to the repository.
- Parameters:
subject (Value) – Subject of the new triple.
predicate (Value) – Predicate of the new triple.
object (Value) – Object of the new triple.
contexts (Iterable[string|URI]) – List of contexts (graph URIs) to add the triple to. Defaults to
None
, which adds the statement to the null context (the default or background graph).attributes (dict[str, str]) – Attributes for the added triple (a mapping from attribute names to values).
- addTriples(triples_or_quads, context=None, ntriples=False, attributes=None)¶
Add the supplied triples or quads to this repository.
Each triple or quad can have between 3 and 5 elements, the last one being the dictionary of attributes (or None if the default attributes should be used).
- Parameters:
triples_or_quads (Iterable[list[string|Value]|tuple[string|Value]|Statement]) – List of triples or quads. Each element can be either a statement or a list or tuple of
Value
objects or strings.context (string|URI|list[string|URI]) – Context (graph) or list of contexts to add the triples to. Defaults to None (the default graph). Note that this will be ignored for all input quads that already specify a context.
ntriples (bool) – If
True
, parts of the triples are assumed to be strings in N-Triples format and are sent to the server without any conversion.attributes (dict[str, str]) – Default attributes for the added triples (a mapping from attribute names to values). These will be used only for statements that do not contain their own attribute dictionaries.
- property add_commit_size¶
The threshold for commit size during triple add operations. Set to 0 (zero) or None to clear size-based autocommit behavior. When set to an integer triple_count > 0, a commit will occur every triple_count triples added and at the end of the triples being added.
- add_objects(text, properties={})¶
Compute the embedding for the given text string and add it to the repository. text can be a single string or list of strings to add multiple objects. Each object added has the same properties added to the object. The params argument looks like {“color” : “red”, “size” : “large”}. Existing objects will not be added again. Returns the object identifier of the last object added.
- allocateEncodedIds(prefix, amount=1)¶
allocateEncodedIds allows you to use the server to allocate unique ids for a given registered prefix which has a fixed-width format specifier.
See notes on next-encoded-upi-for-prefix in:
https://franz.com/agraph/support/documentation/current/encoded-ids.html
- callStoredProc(function, module, *args)¶
- clear(contexts='ALL_CONTEXTS')¶
Removes all statements from designated contexts in the repository. If
contexts
is ALL_CONTEXTS, clears the repository of all statements.
- clearAttributeFilter()¶
Remove the static attribute filter (if set).
- clearNamespaces(reset=True)¶
Delete all namespaces in this repository for the current user.
- Parameters:
reset – If
True
(default) the user’s namespaces are reset to the default set of namespaces, otherwise all namespaces are cleared.
- clearQueryOptions()¶
Delete all query options in this repository for the current user.
- close()¶
Close the connection. This also closes the session if it is active.
It is safe to call this on a connection that has already been closed.
Note that using
with
is the preferred way to manage connections.
- closeSession()¶
Close a session.
It is not an error to call this when no session is active.
- commit(settings=None, **kwargs)¶
Commit changes on an open session.
Parameters can be used to control distributed transaction settings for the current transaction, as if using
temporaryTransactionSettings()
.
- convert_to_vector_store(embedder, api_key=None, model=None, supersede=False)¶
Convert an existing normal repo to a vector store by setting the embedder and optionally the api-key and model. Unless supersede is True this function will do nothing if the repo is already a vector store
- createBNode(nodeID=None)¶
Create a new blank node.
- Parameters:
nodeID (string) – Optional node identifier, if not given a fresh one will be generated.
- Returns:
A BNode value.
- Return type:
- createBox(xMin=None, xMax=None, yMin=None, yMax=None)¶
Create a rectangular search region (a box) for geospatial search. This method works for both Cartesian and spherical coordinate systems.
- createCircle(x, y, radius, unit=None)¶
Create a circular search region for geospatial search.
This method works for both Cartesian and spherical coordinate systems.
- createCoordinate(x=None, y=None, latitude=None, longitude=None)¶
Create an x, y or latitude, longitude coordinate in the current coordinate system.
Either
x
,y
orlatitude
,longitude
must be given.- Parameters:
x – X coordinate of the created point.
y – Y coordinate of the created point.
latitude – Latitude of the created point.
longitude – Longitude of the created point.
- Returns:
A literal representing the created point.
- Return type:
- createFreeTextIndex(name, predicates=None, indexLiterals=None, indexResources=None, indexFields=None, minimumWordSize=None, stopWords=None, wordFilters=None, innerChars=None, borderChars=None, tokenizer=None)¶
Create a free-text index with the given parameters.
See also
- http://franz.com/agraph/support/documentation/current/http-protocol.html#put-freetext-index
Documentation of the HTTP endpoint used by this method.
- http://franz.com/agraph/support/documentation/current/text-index.html
General information about text indexing in AllegroGraph.
- Parameters:
name (string) – Name for the new index.
predicates (list[string|URI]) – A list of predicates to be indexed. If not given all triples will be indexed regardless of predicate.
indexLiterals (bool|list[string]) – Determines which literals to index. It can be``True`` (the default),
False
, or a list of strings, indicating the literal types or langs that should be indexed.indexResources (bool|string) – Determines which resources are indexed. It can be
True
,False
(the default), or"short"
, to index only the part of resources after the last slash or hash character.indexFields (list[string]) – List of triples fields to index. Can be any combination of
"subject"
,"predicate"
,"object"
, and"graph"
. The default is["object"]
.minimumWordSize (int) – Determines the minimum size a word must have to be indexed. The default is 3.
stopWords (list[string]) – List of words that should not be indexed. When not given, a list of common English words is used.
wordFilters (list[string]) – List of normalizing filters used to process words before indexing. The list if supported filters can be found here: http://franz.com/agraph/support/documentation/current/text-index.html
innerChars (list[string]) –
The character set to be used as the constituent characters of a word. Should be a list of character classes. Valid classes are:
”alpha”`: All (unicode) alphabetic characters.
"digit"
: All base-10 digits."alphanumeric"
: All digits and alphabetic characters.a single character
a range of characters: A single character, followed by a dash (-) character, followed by another single character.
borderChars (list[string]) – The character set to be used as the border characters of indexed words. Uses the same syntax as
innerChars
.tokenizer (string) – Controls the way in which the text is plit into tokens. Can be either
"default"
or"japanese"
. Note that thejapanese
tokenizer ignoresinnerChars
andborderChars
.
- createLatLongSystem(unit='degree', scale=None, latMin=None, latMax=None, longMin=None, longMax=None)¶
Create a spherical coordinate system and use it as the current coordinate system.
- createLiteral(value, datatype=None, language=None)¶
Create a new literal with value
value
.datatype
, if supplied, should be a URI (it can be a string or anURI
instance, in which casevalue
must be a string.- Parameters:
value (int|long|float|string|datetime.datetime|datetime.date|datetime.time) – Literal value - can be a string, a number or a datetime object.
datatype (string|URI) – Optional literal type. Note that if
value
is not a string the type will be guessed automatically.language (string) – Optional language tag.
- createPolygon(vertices, uri=None, geoType=None)¶
Define a polygonal region with the specified vertices.
- createQuotedTriple(subject, predicate, object)¶
Create a new quoted triple (not to be confused with the Statement type).
- Parameters:
subject (Resource) – Subject of the new quoted triple.
predicate (Resource) – Predicate of the new quoted triple.
object (Resource) – Object of the new quoted triple.
- Returns:
A Triple value.
- Return type:
Triple
- createRange(lowerBound, upperBound)¶
Create a compound literal representing a range from lowerBound to upperBound.
- createRectangularSystem(scale=1, unit=None, xMin=0, xMax=None, yMin=0, yMax=None)¶
Create a Cartesian coordinate system and use it as the current coordinate system.
- Parameters:
- Returns:
The new coordinate system.
- createStatement(subject, predicate, object, context=None)¶
Create a new Statement object.
Note that this does not cause the statement to be added to the repository.
- createURI(uri=None, namespace=None, localname=None, canonical=True)¶
Creates a new URI from the supplied string-representation(s). If two non-keyword arguments are passed, assumes they represent a namespace/localname pair.
- Parameters:
uri (string) – URI text, unless namespace is passed and localname is not, in which case this becomes the namespace.
namespace (string|URI) – Namespace part of the URI if
localname
is passed, otherwise this becomes the local name.localname – Local part of the URI. Should only be used as a keyword argument and together with
namespace
.canonical (bool) – If true (default) ensure that the same URI object is returned each time when the same string is passed to this method.
- Returns:
An URI object.
- Return type:
- deleteAttributeDefinition(name)¶
Delete an attribute definition.
- Parameters:
name – Attribute name.
- deleteDuplicates(mode)¶
Delete duplicate triples from the store.
- Parameters:
mode – can be “spo” (triples are duplicates if they have the same subject, predicate, and object, regardless of the graph) or “spog” (triples are duplicates if they have the same subject, predicate, object, and graph).
See also
Method
getDuplicateStatements()
.
- deleteFreeTextIndex(name)¶
Delete a free-text index from the server.
- Parameters:
name (string) – Index name.
- deleteMaterialized()¶
Deletes all previously materialized triples. Returns the number of triples deleted.
- deleteSpinFunction(uri)¶
- Deletes the Spin function at the given uri.
uri - Spin function identifier
- deleteSpinMagicProperty(uri)¶
- Deletes the Spin magic property at the given uri.
uri - Spin magic property identifier
- disableDuplicateSuppression()¶
Disable duplicate suppression for this store. See https://franz.com/agraph/support/documentation/current/deleting-duplicate-triples.html
- disableRDFStar()¶
Disable the RDF-star semantics for the current Repository.
- disableSubjectTriplesCache()¶
Disable the subject triples cache (see
enableSubjectTriplesCache()
).
- dropIndex(_type)¶
Removes a specific type of index to the current set of triple indices.
- Parameters:
_type (string) – Index name (see
listIndices()
).
- enableRDFStar()¶
Enable the RDF-star semantics for the current Repository.
- enableSubjectTriplesCache(size=None)¶
Maintain a cache of size
size
that caches, for each accessed resource, quads where the resource appears in subject position.This can accelerate the performance of certain types of queries.
- Parameters:
size (int) – The maximum number of subjects whose triples will be cached. Default is 100,000.
- evalFreeTextSearch(pattern, infer=False, callback=None, limit=None, offset=None, index=None)¶
Return a list of statements for the given free-text pattern search.
Note that this method operates on unparsed data. Returned statements will be lists of strings in N-Triples format, not statement objects. The first element of each list will be the triple id (an integer, not a string).
If no index is provided, all indices will be used.
- Parameters:
pattern (string) – Search pattern, see http://franz.com/agraph/support/documentation/current/http-protocol.html#get-post-freetext for details.
index (string|list[string]) – List of indices to query. If not given - query all indices.
callback – A function that will be called for each statement retrieved. If this argument is used then the list of statements is not returned.
- evalGraphqlQuery(query, default_prefix=None, infer=False, namespaces=None, variables=None, aliases=None)¶
Evaluate the GraphQL query in the server.
- evalInServer(code)¶
Evaluate the Lisp code in the server.
You must have “eval” permissions to the store to use this feature.
- evalJavaScript(code)¶
Evaluate the JavaScript code in the server.
You must have “eval” permissions to the store to use this feature.
- executeBooleanQuery(query, language=QueryLanguage.SPARQL)¶
Prepare and immediately evaluate a query that returns a boolean.
- Parameters:
query (str) – Query text.
language (QueryLanguage) – Query language, the default is SPARQL.
- Returns:
Query result.
- Return type:
- executeGraphQuery(query, language=QueryLanguage.SPARQL, output=None, output_format=RDFFormat.NQX: Extended N-Quads (with attributes))¶
Prepare and immediately evaluate a query that returns RDF.
- Parameters:
query (str) – Query text.
language (QueryLanguage) – Query language, the default is SPARQL.
output (str|file) – File path or a file-like object to write the result to.
output_format (RDFFormat) – Serialization format for
output
.
- Returns:
Query result, or
None
ifoutput
is used.- Return type:
RepositoryResult|None
- executeTupleQuery(query, language=QueryLanguage.SPARQL, output=None, output_format=RDFFormat.TABLE: Table)¶
Prepare and immediately evaluate a query that returns tuples.
- Parameters:
query (str) – Query text.
language (QueryLanguage) – Query language, the default is SPARQL.
output (str|file) – File path or a file-like object to write the result to.
output_format (RDFFormat) – Serialization format for
output
.
- Returns:
Query result, or
None
ifoutput
is used.- Return type:
- executeUpdate(query)¶
Prepare and immediately evaluate a SPARQL update query.
- export(handler, contexts='ALL_CONTEXTS')¶
Export all explicit statements in the specified contexts to a file.
Deprecated since version 4.14.1: Use
saveResponse()
instead.
- exportStatements(subj, pred, obj, includeInferred, handler, contexts='ALL_CONTEXTS')¶
Export statements to a file.
Deprecated since version 4.14.1: Use
saveResponse()
instead.- Parameters:
subj (Value) – Subject or
None
(i.e. no filtering on subject).pred (URI) – Predicate or
None
(i.e. no filtering on predicate).obj (Value) – Object or
None
(i.e. no filtering on object).includeInferred (bool) – If
True
inferred triples will be included in the output. The default isFalse
.handler (RDFWriter) – An RDFWriter instance describing the target file and data format.
contexts (Iterable[string|URI]|string|URI) – A context or list of contexts (default: all contexts).
- getAddCommitSize()¶
Get the current value of
add_commit_size
. :return: Value ofadd_commit_size
.
- getAttributeDefinition(name)¶
Get the definition of a given attribute.
Return None if there is no such attribute.
- Parameters:
name – Attribute name.
- Returns:
A definition object.
- Return type:
- getAttributeDefinitions()¶
Get a list of all attribute definitions from the server.
- Returns:
A list of attribute definition objects.
- Return type:
list[AttributeDefinition]
- getAttributeFilter()¶
Get the current static attribute filter.
The result will be a string, not an AttributeFilter object.
- Returns:
The filter or none (if there is no static filter).
- Return type:
- getContextIDs()¶
Return a list of context resources, one for each context referenced by a quad in the triple store. Note that the default context will not be included in the result.
- Returns:
A list of contexts (as
URI
objects).- Return type:
list[URI]
- getDuplicateStatements(mode)¶
Return all duplicates in the store.
- Parameters:
mode – can be “spo” (triples are duplicates if they have the same subject, predicate, and object, regardless of the graph) or “spog” (triples are duplicates if they have the same subject, predicate, object, and graph).
- Returns:
An iterator over duplicate statements.
- Return type:
- getDuplicateSuppressionPolicy()¶
Return the duplicate suppression policy used by the store. See https://franz.com/agraph/support/documentation/current/deleting-duplicate-triples.html
- Returns:
Duplicate suppression policy: “spo”, “spog” or None.
- Return type:
- getFreeTextIndexConfiguration(name)¶
Get the current settings of a free-text index.
The result will be a dictionary where keys are parameter names as used in
createFreeTextIndex()
.- Parameters:
name (string) – Index name.
- Returns:
A dictionary with configuration data, keys are argument names from
createFreeTextIndex()
.- Return type:
- getGeoType()¶
Get the current geospatial coordinate system.
- Returns:
A coordinate system.
- Return type:
- getNamespace(prefix)¶
Get the namespace that is associated with the specified prefix, if any.
- Parameters:
prefix – Namespace prefix.
- Returns:
Namespace URI.
- Raises:
RequestError – if there is no namespace with given prefix.
- getNamespaces()¶
Get all declared prefix/namespace pairs.
The result is a dictionary mapping prefixes to namespace URIs.
- Returns:
A dictionary of namespaces.
- Return type:
dict[string,string]
- getQueryOption(name)¶
Get the current value for the query option, if any.
- Parameters:
name – Query option name.
- Returns:
Query option value.
- Raises:
RequestError – if the given query option is not set.
- getQueryOptions()¶
Get pairs option/value for all enabled query options.
The result is a dictionary mapping option names to values.
- Returns:
A dictionary of query options.
- Return type:
dict[string,string]
- getSpec()¶
Get the session specification string for this repository.
- Returns:
Spec string suitable for use with
openSession()
.
- getSpinFunction(uri)¶
- Gets the string of the function for the given uri.
uri - Spin function identifier
- getSpinMagicProperty(uri)¶
- Get the spin magic property for the uri
uri - spin magic property identifier
- getStatements(subject=None, predicate=None, object=None, contexts='ALL_CONTEXTS', includeInferred=False, limit=None, offset=None, tripleIDs=False, output=None, output_format=RDFFormat.NQX: Extended N-Quads (with attributes))¶
Get all statements with a specific subject, predicate and/or object from the repository. The result is optionally restricted to the specified set of named contexts (graphs).
Return a
RepositoryResult
object that can be used to iterate over the resulting statements and filter out duplicates if desired. Alternatively one can write the results to a file or stream using theoutput
parameter.- Parameters:
subject (Value) – Subject value or
None
(no subject filtering).predicate (URI) – Predicate value or
None
(no predicatefiltering).object (Value) – Object value or
None
(no object filtering).contexts (URI|string|Iterable[URI|string]) – An optional list of graphs to retrieve the statements from. By default statements are taken from all graphs.
includeInferred (bool) – If
True
, include triples inferred through RDFS++ reasoning. The default isFalse
.limit (int) – Max number of statements to retrieve (optional).
offset (int) – Used in conjunction with
limit
to return results starting from the nth statement.tripleIDs – If
True
the id field will be filled in the returned statements.output (str|file) – File path or a file-like object to write the result to.
output_format (RDFFormat) – Serialization format for
output
.include_attributes (bool) – If true the returned statements will include triple attributes. The default is false.
- Returns:
An iterator over the resulting statements or
None
(ifoutput
is used).- Return type:
- getStatementsById(ids, output=None, output_format=RDFFormat.NQX: Extended N-Quads (with attributes))¶
Return all statements whose triple ID matches an ID in the list ‘ids’.
- Parameters:
- Returns:
An iterator over requested statements or
None
(ifoutput
is used).- Return type:
- getSubjectTriplesCacheSize()¶
Return the current size of the subject triples cache.
See also
enablerSubjectTriplesCache()
- getTransactionSettings()¶
Return distributed transaction settings currently in force.
- Returns:
A settings object.
- Return type:
- getUserAttributes()¶
Get the current set of user attributes.
- getValueFactory()¶
Get the
ValueFactory
associated with this repository.Note that it is recommended to use methods defined in
RepositoryConnection
instead of a value factory. The latter is only provided for RDF4J compatibility.- Returns:
A value factory.
- Return type:
- isEmpty()¶
Return
True
if this repository does not contain any (explicit) statements.
- listEncodedIdPrefixes()¶
Lists all encoded id prefixes.
See: https://franz.com/agraph/support/documentation/current/encoded-ids.html
- listFreeTextIndices()¶
Get the names of currently defined free-text indices.
- Returns:
List of index names.
- Return type:
list[string]
- listIndices()¶
Return the list of the current set of triple indices.
Index names are strings such as
"gospi"
,"spogi"
etc. UselistValidIndices()
to get the list of index names supported by the server.- Returns:
List of index names (see
listValidIndices()
).- Return type:
list[string]
- listSpinFunctions()¶
Returns a list of defined SPIN function.
- listSpinMagicProperties()¶
Returns a list of defined SPIN magic properties function.
- listValidIndices()¶
Return the list of valid index names.
- Returns:
List of index names.
- Return type:
list[string]
- loadRules(filename, language=QueryLanguage.PROLOG)¶
Add Prolog rules from file to the current session.
Note that this only works with a dedicated session.
- Parameters:
filename (string) – Path to the file containing Prolog rules.
language – Ignored.
- materializeEntailed(_with=None, without=None, useTypeSubproperty=False, commit=100000)¶
Call to materialize entailed triples to enable reasoning queries without the dynamic query-time reasoner. Returns the number of triples added.
_with and without can be either a single string or a list of strings denoting rules beyond rdfs++ you wish to use. See the documentation for the current set, but “same-as”, “restriction”, “values-from”, “class”, and “property” are examples.
useTypeSubproperty tells the materializer to prefer using types that are rdfs:subPropertyOf rdf:type rather than rdf:type directly.
commit indicates the number of triples per commit for the materializer.
- modifyFreeTextIndex(name, predicates=None, indexLiterals=None, indexResources=None, indexFields=None, minimumWordSize=None, stopWords=None, wordFilters=None, reIndex=None, innerChars=None, borderChars=None, tokenizer=None)¶
Modify parameters of a free-text index.
- Parameters:
name (string) – Name of the index to be modified.
predicates (list[string|URI]) – A list of predicates to be indexed. If not given all triples will be indexed regardless of predicate.
indexLiterals (bool|list[string]) – Determines which literals to index. It can be``True`` (the default),
False
, or a list of strings, indicating the literal types or langs that should be indexed.indexResources (bool|string) – Determines which resources are indexed. It can be
True
,False
(the default), or"short"
, to index only the part of resources after the last slash or hash character.indexFields (list[string]) – List of triples fields to index. Can be any combination of
"subject"
,"predicate"
,"object"
, and"graph"
. The default is["object"]
.minimumWordSize (int) – Determines the minimum size a word must have to be indexed. The default is 3.
stopWords (list[string]) – List of words that should not be indexed. When not given, a list of common English words is used.
wordFilters (list[string]) – List of normalizing filters used to process words before indexing. The list if supported filters can be found here: http://franz.com/agraph/support/documentation/current/text-index.html
innerChars (list[string]) –
The character set to be used as the constituent characters of a word. Should be a list of character classes. Valid classes are:
”alpha”`: All (unicode) alphabetic characters.
"digit"
: All base-10 digits."alphanumeric"
: All digits and alphabetic characters.a single character
a range of characters: A single character, followed by a dash (-) character, followed by another single character.
borderChars (list[string]) – The character set to be used as the border characters of indexed words. Uses the same syntax as
innerChars
.tokenizer (string) – Controls the way in which the text is plit into tokens. Can be either
"default"
or"japanese"
. Note that thejapanese
tokenizer ignoresinnerChars
andborderChars
.
- namespace(prefix)¶
Creates 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. Indexing into the object or calling it like a function will have the same effect.
>>> from franz.openrdf.connect import ag_connect >>> conn = ag_connect('repo') >>> ex = conn.namespace('http://franz.com/example/') >>> ex.foo <http://franz.com/example/foo> >>> ex['bar'] <http://franz.com/example/bar> >>> ex('baz') <http://franz.com/example/baz>
- Parameters:
prefix (str) – Prefix prepended to URIs created by the returned object.
- Returns:
An object that can be used to create URIs.
- nearest_neighbor(text, minScore=0.0, topN=5, selector=None)¶
An embedding is computed for the given text string and the closest embeddings to that embedding are computed. embeddings with a matching score less than minScore are ignored. The best topN matches are returned. The return value is a json list of results. Each item in the list is a list of: object id, matching score, text of the object, and then two fields not used.
- object_embedding(object_id)¶
Return the embedding for the given object_id. The embedding returned is a list of floating point numbers
- object_property_value(object_id, property)¶
Return the value of the given property of the given object_id. object_id can be a string like “http://franz.com/vdb/id/5” or it can be a URI object. The value is returned as a string in ntriple syntax. resources (URI) are surrounded by < and >. Literals begin with a double quote and in the case of a literal with data type the syntax is “value”^^type
- object_text(object_id)¶
Return the text of the object denoted by object_id. object_id can be a string like “http://franz.com/vdb/id/5” or it can be a URI object
- openSession(autocommit=False, lifetime=None, loadinitfile=False)¶
Open a session.
It is not an error to call this when a session is already active on this connection, but no new session will be created (i.e. nested sessions are not supported).
See also
- http://franz.com/agraph/support/documentation/current/http-protocol.html#sessions
More detailed explanation of session-related concepts in the HTTP API reference.
- Parameters:
autocommit (bool) – if
True
, commits are done on each request, otherwise you will need to callcommit()
orrollback()
as appropriate for your application. The default value isFalse
.lifetime (int) – Time (in seconds) before the session expires when idle. Note that the client maintains a thread that pings the session before this happens. The maximum acceptable value is 21600 (6 hours). When the value is
None
(the default) the lifetime is set to 300 seconds (5 minutes).loadinitfile (bool) – if
True
then the current initfile will be loaded for you when the session starts. The default isFalse
.
- optimizeIndices(level=None, wait=None)¶
Optimize indices.
Please see documentation for argument values and meanings:
https://franz.com/agraph/support/documentation/current/triple-index.html#optimize
- prepareBooleanQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)¶
Parse
query
into a boolean query object which can be executed against the triple store.- Parameters:
queryLanguage (QueryLanguage) – Either
QueryLanguage.SPARQL
orQueryLanguage.PROLOG
.query (string) – The query string (must contain an
ASK
query).baseURI (string|URI) – An optional base used to resolve relative URIs in the query.
queryString (string) – Legacy name of the
query
parameter.
- Returns:
A query object.
- Return type:
- prepareGraphQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)¶
Parse
query
into a graph query object which can be executed against the triple store.- Parameters:
queryLanguage (QueryLanguage) – Either
QueryLanguage.SPARQL
orQueryLanguage.PROLOG
.query (string) – The query string (must be a``CONSTRUCT`` or
DESCRIBE
query).baseURI (string|URI) – An optional base used to resolve relative URIs in the query.
queryString (string) – Legacy name of the
query
parameter.
- Returns:
A query object.
- Return type:
- prepareQuery(queryLanguage, queryString, baseURI=None)¶
Embed ‘queryString’ into a query object which can be executed against the RDF storage.
- prepareTupleQuery(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)¶
Parse
query
into a tuple query object which can be executed against the triple stroe.- Parameters:
queryLanguage (QueryLanguage) – Either
QueryLanguage.SPARQL
orQueryLanguage.PROLOG
.query (string) – The query string (must contain a
SELECT
query).baseURI (string|URI) – An optional base used to resolve relative URIs in the query.
queryString (string) – Legacy name of the
query
parameter.
- Returns:
A query object.
- Return type:
- prepareUpdate(queryLanguage=QueryLanguage.SPARQL, query=None, baseURI=None, queryString=None)¶
Parse
query
into an update query object which can be executed against the triple store.- Parameters:
queryLanguage (QueryLanguage) – Either
QueryLanguage.SPARQL
orQueryLanguage.PROLOG
.query (string) – The query string (must contain an
UPDATE
query).baseURI (string|URI) – An optional base used to resolve relative URIs in the query.
queryString (string) – Legacy name of the
query
parameter.
- Returns:
A query object.
- Return type:
- putSpinFunction(uri, sparqlQuery, arguments)¶
- Adds a Spin function.
uri - Spin function identifier sparqlQuery - Spin function query text arguments - names of arguments in the sparqlQuery
- putSpinMagicProperty(uri, sparqlQuery, arguments)¶
- Add a Spin magic property.
uri - Spin magic property identifier sparqlQuery arguments - names of arguments to the sparqlQuery - must contain the leading question mark
- registerDatatypeMapping(predicate=None, datatype=None, nativeType=None)¶
Register an inlined datatype.
- registerEncodedIdPrefix(prefix, format)¶
Registers a single encoded prefix.
See: https://franz.com/agraph/support/documentation/current/encoded-ids.html
- registerEncodedIdPrefixes(registrations)¶
Registers multiple encoded prefixes. Any kind of iteratable collection of items with a prefix attribute and format attribute, or the prefix at index 0 and the format at index 1 will do (e.g. a list of tuples). Using PrefixFormat instances also works well.
See: https://franz.com/agraph/support/documentation/current/encoded-ids.html
- registerNeighborMatrix(name, generator, group_uris, max_depth=2)¶
Construct a neighbor matrix named
name
.The generator named
generator
is applied to each URI ingroup_uris
, computing edges to max depthmax_depth
.Requires a dedicated session.
- Parameters:
name (string) – Name that will be used to identify the matrix.
generator (string) – Name of the SNA generator used to compute the edges. See
registerSNAGenerator()
.group_uris (list[URI|string]) – Initial list of vertices from which the graph will be created.
max_depth (int) – Max distance from the initial vertices.
- registerSNAGenerator(name, subjectOf=None, objectOf=None, undirected=None, generator_query=None)¶
Create a new SNA generator named
name
. If one already exists with the same name - redefine it.The edges traversed by the new generator can be defined in one of two ways:
Using three lists of predicates to define edges between subjects and objects of triples (
subjectOf
,objectOf
,undirected
).Using a Prolog query (
generator_query
).
Requires a dedicated session.
- Parameters:
name (string) – Name of the new/modified generator.
subjectOf (list[URI|string]) – Create object to subject edges for these predicates.
objectOf (list[URI|string]) – Create subject to object edges for these predicates.
undirected (list[URI|string]) – Create edges in both directions for these predicates.
generator_query – A Prolog query that generates neighbors given a start node
?node
.
- remove(arg0, arg1=None, arg2=None, contexts=None)¶
Call
removeTriples()
orremoveStatement()
.Best practice is to avoid
remove()
and useremoveTriples()
orremoveStatement()
directly.Note that
context
fields of statements passed to this method are ignored.arg0
may be aStatement
. If so, thenarg1
andarg2
default to None.arg0
,arg1
, andarg2
may be the subject, predicate and object of a triple.
- removeNamespace(prefix)¶
Remove a namespace declaration by removing the association between a prefix and a namespace name.
- Parameters:
prefix (string) – Namespace prefix.
- removeQuads(quads, ntriples=False)¶
Remove enumerated quads from this repository. Each quad can be a list or a tuple of
Value
objects.- Parameters:
quads (Iterable[list[string|Value]|tuple[string|Value]]) – List of quads. Each element can be either a statement or a list or tuple of
Value
objects or strings.ntriples (bool) – If
True
, parts of the quads are assumed to be strings in N-Triples format and are sent to the server without any conversion.
- removeQuadsByID(tids)¶
Remove all quads with matching IDs.
- Parameters:
tids (list[int]) – List of IDs to be removed.
- removeQueryOption(name)¶
Remove a namespace declaration by removing the association between a prefix and a namespace name.
- Parameters:
prefix (string) – Query option name.
- removeStatement(statement, contexts=None)¶
Remove the supplied statement from the specified contexts in the repository.
- removeTriples(subject, predicate, object, contexts='ALL_CONTEXTS')¶
Remove the statement(s) with the specified subject, predicate and object from the repository, optionally restricted to the specified contexts.
- remove_objects(text=None, all=False, property=None, value=None)¶
Remove zero or more objects. If all is True then all objects are removed. otherwise if text is given then it specifies the object to remove. otherwise all objects with the given property having the given value are removed.
- rollback()¶
Roll back changes on open session.
- runAsUser(username=None)¶
Only for use as a superuser during a session.
Runs requests on this connection as username.
None - the default - clears the setting.
- saveResponse(fileobj, accept, raiseAll=False)¶
Save the server response(s) for the call(s) within the with statement to fileobj, using accept for the response type requested.
Deprecated since version 100.0.1: Use getStatements(output=…) or evaluate(output=…) to export data.
Responses will be uncompressed and saved to fileobj, but not decoded. Therefore, the API called will likely error out shortly after the response is saved (which is okay because we really only want the side-effect of saving the response).
RequestError is always thrown on errors from the server. Other exceptions can be optionally raised with raiseAll=True.
You will only want to make only one conn call in the with statement unless you wrap each call in its own try/except.
Example:
- with open(‘out’, ‘w’) as response:
- with conn.saveResponse(response, ‘application/rdf+xml’):
conn.getStatements(None, None, None) # The response is written to response
- session(autocommit=False, lifetime=None, loadinitfile=False)¶
A session context manager for use with the
with
statement:with conn.session(): # Automatically calls openSession at block start # Do work # Automatically calls closeSession at block end # or in case of an exception.
- Parameters:
autocommit (bool) – if
True
, commits are done on each request, otherwise you will need to callcommit()
orrollback()
as appropriate for your application. The default value isFalse
.lifetime (int) – Time (in seconds) before the session expires when idle. Note that the client maintains a thread that ping the session before this happens.
loadinitfile (bool) – if
True
then the current initfile will be loaded for you when the session starts. The default isFalse
.
- setAddCommitSize(triple_count)¶
Set the value of
add_commit_size
. :param triple_count: Value ofadd_commit_size
.
- setAttributeDefinition(attr_def)¶
Define or modify an attribute definition.
- Parameters:
attr_def – Attribute definition.
- setAttributeFilter(attribute_filter)¶
Set the static attribute filter.
- Parameters:
attribute_filter (AttributeFilter|str) – The filter - either an AttributeFilter or a string.
- setDuplicateSuppressionPolicy(mode)¶
Set the duplicate suppression policy used by the store. See https://franz.com/agraph/support/documentation/current/deleting-duplicate-triples.html
- Parameters:
mode (str) – Duplicate suppression policy: “spo”, “spog” or None (disable suppression).
- setGeoType(geoType)¶
Set the current geospatial coordinate system.
- Parameters:
geoType (GeoType) – The new coordinate system.
- setNamespace(prefix, name)¶
Define or redefine a namespace mapping in the repository.
- Parameters:
prefix (string) – Namespace prefix.
name (string) – Namespace URI.
- setQueryOption(name, value)¶
Set a query option value for all queries in this repository for the current user.
- Parameters:
name (string) – Query option name.
value (string) – Query option value.
- Raises:
RequestError – if given option name is not a defined query option.
- setTransactionSettings(settings=None, **kwargs)¶
Change distributed transaction settings used by this connection.
The new settings can be described either by a
TransactionSettings
object or by passing individual parameters as keyword arguments. Argument names must match the fields of theTransactionSettings
class.If a settings object is passed all settings will be replaced. Keyword arguments will only affect specific parameters, any setting for which there is no corresponding keyword argument in the call will keep its current value.
If both types of arguments are passed they will be merged, with keyword arguments taking precedence over values from the settings object.
- Parameters:
settings (TransactionSettings) – A settings object.
kwargs – Individual transaction parameters. See
TransactionSettings
for a list of valid names.
- setUserAttributes(attributes)¶
Set user attributes (used to filter the store during queries).
- size(contexts='ALL_CONTEXTS')¶
Returns the number of (explicit) statements that are in the specified contexts in this repository.
- Parameters:
contexts (Iterable[string|URI]) – List of contexts (graph URIs) to count the statements in. By default statements in all graphs will be counted.
- temporaryTransactionSettings(settings=None, **kwargs)¶
Create a context in which transaction settings of this connection are modified or replaced.
If a settings object is given as an argument it will replace all transaction settings. Keyword arguments may be used to modify individual transaction parameters without affecting other settings.
Here is how this method can be used to temporarily lower durability requirements while executing some operations:
with conn.temporaryTransactionSettings(durability='min'): # Durability is now 'min', other settings remain unchanged. # Perform some operations ... conn.commit() # At this points durability will be restored to its original value.
- Parameters:
settings (TransactionSettings) – A settings object.
kwargs – Individual transaction parameters. See
TransactionSettings
for a list of valid names.
- Returns:
A context manager that takes care of changing and restroing distributed transaction settings.
- temporaryUserAttributes(attributes)¶
Set user attributes for the duration of a code block.
This method returns a context manager. It can be used like this:
with conn.temporaryUserAttributes({'access-level': 'low'}): conn.do_something()
- unregisterEncodedIdPrefix(prefix)¶
Unregisters the specified encoded id prefix.
See: https://franz.com/agraph/support/documentation/current/encoded-ids.html
- warmup(includeStrings=None, includeTriples=None, indices=None)¶
Warm up specified parts of the repository in order to speed up access.
- Parameters:
includeStrings (bool) – warm up the string table (default is True).
includeTriples (bool) – warm up the triple indices (default is True). Use the indices argument to specify the indices to warm up.
indices (list[str]|str) – list of indices to warm up (default is None meaning all indices). indices can be a single string naming an index (e.g. ‘spogi’) or a list of strings (e.g. [‘spogi’, ‘posgi’]). Note that includeTriples must True in order for any indices be warmed up.
- franz.openrdf.repository.repositoryconnection.attribute_definition_from_dict(item)¶
- franz.openrdf.repository.repositoryconnection.dump_json_ld(source, sort_keys=False)¶
Convert a dictionary to JSON-LD string.
This basically dumps the source like a regular JSON document, but is a bit smarter about URLs and literals.
- Parameters:
source – Dictionary to be serialized.
sort_keys – if True make sure that metadata keys (@context etc) appear first.
- Returns:
a JSON-serializable dict.
franz.openrdf.repository.repositoryresult module¶
franz.openrdf.repository.transactions module¶
Types and utilities related to transaction settings.
- class franz.openrdf.repository.transactions.TransactionSettings(*args, **kwargs)¶
Bases:
TransactionSettings
A named tuple encapsulating a set of distributed transaction parameters.
Each parameter here can be set to
None
, in which case the actual value of that setting will be determined by the server.When creating a new instance not all arguments have to be specified, the default value for all settings is
None
.- Attributes:
- durability: (int|str):
The durability is a positive integer value that specifies how many instances must have a commit ingested in order for that commit to be considered durable. The count includes the instance that made the commit.
A durability setting of 1 means that when an instance makes a commit that commit is immediately considered durable before even being sent to any other instance (the commit will still be sent to the other instances after it’s considered durable).
A value that equals the total number of nodes in the cluster means that every instance must have ingested the commit before it’s considered durable. If one or more instances are stopped at the moment then the commit will not become durable until the stopped instances are restarted.
- Three symbolic values (strings) may be used instead of numbers:
‘min’, which simply means 1.
‘max’, which means that all instances in the cluster must ingest a commit before it is considered durable.
‘quorum’, which means that more than a half of instances must ingest a commit for it to be considered durable.
- distributed_transaction_timeout (int|datetime.timedelta):
Use this setting to specify how long a commit call will wait for the commit to become durable. It’s a non-negative integer (number of seconds).
If the durability is greater than one then the committing process has to wait for acknowledgements from the other servers that the transaction was committed. The committing process returns to the caller when the durability has been reached or the distributed transaction timeout seconds has passed, whichever comes first.
When the commit returns the caller does not know if durability has been reached.
- transaction_latency_count (int):
Number of commits. Use this setting to limit the number of non-durable (pending) commits that can be active on the cluster. If this limit is reached all new commits will signal an error (and have to be retried).
When a commit is done the committing process tries to wait until the commit is durable but if that takes too long (see distributed_transaction_timeout) then commit will return with the system still working on making that transaction durable.
If the latency count is 4 then even if the last four commits are not yet durable it is possible to do one more commit. But if there are five pending transactions then any attempt to commit will result in an error.
Another example: If you set the latency count to zero then each commit must be durable before the next commit can be ingested.
- transaction_latency_timeout (int|datetime.timedelta):
Use this setting to specify how long a commit operation should wait for the transaction_Latency_count to be satisfied before throwing an error.