com.hp.hpl.mesa.rdf.jena.model
Interface Model

All Superinterfaces:
ModelCon, RDFReaderF, RDFWriterF
All Known Subinterfaces:
DAMLModel
All Known Implementing Classes:
ModelBdb, ModelCom, ModelMem, ModelRDB

public interface Model
extends ModelCon, RDFReaderF, RDFWriterF

An RDF Model.

An RDF model is a set of Statements. Methods are provided for creating resources, properties and literals and the Statements which link them, for adding statements to and removing them from a model, for querying a model and set operations for combining models.

This interface defines a set of primitive methods. A set of convenience methods which extends this interface, e.g. performing automatic type conversions and support for enhanced resources, is defined in ModelCon.

System Properties

Firewalls and Proxies

Some of the methods, e.g. the read methods, may have to traverse a firewall. This can be accomplished using the standard java method of setting system properties. To use a socks proxy, include on the java command line:

-DsocksProxyHost=[your-proxy-domain-name-or-ip-address]

To use an http proxy, include on the command line:

-DproxySet=true -DproxyHost=[your-proxy] -DproxyPort=[your-proxy-port-number]

Alternatively, these properties can be set programatically, e.g.

   System.getProperties().put("proxySet","true");
   System.getProperties().put("proxyHost","proxy.hostname");
   System.getProperties().put("proxyPort",port_number);
 

Version:
$Name: $ $Revision: 1.10 $Date: 2002/01/05 12:11:56 $'
Author:
bwm

Method Summary
 Model abort()
          Abort the current transaction and abandon any changes in progress.
 Model add(Model m)
          Add all the statements in another model to this model.
 Model add(Statement s)
          Add a statement to this model.
 Model add(StmtIterator iter)
          Add all the statements returned by an iterator to this model.
 Model begin()
          Begin a new transation.
 void close()
          Close the Model and free up resources held.
 Model commit()
          Commit the current transaction.
 boolean contains(Resource s, Property p)
          Determine whether this model contains any statements with a given subject and property.
 boolean contains(Resource s, Property p, RDFNode o)
          Determine if a statement is present in this model.
 boolean contains(Statement s)
          Determine if a statement is present in this model.
 boolean containsAll(Model model)
          Determine if all of the statements in a model are also contained in this model.
 boolean containsAll(StmtIterator iter)
          Determine if all of the statements returned by an iterator are contained in this model.
 boolean containsAny(Model model)
          Determine if any of the statements in a model are also contained in this model.
 boolean containsAny(StmtIterator iter)
          Determine if any of the statements returned by an iterator are contained in this model.
 Literal createLiteral(java.lang.String v, java.lang.String language)
          create a literal from a String value with a specified language
 Literal createLiteral(java.lang.String v, java.lang.String language, boolean wellFormed)
          create a literal from a String value with a specified language
 Property createProperty(java.lang.String nameSpace, java.lang.String localName)
          Create a property
 Resource createResource()
          Create a new anonymous resource.
 Resource createResource(java.lang.String uri)
          Create a new resource.
 Statement createStatement(Resource s, Property p, RDFNode o)
          Create a Statement instance.
 Model difference(Model model)
          Create a new model containing all the statements in this model which are not in another.
 boolean equals(java.lang.Object model)
          Test whether one model is the equal to another.
 Statement getProperty(Resource s, Property p)
          Return a statement with given subject and property.
 Property getProperty(java.lang.String nameSpace, java.lang.String localName)
          Return a Property instance in this model.
 Resource getResource(java.lang.String uri)
          Return a Resource instance in this model.
 boolean independent()
          Determine whether this model is independent.
 Model intersection(Model model)
          Create a new model containing all the statements which are in both this model and another.
 boolean isReified(Statement s)
          Determine if this statement is the subject of any statements in this model
 NsIterator listNameSpaces()
          List all namespaces of predicates in the model.
 NodeIterator listObjects()
          List all objects in a model.
 NodeIterator listObjectsOfProperty(Property p)
          List all objects of a given property.
 NodeIterator listObjectsOfProperty(Resource s, Property p)
          List the values of a property of a resource.
 StmtIterator listReifiedStatements()
          List all reified statements in the model.
 StmtIterator listStatements()
          List all statements.
 StmtIterator listStatements(Selector s)
          List the statements matching a selector.
 ResIterator listSubjects()
          List all resources which are subjects of statements.
 ResIterator listSubjectsWithProperty(Property p)
          List all subjects with a given property.
 ResIterator listSubjectsWithProperty(Property p, RDFNode o)
          List all subjects with a given property and property value
 Model query(Selector s)
          Create a new model containing the statements matching a query.
 Model read(java.io.Reader reader, java.lang.String base)
          add statements from an RDF/XML serialization
 Model read(java.io.Reader reader, java.lang.String base, java.lang.String lang)
          add RDF statements represented in language lang to the model.
 Model read(java.lang.String url)
          Add the RDF statements from an XML document.
 Model read(java.lang.String url, java.lang.String lang)
          add statements from a serializion in language lang to the model.
 Model remove(Statement s)
          Removes a statement.
 long size()
          computes the number of statements in the model.
 boolean supportsSetOperations()
          Determine whether this model supports set operations.
 boolean supportsTransactions()
          Determine whether this model supports transactions.
 Model union(Model model)
          Create a new model containing all the statements in this model together with all of those in another given model.
 Model write(java.io.Writer writer)
          Write the model as an XML document.
 Model write(java.io.Writer writer, java.lang.String lang)
          write a serialized represention of a model in a specified language.
 Model write(java.io.Writer writer, java.lang.String lang, java.lang.String base)
          write a serialized represention of a model in a specified language.
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.ModelCon
add, add, add, add, add, add, add, add, add, add, add, contains, contains, contains, contains, contains, contains, contains, contains, createAlt, createAlt, createBag, createBag, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createProperty, createResource, createResource, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, getAlt, getAlt, getBag, getBag, getProperty, getResource, getSeq, getSeq, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, remove, remove
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.RDFReaderF
getReader, getReader, setReaderClassName
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.RDFWriterF
getWriter, getWriter, setWriterClassName
 

Method Detail

size

public long size()
          throws RDFException
computes the number of statements in the model.
Returns:
the number of statements in the model
Throws:
RDFException - Generic RDF Exception

listSubjects

public ResIterator listSubjects()
                         throws RDFException
List all resources which are subjects of statements.

Subsequent operations on those resource may modify this model.

Returns:
an iterator over a set of resources which are subjects of statements in the model.
Throws:
RDFException - Generic RDF Exception

listNameSpaces

public NsIterator listNameSpaces()
                          throws RDFException
List all namespaces of predicates in the model.
Returns:
an iterator over the set of namespaces associated with predicates in the model.
Throws:
RDFException - Generic RDF Exception

listStatements

public StmtIterator listStatements()
                            throws RDFException
List all statements.

Subsequent operations on those statements may modify this model.

Returns:
an iterator over all statements in the model.
Throws:
RDFException - Generic RDF Exception

listReifiedStatements

public StmtIterator listReifiedStatements()
                                   throws RDFException
List all reified statements in the model.

Subsequent operations on those statements may modify this model.

Returns:
an iterator over the set of all reified statements in the model
Throws:
RDFException - Generic RDF Exception

getResource

public Resource getResource(java.lang.String uri)
                     throws RDFException
Return a Resource instance in this model.

Subsequent operations on the returned object may modify this model.

This method should be called if the resource may already exist in the model so that an implementation may reuse the same object. If it does not an object will be created. If it is known that an object for the resource does not already exist, then it may be more efficient to call createResource instead.

Parameters:
uri - the URI of the resource
Returns:
a resource instance
Throws:
RDFException - Generic RDF exception.

getProperty

public Property getProperty(java.lang.String nameSpace,
                            java.lang.String localName)
                     throws RDFException
Return a Property instance in this model.

Subsequent operations on the returned property may modify this model.

This method should be called if the property may already exist in the model so that an implementation may reuse the same object. If it does not an object will be created. If it is known that an object for the property does not already exist, then it may be more efficient to call createProperty instead.

Parameters:
nameSpace - the RDF namespace of the property
localName - the localName of the property in its namespace
Returns:
a property linked to this model
Throws:
RDFException - Generic RDF Exception

createResource

public Resource createResource()
                        throws RDFException
Create a new anonymous resource.

Subsequent operations on the returned resource may modify this model.

Returns:
a new anonymous resource linked to this model.
Throws:
RDFException - Generic RDF exception.

createResource

public Resource createResource(java.lang.String uri)
                        throws RDFException
Create a new resource.

Subsequent operations on the returned resource may modify this model.

Parameters:
uri - the URI of the resource to be created
Returns:
a new resource linked to this model.
Throws:
RDFException - Generic RDF exception.

createProperty

public Property createProperty(java.lang.String nameSpace,
                               java.lang.String localName)
                        throws RDFException
Create a property

Subsequent operations on the returned property may modify this model.

Parameters:
nameSpace - the nameSpace of the property
localName - the name of the property within its namespace
Returns:
a property instance
Throws:
RDFException - Generic RDF exception

createLiteral

public Literal createLiteral(java.lang.String v,
                             java.lang.String language)
                      throws RDFException
create a literal from a String value with a specified language

If v is null, then a literal with an empty string is created.

Parameters:
v - the value of the literal
language - the language associated with the literal
Returns:
a new literal representing the value v with the given language
Throws:
RDFException - generic RDF exception

createLiteral

public Literal createLiteral(java.lang.String v,
                             java.lang.String language,
                             boolean wellFormed)
                      throws RDFException
create a literal from a String value with a specified language

If v is null, then a literal with an empty string is created.

Parameters:
v - the value of the literal
language - the language associated with the literal
wellFormed - true if the Literal is well formed XML
Returns:
a new literal representing the value v with the given language
Throws:
RDFException - generic RDF exception

createStatement

public Statement createStatement(Resource s,
                                 Property p,
                                 RDFNode o)
                          throws RDFException
Create a Statement instance.

Subsequent operations on the statement or any of its parts will modify this model.

Creating a statement does not add it to the set of statements in the model.

Parameters:
s - the subject of the statement
p - the predicate of the statement
o - the object of the statement
Returns:
the new statement
Throws:
RDFException - generic RDF exception

add

public Model add(Statement s)
          throws RDFException
Add a statement to this model.
Parameters:
s - The statement to be added.
Returns:
This model.
Throws:
RDFException - Generic RDF Exception

add

public Model add(StmtIterator iter)
          throws RDFException
Add all the statements returned by an iterator to this model.
Parameters:
iter - An iterator which returns the statements to be added.
Returns:
this model
Throws:
RDFException - Generic RDF Exception

add

public Model add(Model m)
          throws RDFException
Add all the statements in another model to this model.
Parameters:
m - The model whose statements are to be added.
Returns:
this model
Throws:
RDFException - Generic RDF Exception

read

public Model read(java.lang.String url)
           throws RDFException
Add the RDF statements from an XML document.

See Model for a description of how to traverse a firewall.

Parameters:
url - of the document containing the RDF statements.
Returns:
this model
Throws:
RDFException - Generic RDF Exception

read

public Model read(java.io.Reader reader,
                  java.lang.String base)
           throws RDFException
add statements from an RDF/XML serialization
Parameters:
reader - the source of the RDF/XML
base - the base to use when converting relative to absolute uri's
Returns:
the current model
Throws:
RDFException - a generic RDF exception

read

public Model read(java.lang.String url,
                  java.lang.String lang)
           throws RDFException
add statements from a serializion in language lang to the model.

predefined values for lang are "RDF/XML", "N-TRIPLE" and "N3". null represents the default language, "RDF/XML".

See Model for a description of how to traverse a firewall.

Parameters:
url - a string representation of the url to read from
lang - the language of the serialization
Returns:
this model
Throws:
RDFException - generic RDF exception

read

public Model read(java.io.Reader reader,
                  java.lang.String base,
                  java.lang.String lang)
           throws RDFException
add RDF statements represented in language lang to the model.

predefined values for lang are defined in RDFReader

Parameters:
base - the base uri to be used when converting relative URI's to absolute URI's.
lang - the langauge of the serialization null selects the default
reader - the source of the input serialization
Returns:
this model
Throws:
RDFException - generic exception

write

public Model write(java.io.Writer writer)
            throws RDFException
Write the model as an XML document.

The language in which to write the model is specified by the lang argument. Predefined values are "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value is represented by null is "RDF/XML".

Parameters:
writer - a writer to which the XML will be written
Returns:
this model
Throws:
RDFException - Generic RDF Exception

write

public Model write(java.io.Writer writer,
                   java.lang.String lang)
            throws RDFException
write a serialized represention of a model in a specified language.

The language in which to write the model is specified by the lang argument. Predefined values are "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value is represented by null is "RDF/XML".

Parameters:
writer - the output writer
lang - the output langauge
Returns:
this model
Throws:
RDFException - generic exception

write

public Model write(java.io.Writer writer,
                   java.lang.String lang,
                   java.lang.String base)
            throws RDFException
write a serialized represention of a model in a specified language.

Predefine languages are defined in RDFWriterF

Parameters:
writer - the output writer
base - the base uri for relative URI calculations. null means use only absolute URI's.
lang - the language in which the RDF should be written
Returns:
this model
Throws:
RDFException - generic RDF exception

remove

public Model remove(Statement s)
             throws RDFException
Removes a statement.

The statement with the same subject, predicate and object as that supplied will be removed from the model.

Parameters:
s - The statement to be removed.
Returns:
this model
Throws:
RDFException - Generic RDF Exception

getProperty

public Statement getProperty(Resource s,
                             Property p)
                      throws RDFException
Return a statement with given subject and property.

If more than one statement witht the given subject and property exists in the model, it is undefined which will be returned.

Parameters:
s - The subject of the statement to be returned.
p - The property of the statement to be returned.
Returns:
A statement from the model with the given subject and property.
Throws:
RDFException - Generic RDF Exception

listSubjectsWithProperty

public ResIterator listSubjectsWithProperty(Property p)
                                     throws RDFException
List all subjects with a given property.
Parameters:
p - the property sought.
Returns:
an iterator over the subjects
Throws:
RDFException - Generic RDF Exception

listSubjectsWithProperty

public ResIterator listSubjectsWithProperty(Property p,
                                            RDFNode o)
                                     throws RDFException
List all subjects with a given property and property value
Parameters:
p - The predicate sought
o - The value sought
Returns:
an iterator over the subjects
Throws:
RDFException - Generic RDF Exception

listObjects

public NodeIterator listObjects()
                         throws RDFException
List all objects in a model.
Parameters:
p - The predicate sought
Returns:
an iterator over the objects
Throws:
RDFException - Generic RDF Exception

listObjectsOfProperty

public NodeIterator listObjectsOfProperty(Property p)
                                   throws RDFException
List all objects of a given property.
Parameters:
p - The predicate sought
Returns:
an iterator over the objects
Throws:
RDFException - Generic RDF Exception

listObjectsOfProperty

public NodeIterator listObjectsOfProperty(Resource s,
                                          Property p)
                                   throws RDFException
List the values of a property of a resource.
Parameters:
p - The predicate sought
Returns:
an iterator over the objects
Throws:
RDFException - Generic RDF Exception

contains

public boolean contains(Resource s,
                        Property p)
                 throws RDFException
Determine whether this model contains any statements with a given subject and property.
Parameters:
s - The subject sought.
p - The predicate sought.
Returns:
true if there exists within this model a statement with subject s and property p, false otherwise
Throws:
RDFException - Generic RDF Exception

contains

public boolean contains(Resource s,
                        Property p,
                        RDFNode o)
                 throws RDFException
Determine if a statement is present in this model.
Parameters:
s - The subject of the statment tested.
p - The predicate of the statement tested.
o - The object of the statement tested.
Returns:
true if the statement with subject s, property p and object o is in the model, false otherwise
Throws:
RDFException - Generic RDF Exception

contains

public boolean contains(Statement s)
                 throws RDFException
Determine if a statement is present in this model.
Parameters:
s - The statement tested.
Returns:
true if the statement s is in this model, false otherwise
Throws:
RDFException - Generic RDF Exception

containsAny

public boolean containsAny(StmtIterator iter)
                    throws RDFException
Determine if any of the statements returned by an iterator are contained in this model.
Parameters:
iter - an iterator of the statements to be tested
Returns:
true if any of the statements returns by iter are contained in this model and false otherwise.
Throws:
RDFException - Generic RDF Exception

containsAll

public boolean containsAll(StmtIterator iter)
                    throws RDFException
Determine if all of the statements returned by an iterator are contained in this model.
Parameters:
iter - an iterator of the statements to be tested
Returns:
true if any of the statements returns by iter are contained in this model and false otherwise.
Throws:
RDFException - Generic RDF Exception

containsAny

public boolean containsAny(Model model)
                    throws RDFException
Determine if any of the statements in a model are also contained in this model.
Parameters:
model - the model containing the statements to be tested
Returns:
true if any of the statements in model are also contained in this model and false otherwise.
Throws:
RDFException - Generic RDF Exception

containsAll

public boolean containsAll(Model model)
                    throws RDFException
Determine if all of the statements in a model are also contained in this model.
Parameters:
model - the model containing the statements to be tested
Returns:
true if all of the statements in model are also contained in this model and false otherwise.
Throws:
RDFException - Generic RDF Exception

isReified

public boolean isReified(Statement s)
                  throws RDFException
Determine if this statement is the subject of any statements in this model
Parameters:
s - The statement tested.
Returns:
true if the statement s is the subject of a statement in the model, false otherwise
Throws:
RDFException - Generic RDF Exception

listStatements

public StmtIterator listStatements(Selector s)
                            throws RDFException
List the statements matching a selector.

A statment is considered to match if the test method of s returns true when called on s.

Parameters:
s - A selector object.
Returns:
an iterator over the matching statements
Throws:
RDFException - Generic RDF exception.

query

public Model query(Selector s)
            throws RDFException
Create a new model containing the statements matching a query.

A statment is considered to match if the test method of s returns true when called on s.

Parameters:
s - A selector object.
Returns:
an iterator over the matching statements
Throws:
RDFException - Generic RDF exception.

union

public Model union(Model model)
            throws RDFException
Create a new model containing all the statements in this model together with all of those in another given model.
Parameters:
model - The other model whose statements are to be included.
Returns:
A new model containing all the statements that are in either model
Throws:
RDFException - Generic RDF Exception

intersection

public Model intersection(Model model)
                   throws RDFException
Create a new model containing all the statements which are in both this model and another. As models are sets of statements, a statement contained in both models will only appear once in the resulting model.
Parameters:
model - The other model.
Returns:
A new model containing all the statements that are in both models.
Throws:
RDFException - Generic RDF Exception

difference

public Model difference(Model model)
                 throws RDFException
Create a new model containing all the statements in this model which are not in another.
Parameters:
model - the other model whose statements are to be excluded.
Returns:
a new model containing all the statements in this model that are not in the given model.
Throws:
RDFException - Generic RDF Exception

equals

public boolean equals(java.lang.Object model)
Test whether one model is the equal to another.

Two models are considered equal when each statement in one can be matched with a statement in the other. Statements which are identical match.

Special treatment is given to anonymous nodes. A binding is a one to one mapping which maps each anonymous node in this model to an anonymous node in model. Two statements s1 and s2 match under a binding if if s1.subject is anonymous and s2.subject is anonymous and the binding maps s1.subject to s2.subject.

Two models are equal if there is a binding that allows all the statements in one model to match a a statement in the other.

Overrides:
equals in class java.lang.Object
Parameters:
model - the model to be compared
Returns:
true if the models are equal

begin

public Model begin()
            throws RDFException
Begin a new transation.

All changes made to a model within a transaction, will either be made, or none of them will be made.

Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

abort

public Model abort()
            throws RDFException
Abort the current transaction and abandon any changes in progress.
Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

commit

public Model commit()
             throws RDFException
Commit the current transaction.
Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

independent

public boolean independent()
Determine whether this model is independent.

For efficiency reasons, some implementations may create models which which are dependent on others, i.e. a change in one model may cause a change in another. If this is the case this method will return false, otherwise it will return true.

Returns:
true if this model is indepdent of others

supportsTransactions

public boolean supportsTransactions()
Determine whether this model supports transactions.
Returns:
true if this model supports transactions.

supportsSetOperations

public boolean supportsSetOperations()
Determine whether this model supports set operations.
Returns:
true if this model supports set operations.

close

public void close()
Close the Model and free up resources held.

Not all implementations of Model require this method to be called. But some do, so in general its best to call it when done with the object, rather than leave it to the finalizer.



Copyright © 2001 Hewlett-Packard. All Rights Reserved.