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
driverof 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
schemaHandlerof 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
containerof 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
uriof 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
statementsof 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.
checkSchemaof 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
statementof 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
subjectof type string
If not None, statements must have the given subject to match
predicateof type string
If not None, statements must have the given predicate to match
objectof type string
If not None, statements must have the given object to match
statementUriof type string
If not None, statements must have the given statementUri to match
sourceUriof type string
If not None, statements must have the given sourceUri to match
subjectFlagsof type integer
Bit-wise OR'd module constants for matching the subject
predicateFlagsof type integer
Bit-wise OR'd module constants for matching the predicate
objectFlagsof type integer
Bit-wise OR'd module constants for matching the object
statementUriFlagsof type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlagsof 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
statementsof 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
subjectof type string
If not None, statements must have the given subject to match
predicateof type string
If not None, statements must have the given predicate to match
objectof type string
If not None, statements must have the given object to match
statementUriof type string
If not None, statements must have the given statementUri to match
sourceUriof type string
If not None, statements must have the given sourceUri to match
subjectFlagsof type integer
Bit-wise OR'd module constants for matching the subject
predicateFlagsof type integer
Bit-wise OR'd module constants for matching the predicate
objectFlagsof type integer
Bit-wise OR'd module constants for matching the object
statementUriFlagsof type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlagsof 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
subjectof type string
If not None, statements must have the given subject to match
predicateof type string
If not None, statements must have the given predicate to match
objectof type string
If not None, statements must have the given object to match
statementUriof type string
If not None, statements must have the given statementUri to match
sourceUriof type string
If not None, statements must have the given sourceUri to match
subjectFlagsof type integer
Bit-wise OR'd module constants for matching the subject
predicateFlagsof type integer
Bit-wise OR'd module constants for matching the predicate
objectFlagsof type integer
Bit-wise OR'd module constants for matching the object
statementUriFlagsof type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlagsof 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
subjectof type string
If not None, statements must have the given subject to match
predicateof type string
If not None, statements must have the given predicate to match
objectof type string
If not None, statements must have the given object to match
statementUriof type string
If not None, statements must have the given statementUri to match
sourceUriof type string
If not None, statements must have the given sourceUri to match
subjectFlagsof type integer
Bit-wise OR'd module constants for matching the subject
predicateFlagsof type integer
Bit-wise OR'd module constants for matching the predicate
objectFlagsof type integer
Bit-wise OR'd module constants for matching the object
statementUriFlagsof type integer
Bit-wise OR'd module constants for matching the statementUri
sourceUriFlagsof 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
subjectof type string
The subject of the statement
predicateof type string
The predicate of the statement
objectof type string
The object of the statement
uriof type string
The URI of the statement. This is an empty string except for very sophisticated use.
sourceUriof 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
modelof type Ft.Rdf.Model
The model that is used to add the additional statements generated bu reification.
uriof 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
stmtof 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
modelof type Rdf.Model.Model
The model in which the condition is be checked
objof 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
modelof type Rdf.Model.Model
The model in which the condition is be checked
class1of type string
The URI of the class to check as descendant.
class2of 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
modelof type Ft.Rdf.Model
The model from which the serialization is to be extracted
nsMapof 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
selectUriof 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.
implementationof 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
modelof type Ft.Rdf.Model
The model into which the statements generated by the deserialization is to be entered.
nodeof type xml.dom.Node
The DOM node representing the serialization from which the statements are extracted.
sourceUriof type string
The base URI of the serialization. Usually this would be the URI of the document where the serialization is found.
None