There is no standard API for RDF processors. We put together a simple, clean API that suits our uses of RDF very well. There are other APIs such as SIRPaC, RAX, none of which are supported by 4RDF now.
Please see the 4RDF command line documentation for command line help
Module Summary
integer NORMAL = 0
integer IGNORE_CASE = 1
integer REGEX = 2
Class Summary | |
Model
|
Method Summary | |
__init__
|
Initializer for an RDF model instance |
addContainer
|
Add a container to the model. This involves adding a statement for the container type, and a container statement for each item in the collection |
extractContainer
|
Build a container object from the container item relationships in the model (_1, _2, etc.). |
add
|
Add statement(s) to the model |
contains
|
Check if a statement is in the model |
containsPattern
|
Determine if any statement matching the given criteria is in the model. |
statements
|
Returns all the statments in the model |
remove
|
Remove statement(s) from the model |
removePattern
|
Remove all statements from the model that match the specified pattern |
size
|
Returns the number of statements in the model |
complete
|
Return all the statements in the model that match the given pattern. |
exclude
|
Return all the statements in the model that DO NOT match the given pattern. |
generateUri
|
Generates URIs for "anonymous" resources, such as reified statements. The default method is to generate a UUID URN, but this can be easily overriden. |
Method Details |
__init__(driver, schemaHandler)
Initializer for an RDF model instance
ParametersReturn Value
driver
of type Any object meeting the protocol of Ft.Rdf.Drivers.Memory.Memory
This is the object used to abstract the storage and management of the RDF statements. It could be a memory buffer, a DBMS connection, or even some code around a UserList
schemaHandler
of type Ft.Rdf.SchemaHandler.SchemaHandler
This object is used to provide RDF schema support. If None, no schema support will be available for the resulting model. The default is None
None
addContainer(container)
Add a container to the model. This involves adding a statement for the container type, and a container statement for each item in the collection
ParametersReturn Value
container
of type Ft.Rdf.Container.Container
The container instance
None
extractContainer(uri)
Build a container object from the container item relationships in the model (_1, _2, etc.).
ParametersReturn Value
uri
of type Ft.Rdf.Container.Container
The uri of the represented container
- Ft.Rdf.Container.Container
A container object (Bag, Alt or Set) representing all the container item relationships. Note that the returned object is not live. Changes to the model after the container is extracted will not affect the extracted container.
add(statements, checkSchema=1)
Add statement(s) to the model
ParametersReturn Value
statements
of type list of Rdf.Statement.Statement
The new statement(s) to add to the model. Can be either a list of or a single Statement instance.
checkSchema
of type boolean
True enforces that the addition does not violate the RDF schema.
None
contains(statement)
Check if a statement is in the model
ParametersReturn Value
statement
of type Rdf.Statement.Statement
The statement to check.
None
containsPattern(subject, predicate, object, statementUri=None, sourceUri=None, subjectFlags=0, predicateFlags=0, objectFlags=0, statementUriFlags=0, sourceUriFlags=0)
Determine if any statement matching the given criteria is in the model.
ParametersReturn Value
subject
of type string
If not None, statements must have the given subject to match
predicate
of type string
If not None, statements must have the given predicate to match
object
of type string
If not None, statements must have the given object to match
statementUri
of type string
If not None, statements must have the given statementUri to match
sourceUri
of type string
If not None, statements must have the given sourceUri to match
subjectFlags
of type integer
Bit-wise OR'd module constants for matching the subject
predicateFlags
of type integer
Bit-wise OR'd module constants for matching the predicate
objectFlags
of type integer
Bit-wise OR'd module constants for matching the object
statementUriFlags
of type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlags
of type integer
Bit-wise OR'd module constants for matching the sourceUri
- boolean
True if any statements in the model match the given pattern
statements()
Returns all the statments in the model
ParametersNoneReturn Value
- list of Ft.Rdf.Statement.Statement
Sll the statements in the model
remove(statements)
Remove statement(s) from the model
ParametersReturn Value
statements
of type list of Rdf.Statement.Statement
The statement(s) to remove. Can be either list of or single Ft.Rdf.Statement.Statement
None
removePattern(subject, predicate, object, statementUri=None, sourceUri=None, subjectFlags=0, predicateFlags=0, objectFlags=0, statementUriFlags=0, sourceUriFlags=0)
Remove all statements from the model that match the specified pattern
ParametersReturn Value
subject
of type string
If not None, statements must have the given subject to match
predicate
of type string
If not None, statements must have the given predicate to match
object
of type string
If not None, statements must have the given object to match
statementUri
of type string
If not None, statements must have the given statementUri to match
sourceUri
of type string
If not None, statements must have the given sourceUri to match
subjectFlags
of type integer
Bit-wise OR'd module constants for matching the subject
predicateFlags
of type integer
Bit-wise OR'd module constants for matching the predicate
objectFlags
of type integer
Bit-wise OR'd module constants for matching the object
statementUriFlags
of type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlags
of type integer
Bit-wise OR'd module constants for matching the sourceUri
None
size()
Returns the number of statements in the model
ParametersNoneReturn Value
- integer
The number of statements in the model. Will be equal to or greater than 0
complete(subject, predicate, object, statementUri=None, sourceUri=None, subjectFlags=0, predicateFlags=0, objectFlags=0, statementUriFlags=0, sourceUriFlags=0)
Return all the statements in the model that match the given pattern.
ParametersReturn Value
subject
of type string
If not None, statements must have the given subject to match
predicate
of type string
If not None, statements must have the given predicate to match
object
of type string
If not None, statements must have the given object to match
statementUri
of type string
If not None, statements must have the given statementUri to match
sourceUri
of type string
If not None, statements must have the given sourceUri to match
subjectFlags
of type integer
Bit-wise OR'd module constants for matching the subject
predicateFlags
of type integer
Bit-wise OR'd module constants for matching the predicate
objectFlags
of type integer
Bit-wise OR'd module constants for matching the object
statementUriFlags
of type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlags
of type integer
Bit-wise OR'd module constants for matching the sourceUri
- list of Ft.Rdf.Statement.Statement
The matching statements in the model.
exclude(subject, predicate, object, statementUri=None, sourceUri=None, subjectFlags=0, predicateFlags=0, objectFlags=0, statementUriFlags=0, sourceUriFlags=0)
Return all the statements in the model that DO NOT match the given pattern.
ParametersReturn Value
subject
of type string
If not None, statements must have the given subject to match
predicate
of type string
If not None, statements must have the given predicate to match
object
of type string
If not None, statements must have the given object to match
statementUri
of type string
If not None, statements must have the given statementUri to match
sourceUri
of type string
If not None, statements must have the given sourceUri to match
subjectFlags
of type integer
Bit-wise OR'd module constants for matching the subject
predicateFlags
of type integer
Bit-wise OR'd module constants for matching the predicate
objectFlags
of type integer
Bit-wise OR'd module constants for matching the object
statementUriFlags
of type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlags
of type integer
Bit-wise OR'd module constants for matching the sourceUri
- list of Ft.Rdf.Statement.Statement
All statements in the model not matching the pattern.
generateUri()
Generates URIs for "anonymous" resources, such as reified statements. The default method is to generate a UUID URN, but this can be easily overriden.
ParametersNoneReturn Value
- string
A generated URI
Module Summary
Class Summary | |
Statement
|
Represents an RDF triple or statement |
Represents an RDF triple or statement
Method Summary | |
__init__
|
Initializer for an RDF statement instance |
reify
|
Prepare the statement in the model so that it can be the subject of other statements. See the RDF spec for details of how statements are expanded for reification. Note that the original statement is not removed by reification. The statement's uri is used as the subject of the added statements, or a URI is generated if the statement's uri is an empty string. |
Method Details |
__init__(subject, predicate, object, uri='', sourceUri='')
Initializer for an RDF statement instance
ParametersReturn Value
subject
of type string
The subject of the statement
predicate
of type string
The predicate of the statement
object
of type string
The object of the statement
uri
of type string
The URI of the statement. This is an empty string except for very sophisticated use.
sourceUri
of type string
The uri of the document containing this statement. This is an empty string except for very sophisticated use.
None
reify(model, uri=None)
Prepare the statement in the model so that it can be the subject of other statements. See the RDF spec for details of how statements are expanded for reification. Note that the original statement is not removed by reification. The statement's uri is used as the subject of the added statements, or a URI is generated if the statement's uri is an empty string.
ParametersReturn Value
model
of type Ft.Rdf.Model
The model that is used to add the additional statements generated bu reification.
uri
of type string
URI to be assigned to the statement. If None, then first the statement object is checked for a URI, otherwise the model generates a URI for the reified statement. Default is None.
None
Module Summary
Class Summary | |
SchemaHandler
|
Processing of RDF schema information on behalf of a model instance. |
Processing of RDF schema information on behalf of a model instance.
Method Summary | |
__init__
|
Initializer for a SchemaHandler. There are no parameters. |
isCoreRdfs
|
Checks whether a statement comes from the core RDF meta-model. |
isInstance
|
Checks whether a resource is an instance of a class. Note that this is also true if the resource is an instance of any subclass of the given class. |
isSubClass
|
Checks whether a class is an instance of another class. |
Method Details |
__init__()
Initializer for a SchemaHandler. There are no parameters.
ParametersNoneReturn ValueNone
isCoreRdfs(stmt)
Checks whether a statement comes from the core RDF meta-model.
ParametersReturn Value
stmt
of type Rdf.Statement.Statement
The statement to check.
- boolean
1 if the statement comes from the core RDF meta-model, otherwise 0.
isInstance(model, obj, class_)
Checks whether a resource is an instance of a class. Note that this is also true if the resource is an instance of any subclass of the given class.
ParametersReturn Value
model
of type Rdf.Model.Model
The model in which the condition is be checked
obj
of type string
The URI of the resource to check for class membership.
class_
of type string
The URI of the class to be checked.
- boolean
1 if the statement is an instance of the class, otherwise 0.
isSubClass(model, class1, class2)
Checks whether a class is an instance of another class.
ParametersReturn Value
model
of type Rdf.Model.Model
The model in which the condition is be checked
class1
of type string
The URI of the class to check as descendant.
class2
of type string
The URI of the class to check as ancestor.
- boolean
1 if the first class is a descendant of the second, otherwise 0.
Serializers create a serialized representation from an RDF model, or populate a model with statements from a serialized form. Currently the only built-in serializer for 4RDF handles a DOM form representing the XML serialization from the RDF Model and syntax recommendation.
Serialize or deserialize a model based on the XML serialization in the RDF Model and Syntax recommendation.
Module Summary
Class Summary | |
Serializer
|
Serialize or deserialize a model based on the XML serialization in the RDF Model and Syntax recommendation. |
Serialize or deserialize a model based on the XML serialization in the RDF Model and Syntax recommendation.
Method Summary | |
serialize
|
Construct a DOM representing statements in the model. |
deserialize
|
Generate RDF statements from an XML serialization and insert these into a Model. |
Method Details |
serialize(model, nsMap=None, selectUri=None, implementation=Ft.Lib.pDomlette.DOMImplementation)
Construct a DOM representing statements in the model.
ParametersReturn Value
model
of type Ft.Rdf.Model
The model from which the serialization is to be extracted
nsMap
of type dictionary
A mapping from URIs that are found in the model to prefixes that will be used for the corresponding XML namespaces in the serialization. If none, prefixes will be generated for each unique namespaceURI
selectUri
of type string
Only statements with this URI will be selected for serialization. If None, all statements will be serialized. Note that if the model is set up for schema validation, the RDFS schema statements are suppressed from the output.
implementation
of type xml.dom.DOMImplementation
An instance of a DOM implementation used to create the serialized document
- xml.dom.Document
The DOM Document node that represents the serialized document.
deserialize(model, node, sourceUri)
Generate RDF statements from an XML serialization and insert these into a Model.
ParametersReturn Value
model
of type Ft.Rdf.Model
The model into which the statements generated by the deserialization is to be entered.
node
of type xml.dom.Node
The DOM node representing the serialization from which the statements are extracted.
sourceUri
of type string
The base URI of the serialization. Usually this would be the URI of the document where the serialization is found.
None