4RDF


The 4RDF API

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.

Module Ft.Rdf.Model

Module Summary

Type Defs, Enums, Unions and Constants

Constant NORMAL

integer NORMAL = 0

Constant IGNORE_CASE

integer IGNORE_CASE = 1

Constant REGEX

integer REGEX = 2

Classes

Class Summary
Model  

 

Class 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__

__init__(driver, schemaHandler)

Initializer for an RDF model instance

Parameters
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

Return Value
None


addContainer

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

Parameters
container of type Ft.Rdf.Container.Container

The container instance

Return Value
None


extractContainer

extractContainer(uri)

Build a container object from the container item relationships in the model (_1, _2, etc.).

Parameters
uri of type Ft.Rdf.Container.Container

The uri of the represented container

Return Value
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

add(statements, checkSchema=1)

Add statement(s) to the model

Parameters
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.

Return Value
None


contains

contains(statement)

Check if a statement is in the model

Parameters
statement of type Rdf.Statement.Statement

The statement to check.

Return Value
None


containsPattern

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.

Parameters
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

Return Value
boolean

True if any statements in the model match the given pattern



statements

statements()

Returns all the statments in the model

Parameters
None
Return Value
list of Ft.Rdf.Statement.Statement

Sll the statements in the model



remove

remove(statements)

Remove statement(s) from the model

Parameters
statements of type list of Rdf.Statement.Statement

The statement(s) to remove. Can be either list of or single Ft.Rdf.Statement.Statement

Return Value
None


removePattern

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

Parameters
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

Return Value
None


size

size()

Returns the number of statements in the model

Parameters
None
Return Value
integer

The number of statements in the model. Will be equal to or greater than 0



complete

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.

Parameters
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

Return Value
list of Ft.Rdf.Statement.Statement

The matching statements in the model.



exclude

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.

Parameters
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

Return Value
list of Ft.Rdf.Statement.Statement

All statements in the model not matching the pattern.



generateUri

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.

Parameters
None
Return Value
string

A generated URI



Module Ft.Rdf.Statement

Module Summary

Classes

Class Summary
Statement Represents an RDF triple or statement 

 

Class 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__

__init__(subject, predicate, object, uri='', sourceUri='')

Initializer for an RDF statement instance

Parameters
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.

Return Value
None


reify

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.

Parameters
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.

Return Value
None


Module Ft.Rdf.SchemaHandler

Module Summary

Classes

Class Summary
SchemaHandler Processing of RDF schema information on behalf of a model instance. 

 

Class SchemaHandler

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__

__init__()

Initializer for a SchemaHandler. There are no parameters.

Parameters
None
Return Value
None


isCoreRdfs

isCoreRdfs(stmt)

Checks whether a statement comes from the core RDF meta-model.

Parameters
stmt of type Rdf.Statement.Statement

The statement to check.

Return Value
boolean

1 if the statement comes from the core RDF meta-model, otherwise 0.



isInstance

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.

Parameters
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.

Return Value
boolean

1 if the statement is an instance of the class, otherwise 0.



isSubClass

isSubClass(model, class1, class2)

Checks whether a class is an instance of another class.

Parameters
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.

Return Value
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.

Module Ft.Rdf.Serializers.Dom

Serialize or deserialize a model based on the XML serialization in the RDF Model and Syntax recommendation.

Module Summary

Classes

Class Summary
Serializer Serialize or deserialize a model based on the XML serialization in the RDF Model and Syntax recommendation. 

 

Class Serializer

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

serialize(model, nsMap=None, selectUri=None, implementation=Ft.Lib.pDomlette.DOMImplementation)

Construct a DOM representing statements in the model.

Parameters
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

Return Value
xml.dom.Document

The DOM Document node that represents the serialized document.



deserialize

deserialize(model, node, sourceUri)

Generate RDF statements from an XML serialization and insert these into a Model.

Parameters
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.

Return Value
None