- All Superinterfaces:
Lock
,ModelCon
,ModelGraphInterface
,PrefixMapping
,RDFReaderF
,RDFWriterF
- All Known Implementing Classes:
InfModelImpl
,ModelCom
,MonitorModel
,OntModelImpl
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.
Models may create Resources [URI nodes and bnodes]. Creating a Resource does not make the Resource visible to the model; Resources are only "in" Models if Statements about them are added to the Model. Similarly, the only way to "remove" a Resource from a Model is to remove all the Statements that mention it.
When a Resource or Literal is created by a Model, the Model is free to re-use an existing Resource or Literal object with the correct values, or it may create a fresh one. [All Jena RDFNodes and Statements are immutable, so this is generally safe.]
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
.
The good practice is to close explicitly every Jena's ExtendedIterator
produced by the Model
right after query operation.
Depending on the implementation,
the iterator may throw a ConcurrentModificationException
if continued with it after modification operation.
This may happen even if the queried data does not relate directly to the modified data
(i.e. when triple search pattern does not match added or deleted triple).
A ExtendedIterator
should be operated on
(invoking materializing ExtendedIterator
operation) only once;
in general reusable are not allowed and may lead to an exception.
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 programmatically, e.g.
System.getProperties().put("proxySet","true"); System.getProperties().put("proxyHost","proxy.hostname"); System.getProperties().put("proxyPort",port_number);
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.jena.shared.PrefixMapping
PrefixMapping.Factory, PrefixMapping.IllegalPrefixException, PrefixMapping.JenaLockedException
-
Field Summary
Fields inherited from interface org.apache.jena.shared.PrefixMapping
Extended, Standard
-
Method Summary
Modifier and TypeMethodDescriptionabort()
Abort the current transaction and abandon any changes in progress.add all the statements in the List to this Model, going through the bulk update interface (which means turning them into triples in one form or another).Add all the statements in another model to this model.Add a statement to this model.Add all the statements to the Model, using through the bulk update interface.add
(StmtIterator iter) Add all the statements returned by an iterator to this model.begin()
Begin a new transaction.<T> T
calculateInTxn
(Supplier<T> action) Execute the supplieraction
within a transaction.Clear this prefix mapping of all mappingsvoid
close()
Close the Model and free up resources held.commit()
Commit the current transaction.boolean
Determine whether this model contains any statements with a given subject and property.boolean
Determine if an (S, P, O) pattern is present in this model, with null allowed to represent a wildcard match.boolean
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.boolean
determine if the RDFNode r appears in any statement of this model.Answer a new empty list.createList
(Iterator<? extends RDFNode> members) Answer a new list containing the resources from the given iterator, in order.createList
(RDFNode... members) Answer a new list containing the nodes from the given eleemnts, in order.createLiteral
(String v, String language) Create an untyped literal from a String value with a specified language.createProperty
(String nameSpace, String localName) Create a property with a given URI composed from a namespace part and a localname part by concatenating the strings.Create a new anonymous resource whose model is this model.createResource
(String uri) Create a new resource associated with this model.createResource
(AnonId id) Create a blank node resource with a specified identifier.createResource
(Statement statement) Create a resource that represents a statement.createStatement
(Resource s, Property p, RDFNode o) Create a Statement instance.createTypedLiteral
(Object value) Build a typed literal label from its value form using whatever datatype is currently registered as the the default representation for this java class.createTypedLiteral
(Object value, RDFDatatype dtype) Build a typed literal from its value form.createTypedLiteral
(String lex, RDFDatatype dtype) Build a typed literal from its lexical form.difference
(Model model) Create a new, independent, model containing all the statements in this model which are not in another.boolean
Test whether the given objectm
is a model that is equal to this model, which is true iff the underlying graphs are identical Java objects.void
executeInTxn
(Runnable action) Execute the runnableaction
within a transaction.getLock()
Get the model lock for this model.getProperty
(String nameSpace, String localName) Return a Property instance with the given URI in this model.getProperty
(Resource s, Property p) Answer a statement (s, p, ?getProperty
(Resource s, Property p, String lang) Answer a statement (s, p, ?Deprecated.Return a statement with given subject and property.getRequiredProperty
(Resource s, Property p, String lang) Return a statement with given subject and property.getResource
(String uri) Return a Resource instance with the given URI in this model.getResource
(AnonId id) Return a Resource instance with the given URI in this model.Deprecated.Use RIOT viaorg.apache.jena.riotRDFDataMgr
or callwrite(java.io.Writer)
.boolean
Determine whether this model is independent.intersection
(Model model) Create a new, independent, model containing all the statements which are in both this model and another.boolean
isClosed()
Answer true iff .close() has been called on this Model.boolean
isEmpty()
Answer true iff the model contains no explicit statements (ie it's size is zero, listStatements() would deliver the empty iterator).boolean
Compare this Model with another for equality ignoring the labels on bNodes.(You probably don't want this method; more likely you want the PrefixMapping methods that Model supports.)List all objects in a model.List all objects of a given property. .remove() is not implemented on this iterator.List the values of a property of a resource.Answer an iterator [with no duplicates] over all the resources in this model that have propertyp
.Answer an iterator [with no duplicates] over all the resources in this model that have propertyp
with valueo
.List all statements.listStatements
(Resource s, Property p, RDFNode o) Find all the statements matching a pattern.List all resources which are subjects of statements.An alias forlistResourcesWithProperty(Property)
, retained for backward compatibility.An alias forlistResourcesWithProperty
, retained for backward compatibility.Notify any listeners that the event e has occurred.read
(InputStream in, String base) Add statements from a document.read
(InputStream in, String base, String lang) Add RDF statements represented in languagelang
to the model.Using this method is often a mistake.Using this method is often a mistake.Add the RDF statements from a document.Add statements from a serializion in languagelang
to the model.Read into this model the RDF aturl
, usingbaseURI
as the base URI if it is non-null.register
(ModelChangedListener listener) Register a listener for model-changed events on this model.Remove all the statements in the list from this model, using the bulk update interface.Removes a statement.Remove all the statements from the Model, using the bulk update interface.Remove all the statements from this model.Remove all the statements matching (s, p, o) from this model.removeNsPrefix
(String prefix) Remove any existing maplet with the given prefix name and answer this mapping.setNsPrefix
(String prefix, String uri) Specify the prefix name for a URI prefix string.setNsPrefixes
(Map<String, String> map) Copies the prefix mapping from other into this.setNsPrefixes
(PrefixMapping other) Copies the prefixes from other into this.long
size()
size will return the number of statements in a concrete model, for a virtualized model such as one created by an inference engine, it will return an estimated lower bound for the number of statements in the model but it is possible for a subsequent listStatements on such a model to discover more statements than size() indicated.boolean
Determine whether this model supports set operations.boolean
Determine whether this model supports transactions.Create a new, independent, model containing all the statements in this model together with all of those in another given model.unregister
(ModelChangedListener listener) Unregister a listener from model-changed events on this model.Update this PrefixMapping with the bindings inmap
, only adding those (p, u) pairs for which neither p nor u appears in this mapping.write
(OutputStream out) Write a serialization of this model as an XML document.write
(OutputStream out, String lang) Write a serialized representation of this model in a specified language.write
(OutputStream out, String lang, String base) Write a serialized representation of a model in a specified language.Deprecated.Preferwrite(OutputStream, String)
and specify the language.Write a serialized representation of a model in a specified language.Write a serialized representation of a model in a specified language.Methods inherited from interface org.apache.jena.shared.Lock
enterCriticalSection, leaveCriticalSection
Methods inherited from interface org.apache.jena.rdf.model.ModelCon
add, add, add, add, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, contains, contains, containsLiteral, containsLiteral, containsLiteral, containsLiteral, containsLiteral, containsLiteral, containsLiteral, createAlt, createAlt, createBag, createBag, createLiteral, createLiteralStatement, createLiteralStatement, createLiteralStatement, createLiteralStatement, createLiteralStatement, createLiteralStatement, createLiteralStatement, createProperty, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, getAlt, getAlt, getBag, getBag, getList, getList, getProperty, getRDFNode, getSeq, getSeq, listLiteralStatements, listLiteralStatements, listLiteralStatements, listLiteralStatements, listLiteralStatements, listLiteralStatements, listResourcesWithProperty, listResourcesWithProperty, listResourcesWithProperty, listResourcesWithProperty, listResourcesWithProperty, listResourcesWithProperty, listStatements, listStatements, listSubjectsWithProperty, listSubjectsWithProperty, remove, remove, remove
Methods inherited from interface org.apache.jena.rdf.model.ModelGraphInterface
asRDFNode, asStatement, getGraph, wrapAsResource
Methods inherited from interface org.apache.jena.shared.PrefixMapping
expandPrefix, getNsPrefixMap, getNsPrefixURI, getNsURIPrefix, hasNoMappings, lock, numPrefixes, qnameFor, samePrefixMappingAs, shortForm
-
Method Details
-
size
long size()size will return the number of statements in a concrete model, for a virtualized model such as one created by an inference engine, it will return an estimated lower bound for the number of statements in the model but it is possible for a subsequent listStatements on such a model to discover more statements than size() indicated.- Returns:
- the number of statements in a concrete model or an estimated lower bound on the number of statements in an virtualized model
-
isEmpty
boolean isEmpty()Answer true iff the model contains no explicit statements (ie it's size is zero, listStatements() would deliver the empty iterator).- Returns:
- true iff the model contains no explicit statements.
-
listSubjects
ResIterator listSubjects()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. .remove() is not implemented on this iterator.
-
listNameSpaces
NsIterator listNameSpaces()(You probably don't want this method; more likely you want the PrefixMapping methods that Model supports.) List the namespaces used by predicates and types in the model. This method is really intended for use by the RDF/XML writer, which needs to know these namespaces to generate correct and vaguely pretty XML.The namespaces returned are those of (a) every URI used as a property in the model and (b) those of every URI that appears as the object of an rdf:type statement.
Note that the notion of "namespace" used here is not that of an XML prefix-namespace, but just of the minimal legal left part of a URI (see Util.splitNamespace for details). If you want the RDF/XML (or N3) namespaces, treat the Model as a PrefixMapping.
- Returns:
- an iterator over every predicate and type namespace
- See Also:
-
getResource
Return a Resource instance with the given URI in this model. This method behaves identically to
.createResource(String)
Subsequent operations on the returned object may modify this model.
- Parameters:
uri
- the URI of the resource- Returns:
- a resource instance
-
getResource
Return a Resource instance with the given URI in this model. This method behaves identically to
.createResource(AnonId)
Subsequent operations on the returned object may modify this model.
- Parameters:
id
- An anonymous bode Id.- Returns:
- a resource instance
-
getProperty
Return a Property instance with the given URI in this model. This method behaves identically tocreateProperty(String,String)
and exists as legacy: createProperty is now capable of, and allowed to, reuse existing objects.Subsequent operations on the returned property may modify this model.
- Parameters:
nameSpace
- the RDF namespace of the propertylocalName
- the localName of the property in its namespace- Returns:
- a property linked to this model
-
createResource
Resource createResource()Create a new anonymous resource whose model is this model. This bnode will have a new AnonId distinct from any allocated by any other call of this method.Subsequent operations on the returned resource may modify this model.
- Returns:
- a new anonymous resource linked to this model.
-
createResource
Create a blank node resource with a specified identifier. The resulting bnode will be equal to any other bnode with the same AnonId (even if they are in separate models - be warned). The intended use for this method is to allow bnode round-tripping between Jena models and other representations.This method may return an existing bnode with the correct AnonId and model, or it may construct a fresh one, as it sees fit.
Operations on the result may modify this model
- Parameters:
id
- the identifier to use for this blank node- Returns:
- a blank node with that identifier
-
createResource
Create a new resource associated with this model. If the uri string is null, this creates a bnode, as percreateResource()
. Otherwise it creates a URI node. A URI resource is .equals() to any other URI Resource with the same URI (even in a different model - be warned).This method may return an existing Resource with the correct URI and model, or it may construct a fresh one, as it sees fit.
Operations on the result Resource may change this model.
- Parameters:
uri
- the URI of the resource to be created- Returns:
- a new resource linked to this model.
-
createResource
Create a resource that represents a statement. This is in support of RDF-star.- Parameters:
statement
-- Returns:
- a new resource linked to this model.
-
createProperty
Create a property with a given URI composed from a namespace part and a localname part by concatenating the strings.This method may return an existing property with the correct URI and model, or it may construct a fresh one, as it sees fit.
Subsequent operations on the returned property may modify this model.
- Parameters:
nameSpace
- the nameSpace of the propertylocalName
- the name of the property within its namespace- Returns:
- a property instance
-
createLiteral
Create an untyped literal from a String value with a specified language.- Parameters:
v
- the lexical form of the literallanguage
- the language associated with the literal- Returns:
- a new literal representing the value v with the given language
-
createTypedLiteral
Build a typed literal from its lexical form. The lexical form will be parsed now and the value stored. If the form is not legal this will throw an exception.Note that in preview releases of Jena2 it was also possible to specify a language type. Changes to the RDF specification mean that this is no longer legal except for plain literals. To create a plain literal with a language tag use
createLiteral
.- Parameters:
lex
- the lexical form of the literaldtype
- the type of the literal, null for old style "plain" literals- Throws:
DatatypeFormatException
- if lex is not a legal form of dtype
-
createTypedLiteral
Build a typed literal from its value form.Note that in preview releases of Jena2 it was also possible to specify a language type. Changes to the RDF specification mean that this is no longer legal except for plain literals. To create a plain literal with a language tag use
createLiteral
.- Parameters:
value
- the value of the literaldtype
- the type of the literal, null for old style "plain" literals
-
createTypedLiteral
Build a typed literal label from its value form using whatever datatype is currently registered as the the default representation for this java class. No language tag is supplied.- Specified by:
createTypedLiteral
in interfaceModelCon
- Parameters:
value
- the literal value to encapsulate- Returns:
- a new literal representing the value v
-
createStatement
Create a Statement instance. (Creating a statement does not add it to the set of statements in the model; see Model::add). This method may return an existing Statement with the correct components and model, or it may construct a fresh one, as it sees fit.Subsequent operations on the statement or any of its parts may modify this model.
- Parameters:
s
- the subject of the statementp
- the predicate of the statemento
- the object of the statement- Returns:
- the new statement
-
createList
RDFList createList()Answer a new empty list. This is equivalent to a list consisting only ofrdf:nil
.- Returns:
- An RDF-encoded list of no elements
-
createList
Answer a new list containing the resources from the given iterator, in order.
- Parameters:
members
- An iterator, each value of which is expected to be an RDFNode- Returns:
- An RDF-encoded list of the elements of the iterator
-
createList
Answer a new list containing the nodes from the given eleemnts, in order. If the list of elements is empty, until the list is made the object or subject in the model, or has an element added, it will not appear in the model (e.g. when written out).
- Parameters:
members
- An array of RDF nodes that will be the members of the list- Returns:
- An RDF-encoded list
-
add
Add a statement to this model.- Parameters:
s
- The statement to be added.- Returns:
- This model.
-
add
Add all the statements to the Model, using through the bulk update interface.- Parameters:
statements
- the array of statements to add- Returns:
- this model, to allow cascading
-
remove
Remove all the statements from the Model, using the bulk update interface.- Parameters:
statements
- the array of statements to be added- Returns:
- this model, to allow cascading
-
add
add all the statements in the List to this Model, going through the bulk update interface (which means turning them into triples in one form or another).- Parameters:
statements
- a List of Statements- Returns:
- this model, to allow cascading
-
remove
Remove all the statements in the list from this model, using the bulk update interface.- Parameters:
statements
- a List of Statements to remove- Returns:
- this model, to allow cascading
-
add
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
-
add
Add all the statements in another model to this model.- Parameters:
m
- The model whose statements are to be added.- Returns:
- this model
-
read
Add the RDF statements from a document. Uses content negotiation to request appropriate mime types. If the content type is not found, it may guess from the URL.See
Model
for a description of how to traverse a firewall.See "Reading and Writing RDF in Apache Jena" for more information about determining the syntax.
- Parameters:
url
- of the document containing the RDF statements.- Returns:
- this model
-
read
Add statements from a document. This method assumes the concrete syntax is RDF/XML. Seeread(InputStream, String, String)
for explicitly setting the language.See "Reading and Writing RDF in Apache Jena" for more information about concrete syntaxes.
- Parameters:
in
- the input streambase
- the base uri to be used when converting relative URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done by prepending the base URI to the relative URI/fragment.) If there are no relative URIs in the source, this argument may safely benull
. If the base is the empty string, then relative URIs will be retained in the model. This is typically unwise and will usually generate errors when writing the model back out.- Returns:
- the current model
-
read
Add RDF statements represented in languagelang
to the model.
Predefined values forlang
are "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL").null
represents the default language, "RDF/XML". "RDF/XML-ABBREV" is a synonym for "RDF/XML".- Parameters:
base
- the base uri to be used when converting relative URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done by prepending the base URI to the relative URI/fragment.) If there are no relative URIs in the source, this argument may safely benull
. If the base is the empty string, then relative URIs will be retained in the model. This is typically unwise and will usually generate errors when writing the model back out.See "Reading and Writing RDF in Apache Jena" for more information about concrete syntaxes.
lang
- the language of the serializationnull
selects the defaultin
- the source of the input serialization- Returns:
- this model
-
read
Using this method is often a mistake. Add statements from an RDF/XML serialization. It is generally better to use an InputStream if possible, otherwise there is a danger of a mismatch between the character encoding of say the FileReader and the character encoding of the data in the file. It is better to explicitly set the serialization format. Seeread(InputStream, String, String)
for explicitily setting the serialization language.See "Reading and Writing RDF in Apache Jena" for more information about concrete syntaxes.
- Parameters:
reader
-base
- the base uri to be used when converting relative URI's to absolute URI's and to guess the RDF serialization syntax.- Returns:
- the current model
-
read
Add statements from a serializion in languagelang
to the model.
Predefined values forlang
are "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL") and "N3".null
represents the default language, "RDF/XML". "RDF/XML-ABBREV" is a synonym for "RDF/XML".
See
Model
for a description of how to traverse a firewall.See "Reading and Writing RDF in Apache Jena" for more information about concrete syntaxes.
- Parameters:
url
- a string representation of the url to read fromlang
- the language of the serialization- Returns:
- this model
-
read
Using this method is often a mistake. Add RDF statements represented in languagelang
to the model.
Predefined values forlang
are "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL") and "N3".null
represents the default language, "RDF/XML". "RDF/XML-ABBREV" is a synonym for "RDF/XML".
It is generally better to use an InputStream if possible.read(InputStream,String)
, otherwise there is a danger of a mismatch between the character encoding of say the FileReader and the character encoding of the data in the file.- Parameters:
base
- the base uri to be used when converting relative URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done by prepending the base URI to the relative URI/fragment.) If there are no relative URIs in the source, this argument may safely benull
. If the base is the empty string, then relative URIs will be retained in the model. This is typically unwise and will usually generate errors when writing the model back out.lang
- the language of the serializationnull
selects the defaultreader
- the source of the input serialization- Returns:
- this model
-
read
Read into this model the RDF aturl
, usingbaseURI
as the base URI if it is non-null. The RDF is assumed to be RDF/XML unlesslang
is non-null, in which case it names the language to be used. Answer this model. -
write
Deprecated.Preferwrite(OutputStream, String)
and specify the language.Write the model as an XML document. It is often better to use an OutputStream rather than a Writer, since this will avoid character encoding errors.
- Parameters:
writer
- A writer to which the XML will be written- Returns:
- this model
-
write
Write a serialized representation of a model in a specified language. It is often better to use an OutputStream rather than a Writer, since this will avoid character encoding errors.
The language in which to write the model is specified by the
lang
argument. Predefined values are "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE", "TURTLE", (and "TTL") and "N3". The default value, represented bynull
is "RDF/XML".- Parameters:
writer
- The output writerlang
- The output language- Returns:
- this model
-
write
Write a serialized representation of a model in a specified language. It is often better to use an OutputStream rather than a Writer, since this will avoid character encoding errors.
The language in which to write the model is specified by the
lang
argument. Predefined values are "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE", "TURTLE", (and "TTL") and "N3". The default value, represented bynull
, is "RDF/XML".- Parameters:
writer
- The output writerbase
- 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
-
write
Write a serialization of this 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 bynull
is "RDF/XML".- Parameters:
out
- The output stream to which the XML will be written- Returns:
- This model
-
write
Write a serialized representation of this 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", "TURTLE", (and "TTL") and "N3". The default value, represented bynull
, is "RDF/XML".- Parameters:
out
- The output stream to which the RDF is writtenlang
- The output language- Returns:
- This model
-
write
Write a serialized representation 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", "TURTLE", (and "TTL") and "N3". The default value, represented bynull
, is "RDF/XML".- Parameters:
out
- The output stream to which the RDF is writtenbase
- The base uri to use when writing relative URI's.null
means use only absolute URI's. This is used for relative URIs that would be resolved against the document retrieval URL. For some values oflang
, this value may be included in the output.lang
- The language in which the RDF should be written- Returns:
- This model
-
getReader
Deprecated.Use RIOT viaorg.apache.jena.riotRDFDataMgr
or callread(java.lang.String)
.Description copied from interface:RDFReaderF
return an RDFReader instance for the specified serialization language.- Specified by:
getReader
in interfaceRDFReaderF
- Parameters:
lang
- the serialization language -null
selects the default (RDF/XML).- Returns:
- the RDFWriter instance
-
getWriter
Deprecated.Use RIOT viaorg.apache.jena.riotRDFDataMgr
or callwrite(java.io.Writer)
.Description copied from interface:RDFWriterF
an RDFWriter instance for the specified serialization language.- Specified by:
getWriter
in interfaceRDFWriterF
- Parameters:
lang
- the serialization language -null
selects the default (RDF/XML)- Returns:
- the RDFWriter instance
-
remove
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
-
getRequiredProperty
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. If none exist, an exception is thrown.
- 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:
PropertyNotFoundException
-
getRequiredProperty
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. If none exist, an exception is thrown.
- Parameters:
s
- The subject of the statement to be returned.p
- The property of the statement to be returned.lang
- The language- Returns:
- A statement from the model with the given subject and property.
- Throws:
PropertyNotFoundException
-
getProperty
Answer a statement (s, p, ?O) from this model. If none exist, return null; if several exist, pick one arbitrarily.- Parameters:
s
- the subject of the statement to returnp
- the predicate of the statement to return- Returns:
- some statement (s, p, ?O) or null if none can be found
-
getProperty
Answer a statement (s, p, ?O) from this model. If none exist, return null; if several exist, pick one arbitrarily.- Parameters:
s
- the subject of the statement to returnp
- the predicate of the statement to returnlang
- language of the object- Returns:
- some statement (s, p, ?O@lang) or null if none can be found
-
listSubjectsWithProperty
An alias forlistResourcesWithProperty(Property)
, retained for backward compatibility. It may be deprecated in later releases. -
listResourcesWithProperty
Answer an iterator [with no duplicates] over all the resources in this model that have propertyp
.remove()
is not implemented on this iterator. -
listSubjectsWithProperty
An alias forlistResourcesWithProperty
, retained for backward compatibility. It may be deprecated in later releases. -
listResourcesWithProperty
Answer an iterator [with no duplicates] over all the resources in this model that have propertyp
with valueo
.remove()
is not implemented on this iterator. -
listObjects
NodeIterator listObjects()List all objects in a model.- Returns:
- an iterator over the objects. .remove() is not implemented on this iterator.
-
listObjectsOfProperty
List all objects of a given property. .remove() is not implemented on this iterator.- Parameters:
p
- The predicate sought- Returns:
- an iterator over the objects
-
listObjectsOfProperty
List the values of a property of a resource.- Parameters:
p
- The predicate sought- Returns:
- an iterator over the objects. .remove() is not implemented on this iterator.
-
contains
Determine whether this model contains any statements with a given subject and property.- Parameters:
s
- The subject sought (null for any).p
- The predicate sought (null for any).- Returns:
- true if there exists within this model a statement with subject s and property p, false otherwise
-
containsResource
determine if the RDFNode r appears in any statement of this model. (containsRDFNode is a horrible name, and in any case, even literals will be resources one day)- Parameters:
r
- the RDFNode to be searched for- Returns:
- true iff r appears as some subject, predicate, or object
-
contains
Determine if an (S, P, O) pattern is present in this model, with null allowed to represent a wildcard match.- Parameters:
s
- The subject of the statement tested (null as wildcard).p
- The predicate of the statement tested (null as wildcard).o
- The object of the statement tested (null as wildcard).- Returns:
- true if the statement with subject s, property p and object o is in the model, false otherwise
-
contains
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
-
containsAny
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.
-
containsAll
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.
-
containsAny
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.
-
containsAll
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.
-
listStatements
StmtIterator listStatements()List all statements.Subsequent operations on those statements may modify this model.
- Returns:
- an iterator over all statements in the model.
-
listStatements
Find all the statements matching a pattern.Return an iterator over all the statements in a model that match a pattern. The statements selected are those whose subject matches the
subject
argument, whose predicate matches thepredicate
argument and whose object matches theobject
argument. If an argument isnull
it matches anything.- Parameters:
s
- The subject soughtp
- The predicate soughto
- The value sought- Returns:
- an iterator over the subjects
-
union
Create a new, independent, model containing all the statements in this model together with all of those in another given model. By independent we mean that changes to the result model do not affect the operand models, and vice versa.The new model need not be of the same type as either this model or the argument model: typically it will be a memory-based model, even if this model is a database 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
-
intersection
Create a new, independent, 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. The new model need not be of the same type as either this model or the argument model: typically it will be a memory-based model.- Parameters:
model
- The other model.- Returns:
- A new model containing all the statements that are in both models.
-
difference
Create a new, independent, model containing all the statements in this model which are not in another. The new model need not be of the same type as either this model or the argument model: typically it will be a memory-based model.- 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.
-
equals
Test whether the given objectm
is a model that is equal to this model, which is true iff the underlying graphs are identical Java objects. This is not the same test as comparing whether two models have the same structure (i.e. contain the same set of statements). To test for strucutural equivalence, seeisIsomorphicWith(org.apache.jena.rdf.model.Model)
. -
begin
Model begin()Begin a new transaction.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.
-
abort
Model abort()Abort the current transaction and abandon any changes in progress.- Returns:
- this model to enable cascading.
-
commit
Model commit()Commit the current transaction.- Returns:
- this model to enable cascading.
-
executeInTxn
Execute the runnableaction
within a transaction. If it completes normally, commit the transaction, otherwise abort the transaction. -
calculateInTxn
Execute the supplieraction
within a transaction. If it completes normally, commit the transaction and return the result, otherwise abort the transaction. -
independent
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
boolean supportsTransactions()Determine whether this model supports transactions.- Returns:
- true if this model supports transactions.
-
supportsSetOperations
boolean supportsSetOperations()Determine whether this model supports set operations.- Returns:
- true if this model supports set operations.
-
isIsomorphicWith
Compare this Model with another for equality ignoring the labels on bNodes. See RDF Concepts.Two models are isomorphic 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 inmodel
. Two statements s1 and s2 match under a binding if s1.subject is anonymous and s2.subject is anonymous and the binding maps s1.subject to s2.subject.Two models are isomorphic if there is a binding that allows all the statements in one model to match a a statement in the other.
- Parameters:
g
- Compare against this.- Returns:
- boolean True if the two RDF graphs are isomorphic.
-
close
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.
-
getLock
Lock getLock()Get the model lock for this model.See also the operations
Lock.enterCriticalSection(boolean)
andLock.leaveCriticalSection()
.It is better to use transactions.
-
register
Register a listener for model-changed events on this model. The methods on the listener will be called when API add/remove calls on the model succeed [in whole or in part].The same listener may be registered many times; if so, it's methods will be called as many times as it's registered for each event.
- Returns:
- this model, for cascading
- See Also:
-
unregister
Unregister a listener from model-changed events on this model. The listener is dtached from the model. The model is returned to permit cascading. If the listener is not attached to the model, then nothing happens.- Returns:
- this model, for cascading
- See Also:
-
notifyEvent
Notify any listeners that the event e has occurred.- Parameters:
e
- the event that has occurred
-
removeAll
Model removeAll()Remove all the statements from this model. -
removeAll
Remove all the statements matching (s, p, o) from this model. -
isClosed
boolean isClosed()Answer true iff .close() has been called on this Model. -
setNsPrefix
Description copied from interface:PrefixMapping
Specify the prefix name for a URI prefix string. Any existing use of that prefix name is overwritten. The result is this same prefixMapping. (The earlier restriction that adding second prefix for the same URI caused the earlier binding to be deleted has been withdrawn.)A prefix name must be a valid NCName, or the empty string. The empty string is reserved to mean "the default namespace".
Need not check the RFC2396 validity of the URI. Bad URIs are either silently ignored or behave as if they were good. The earlier restriction that the URI should end with a non-NCName character has been removed.
Note, in particular, that the prefix mapping can only be used if it includes the URI up to any '#' character because '#' is not legal in the local part of an NCName.
- Specified by:
setNsPrefix
in interfacePrefixMapping
- Parameters:
prefix
- the string to be used for the prefix.uri
- the URI prefix to be named- Returns:
- this PrefixMapping
-
removeNsPrefix
Description copied from interface:PrefixMapping
Remove any existing maplet with the given prefix name and answer this mapping. If the prefix is the empty string, then this removes the default namespace. If the prefix is not a legal prefix string, or is not present in the mapping, nothing happens.The reverse URI-to-prefix mapping is updated, but if there are multiple prefixes for the removed URI it is unspecified which of them will be chosen.
- Specified by:
removeNsPrefix
in interfacePrefixMapping
- Parameters:
prefix
- the prefix string to remove- Returns:
- this PrefixMapping
-
clearNsPrefixMap
Model clearNsPrefixMap()Description copied from interface:PrefixMapping
Clear this prefix mapping of all mappings- Specified by:
clearNsPrefixMap
in interfacePrefixMapping
-
setNsPrefixes
Description copied from interface:PrefixMapping
Copies the prefix mapping from other into this. Illegal prefix mappings are detected. Existing binds of the same prefix are lost. The result is this same prefixMapping.- Specified by:
setNsPrefixes
in interfacePrefixMapping
- Parameters:
map
- the Map whose maplets are to be added- Returns:
- this PrefixMapping
-
org.apache.jena.riotRDFDataMgr
or callread(java.lang.String)
.