public abstract class AbstractModel extends AbstractModelRemovePatterns implements Model
Modifier and Type | Field and Description |
---|---|
protected Object |
model
The underlying implementation.
|
Constructor and Description |
---|
AbstractModel() |
Modifier and Type | Method and Description |
---|---|
void |
addAll(Iterator<? extends Statement> other)
Add all statements contained in 'other' to this model = 'union'
|
void |
addModel(Model model)
subclasses should overwrite this for performance reasons
|
BlankNode |
addReificationOf(Statement statement)
A convenience function for addReficationOf( createBlankNode(), statement
);
|
Resource |
addReificationOf(Statement statement,
Resource resource)
Reifies the statement, whether the statement was present in the model or
not.
|
void |
addStatement(Resource subject,
URI predicate,
String literal)
adds a (subject, property, literal)-statement to the model.
|
void |
addStatement(Resource subject,
URI predicate,
String literal,
String languageTag)
adds a (subject, property, liteal, language-tag)-statement to the model.
|
void |
addStatement(Resource subject,
URI predicate,
String literal,
URI datatypeURI)
adds a (subject, property, literal ,datatype)-statement to the model.
|
void |
addStatement(Statement statement)
adds a statement to this model
|
void |
addStatement(String subjectURIString,
URI predicate,
String literal)
adds a (subject, property, literal)-statement to the model.
|
void |
addStatement(String subjectURIString,
URI predicate,
String literal,
String languageTag)
adds a (subject, property, liteal, language-tag)-statement to the model.
|
void |
addStatement(String subjectURIString,
URI predicate,
String literal,
URI datatypeURI)
adds a (subject, property, literal, data-type)-statement to the model.
|
protected void |
assertModel()
This method checks if the model is properly initialized and i.e.
|
void |
close()
Close connection to defined, underlying implementation
|
void |
commit()
Deprecated.
|
boolean |
contains(ResourceOrVariable subject,
UriOrVariable predicate,
NodeOrVariable object)
Convenience method.
|
boolean |
contains(ResourceOrVariable subject,
UriOrVariable predicate,
String plainLiteral)
Convenience method.
|
boolean |
contains(Statement s)
Convenience method.
|
long |
countStatements(TriplePattern pattern)
Very inefficient.
|
DatatypeLiteral |
createDatatypeLiteral(String literal,
URI datatypeURI) |
LanguageTagLiteral |
createLanguageTagLiteral(String literal,
String languageTag) |
PlainLiteral |
createPlainLiteral(String literal)
Create a new plain literal
|
Statement |
createStatement(Resource subject,
URI predicate,
Node object)
Create a new statement - but DOES NOT add it to the model
|
TriplePattern |
createTriplePattern(ResourceOrVariable subject,
UriOrVariable predicate,
NodeOrVariable object) |
URI |
createURI(String uriString)
The model must create URIs it would accept itself.
|
void |
deleteReification(Resource reificationResource)
Delete reifications made by this resource.
|
ClosableIterator<Statement> |
findStatements(TriplePattern triplepattern)
Convenience method.
|
Collection<Resource> |
getAllReificationsOf(Statement statement) |
Diff |
getDiff(Iterator<? extends Statement> other)
Computes a Diff by using HashSets.
|
Object |
getProperty(URI propertyURI)
Note: This is a property of the model, not an RDF property
|
Object |
getUnderlyingModelImplementation() |
boolean |
hasReifications(Statement statement) |
boolean |
isEmpty()
sublcasses should override this method for performance
|
boolean |
isOpen() |
URI |
newRandomUniqueURI()
Implementations are free to choose if their semantics are unique within
the this model, the ModelSet, or unique in the universe
|
Model |
open()
Open connection to defined, unterlying implementation.
|
ClosableIterable<Statement> |
queryConstruct(String query,
String querylanguage)
Throws an exception if the syntax is not SPARQL
|
QueryResultTable |
querySelect(String query,
String querylanguage)
Throws an exception if the syntax is not SPARQL
|
void |
readFrom(InputStream in,
Syntax syntax)
Throws an exception if the syntax is not RDF/XML.
|
void |
readFrom(InputStream in,
Syntax syntax,
String baseURI)
Note: Subclasses are encouraged to overwrite this.
Throws an exception if the syntax is not RDF/XML.
|
void |
readFrom(Reader reader,
Syntax syntax,
String baseURI)
Note: Subclasses are encouraged to overwrite this.
Throws an exception if the syntax is not RDF/XML.
|
void |
removeAll()
Removes all statements from this model.
|
void |
removeAll(Iterator<? extends Statement> statements)
Removes all statements contained in 'other' from this model =
'difference'
|
void |
removeStatement(Resource subject,
URI predicate,
String literal) |
void |
removeStatement(Resource subject,
URI predicate,
String literal,
String languageTag)
remove a (subject, property ,literal, language tag)-statement from the
model
|
void |
removeStatement(Resource subject,
URI predicate,
String literal,
URI datatypeURI)
remove a (subject, property ,literal, datatype)-statement from the model
datatype often is an uri for a xml schema datatype (xsd)
|
void |
removeStatement(Statement statement)
remove a rdf2go-statement from the model
|
void |
removeStatement(String subjectURIString,
URI predicate,
String literal) |
void |
removeStatement(String subjectURIString,
URI predicate,
String literal,
String languageTag)
remove a (subject, property ,literal, language tag)-statement from the
model
|
void |
removeStatement(String subjectURIString,
URI predicate,
String literal,
URI datatypeURI)
remove a (subject, property ,literal, datatype)-statement from the model
datatype often is an uri for a xml schema datatype (xsd)
|
void |
removeStatements(ResourceOrVariable subject,
UriOrVariable predicate,
NodeOrVariable object)
remove a (subject, property ,object)-statement from the model
|
void |
removeStatements(TriplePattern triplePattern)
remove all matching triple patterms from the model
|
String |
serialize(Syntax syntax)
Convenience method.
|
void |
setAutocommit(boolean autocommit)
Deprecated.
|
void |
setProperty(URI propertyURI,
Object value)
Add an arbitrary property, this will not be persisted and is only
available at runtime.
|
long |
size()
This is a really slow implementation, please override.
|
boolean |
sparqlAsk(String query)
SPARQL ask queries
|
void |
update(DiffReader diff)
Implementations with support for transactions should use them instead of
this implementation.
|
void |
writeTo(OutputStream out,
Syntax syntax)
Throws an exception if the syntax is not known
|
addStatement, removeStatement
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dump, getContextURI, isIsomorphicWith
createBlankNode, createBlankNode, isValidURI
removeStatement
iterator
forEach, spliterator
addStatement
sparqlConstruct, sparqlDescribe, sparqlSelect
findStatements
readFrom, readFrom, readFrom, writeTo, writeTo, writeTo
getNamespace, getNamespaces, removeNamespace, setNamespace
protected Object model
public void addModel(Model model)
public void addAll(Iterator<? extends Statement> other) throws ModelRuntimeException
ModelWriter
addAll
in interface ModelWriter
addAll
in class AbstractModelWriter
other
- another RDF2GO modelModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(Resource subject, URI predicate, String literal) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subject
- of the statementpredicate
- of the statementliteral
- of the statement. A PlainLiteral
will be created.ModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(Resource subject, URI predicate, String literal, String languageTag) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subject
- URI or Object (= blankNode)predicate
- of the statementliteral
- main part of literal value of the statementlanguageTag
- RDF language tagModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(Resource subject, URI predicate, String literal, URI datatypeURI) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subject
- of the statementpredicate
- of the statementliteral
- main part of the literal of the statementdatatypeURI
- for the datatype part of the literalModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(Statement statement) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
statement
- the statement to addModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(String subjectURIString, URI predicate, String literal) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subjectURIString
- interpreted as URI of the statementpredicate
- of the statementliteral
- for the PlainLiteral
ModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(String subjectURIString, URI predicate, String literal, String languageTag) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subjectURIString
- interpreted as a URIpredicate
- of the statementliteral
- main part of the LanguageTagLiteral
languageTag
- RDF language tag of the LanguageTagLiteral
ModelRuntimeException
- if there is either an error with the
underlying model or an IOException
public void addStatement(String subjectURIString, URI predicate, String literal, URI datatypeURI) throws ModelRuntimeException
ModelWriter
addStatement
in interface ModelWriter
addStatement
in class AbstractModelWriter
subjectURIString
- interpreted as URI of the statementpredicate
- of the statementliteral
- for the DatatypeLiteral
datatypeURI
- for the DatatypeLiteral
ModelRuntimeException
- if there is either an error with the
underlying model or an IOException
protected void assertModel()
public void close()
@Deprecated public void commit()
commit
in interface Commitable
public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException
contains
in interface FindableModel
subject
- defined or a Variable
, e.g. Variable.ANY
predicate
- defined or a Variable
, e.g. Variable.ANY
object
- defined or a Variable
, e.g. Variable.ANY
ModelRuntimeException
- most often caused by underlying
IOException
, if anypublic boolean contains(ResourceOrVariable subject, UriOrVariable predicate, String plainLiteral) throws ModelRuntimeException
contains
in interface FindableModel
subject
- defined or a Variable
, e.g. Variable.ANY
predicate
- defined or a Variable
, e.g. Variable.ANY
plainLiteral
- a string interpreted as adefined PlainLiteral
ModelRuntimeException
- most often caused by underlying
IOException
, if anypublic boolean contains(Statement s) throws ModelRuntimeException
contains
in interface FindableModel
s
- a StatementModelRuntimeException
- most often caused by underlying
IOException
, if anypublic long countStatements(TriplePattern pattern) throws ModelRuntimeException
countStatements
in interface FindableModel
ModelRuntimeException
public DatatypeLiteral createDatatypeLiteral(String literal, URI datatypeURI) throws ModelRuntimeException
createDatatypeLiteral
in interface ModelValueFactory
ModelRuntimeException
- e.g. if the datatype URI causes problemspublic LanguageTagLiteral createLanguageTagLiteral(String literal, String languageTag) throws ModelRuntimeException
createLanguageTagLiteral
in interface ModelValueFactory
ModelRuntimeException
- e.g. if the language tag is malformedpublic PlainLiteral createPlainLiteral(String literal) throws ModelRuntimeException
ModelValueFactory
createPlainLiteral
in interface ModelValueFactory
ModelRuntimeException
public Statement createStatement(Resource subject, URI predicate, Node object)
ModelValueFactory
createStatement
in interface ModelValueFactory
public TriplePattern createTriplePattern(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object)
createTriplePattern
in interface FindableModel
subject
- defined or a Variable
, e.g. Variable.ANY
predicate
- defined or a Variable
, e.g. Variable.ANY
object
- defined or a Variable
, e.g. Variable.ANY
public URI createURI(String uriString) throws ModelRuntimeException
ModelValueFactory
createURI
in interface ModelValueFactory
ModelRuntimeException
public ClosableIterator<Statement> findStatements(TriplePattern triplepattern) throws ModelRuntimeException
findStatements
in interface FindableModel
triplepattern
- to be matchedModelRuntimeException
- most often caused by underlying
IOException
, if anypublic Diff getDiff(Iterator<? extends Statement> other) throws ModelRuntimeException
getDiff
in interface ModelAddRemove
ModelRuntimeException
public Object getProperty(URI propertyURI)
getProperty
in interface Model
propertyURI
- used as a property name to get the model propertypublic Object getUnderlyingModelImplementation()
getUnderlyingModelImplementation
in interface Model
public boolean isEmpty()
public boolean isOpen()
public URI newRandomUniqueURI()
ModelValueFactory
newRandomUniqueURI
in interface ModelValueFactory
public Model open()
public ClosableIterable<Statement> queryConstruct(String query, String querylanguage) throws QueryLanguageNotSupportedException, ModelRuntimeException
queryConstruct
in interface Sparqlable
QueryLanguageNotSupportedException
- if the adapter can't
understand the given query languageModelRuntimeException
- if the execution throws an exceptionMalformedQueryException
- if the query is not a valid construct
query in the given query languagepublic QueryResultTable querySelect(String query, String querylanguage) throws QueryLanguageNotSupportedException, ModelRuntimeException
querySelect
in interface Sparqlable
QueryLanguageNotSupportedException
- if the given query langauge is
not supportedModelRuntimeException
- if the execution throws an exceptionMalformedQueryException
- if the query is not a valid query in the
given query languagepublic void readFrom(InputStream in, Syntax syntax) throws IOException, ModelRuntimeException
readFrom
in interface ModelIO
syntax
- syntax to useIOException
- on IOErrorsModelRuntimeException
- on RDF serialization errors or model errorspublic void readFrom(InputStream in, Syntax syntax, String baseURI) throws IOException, ModelRuntimeException
readFrom
in interface ModelIO
IOException
ModelRuntimeException
public void readFrom(Reader reader, Syntax syntax, String baseURI) throws ModelRuntimeException, IOException
readFrom
in interface ModelIO
IOException
- from readerModelRuntimeException
- from modelpublic void removeAll() throws ModelRuntimeException
ModelAddRemove
removeAll
in interface ModelAddRemove
removeAll
in class AbstractModelAddRemove
ModelRuntimeException
public void removeAll(Iterator<? extends Statement> statements)
ModelAddRemove
removeAll
in interface ModelAddRemove
removeAll
in class AbstractModelAddRemove
public void removeStatement(Resource subject, URI predicate, String literal) throws ModelRuntimeException
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(Resource subject, URI predicate, String literal, String languageTag) throws ModelRuntimeException
ModelAddRemove
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(Resource subject, URI predicate, String literal, URI datatypeURI) throws ModelRuntimeException
ModelAddRemove
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(Statement statement) throws ModelRuntimeException
ModelAddRemove
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(String subjectURIString, URI predicate, String literal) throws ModelRuntimeException
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(String subjectURIString, URI predicate, String literal, String languageTag) throws ModelRuntimeException
ModelAddRemove
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatement(String subjectURIString, URI predicate, String literal, URI datatypeURI) throws ModelRuntimeException
ModelAddRemove
removeStatement
in interface ModelAddRemove
removeStatement
in class AbstractModelAddRemove
ModelRuntimeException
public void removeStatements(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException
ModelRemovePatterns
removeStatements
in interface ModelRemovePatterns
removeStatements
in class AbstractModelRemovePatterns
subject
- URI or Object (= blankNode)object
- URI or String (=plainLiteral) or BlankNode (=blankNode) or
TypedLiteral or LanguageTagLiteralModelRuntimeException
public void removeStatements(TriplePattern triplePattern) throws ModelRuntimeException
ModelRemovePatterns
removeStatements
in interface ModelRemovePatterns
removeStatements
in class AbstractModelRemovePatterns
ModelRuntimeException
public String serialize(Syntax syntax) throws SyntaxNotSupportedException
serialize
in interface ModelIO
SyntaxNotSupportedException
- if the syntax is not supported@Deprecated public void setAutocommit(boolean autocommit)
setAutocommit
in interface Commitable
autocommit
- If true, all changes are immediately written to the
underlying persistence layer, if any is used.public void setProperty(URI propertyURI, Object value)
setProperty
in interface Model
propertyURI
- used as a parameter name for storing a model propertyvalue
- any java object. Only stored in memory, not in RDF.public long size() throws ModelRuntimeException
size
in interface Model
ModelRuntimeException
public boolean sparqlAsk(String query) throws ModelRuntimeException, MalformedQueryException
Sparqlable
sparqlAsk
in interface Sparqlable
query
- a SPARQL AKS queryModelRuntimeException
- if the execution throws an exceptionMalformedQueryException
- if the query is not a valid SPARQL ASK
querypublic void update(DiffReader diff) throws ModelRuntimeException
update
in interface ModelAddRemove
update
in class AbstractModelAddRemove
ModelRuntimeException
public void writeTo(OutputStream out, Syntax syntax) throws IOException, ModelRuntimeException
writeTo
in interface ModelIO
out
- the output to write tosyntax
- syntax to useIOException
- on IOErrorsModelRuntimeException
- on RDF serialization errors or model errorspublic BlankNode addReificationOf(Statement statement)
ReificationSupport
addReificationOf
in interface ReificationSupport
public Resource addReificationOf(Statement statement, Resource resource)
ReificationSupport
(resource) rdf:type rdf:Statement .
(resource) rdf:subject (statement.getSubject()) .
(resource) rdf:predicate (statement.getPredicate()) .
(resource) rdf:object (statement.getObject()) .
addReificationOf
in interface ReificationSupport
statement
- which will be reifiedresource
- used to represent the reified statementpublic boolean hasReifications(Statement statement)
hasReifications
in interface ReificationSupport
?reificationResource rdf:type rdf:Statement .
?reificationResource rdf:subject ?s .
?reificationResource rdf:predicate ?p .
?reificationResource rdf:object ?o .
public Collection<Resource> getAllReificationsOf(Statement statement)
getAllReificationsOf
in interface ReificationSupport
public void deleteReification(Resource reificationResource)
ReificationSupport
(reificationResource) rdf:type rdf:Statement .
(reificationResource) rdf:subject * .
(reificationResource) rdf:predicate * .
(reificationResource) rdf:object * .
Note that one resource might have been used in several
reifications. Although semantic nonsense, this can happen. This method
cleans up also these cases.
Note that this method deletes the reification from all contexts.deleteReification
in interface ReificationSupport
Copyright © 2005–2018 IT-Consulting Dr. Max Völkel | Project started at FZI Forschungszentrum Informatik, www.fzi.de. All rights reserved.