Interface IOntologyBackend
- All Superinterfaces:
IServiceProvider
- All Known Implementing Classes:
OpenRobotsOntology
This interface describes the abstract behaviour of an ontology backend. It
presents the list of operation the "knowledge store" should provide to be
used with the ontology server.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(com.hp.hpl.jena.rdf.model.Statement statement, MemoryProfile memProfile, boolean safe) Deprecated.boolean
add
(Set<com.hp.hpl.jena.rdf.model.Statement> statements, MemoryProfile memProfile, boolean safe) Adds a set of new statements (assertion) to the ontology.boolean
check
(com.hp.hpl.jena.rdf.model.Statement statement) Checks if a statement is asserted or can be inferred from the ontology.boolean
check
(PartialStatement statement) Checks if a pattern represented as a partial statement matches at least one asserted of inferred statement.
For instance: A pattern like[?object rdf:type Bottle]
would match all instances of the classBottle
.[anAgent sees ?something]
would match all objects seen by instance "anAgent
".boolean
Performs a consistency validation against the ontology.boolean
checkConsistency
(Set<com.hp.hpl.jena.rdf.model.Statement> statements) Checks a set of statements (or partial statements) are not inconsistent with the current model.void
clear
(PartialStatement partialStmt) Remove all statements matching the partial statement.void
clearEvent
(IWatcher watcher) Removes one specific event watcher.void
Removes all registered event watchers for this model.void
close()
Closes the modelcreatePartialStatement
(String statement) This static method acts as a PartialStatement factory.com.hp.hpl.jena.ontology.OntProperty
createProperty
(String lex_property) Helper to create ainvalid reference
property
This is a shortcut forOpenRobotOntology.getModel().createProperty(Namespaces.format(lex_property))
com.hp.hpl.jena.ontology.OntResource
createResource
(String lex_resource) Helper to create ainvalid reference
resource
This is a shortcut forOpenRobotOntology.getModel().createResource(Namespaces.format(lex_resource))
.com.hp.hpl.jena.rdf.model.Statement
createStatement
(String statement) This static method acts as a Statement factory.Set
<com.hp.hpl.jena.rdf.model.RDFNode> Tries to identify a resource given a set of partially defined statements (plus optional restrictions) about this resource.Set
<com.hp.hpl.jena.ontology.OntClass> getClassesOf
(com.hp.hpl.jena.ontology.OntResource individual, boolean onlyDirect) Set
<com.hp.hpl.jena.ontology.OntResource> getInstancesOf
(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) com.hp.hpl.jena.ontology.OntModel
getModel()
Returns the underlying Jena ontology model.com.hp.hpl.jena.ontology.OntResource
getResource
(String lex_resource) Try to retrieve a resource from the ontology, based on its lexical form.Set
<com.hp.hpl.jena.ontology.OntClass> getSubclassesOf
(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) com.hp.hpl.jena.rdf.model.Model
getSubmodel
(com.hp.hpl.jena.rdf.model.Resource node) Returns the set of inferred and asserted statement involving a resource as a Jena Model..Set
<com.hp.hpl.jena.ontology.OntClass> getSuperclassesOf
(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) Return the list of event types implemented (hence usable) by this backend.Returns the set of all [id, type, label] (with type one of INSTANCE, CLASS, OBJECT_PROPERTY, DATATYPE_PROPERTY, UNDEFINED) of concepts whose labels or id match the given parameter.lookup
(String id, ResourceType type) Returns the set of all id of concepts whose labels or ids match the given parameter and of the given type.Set
<com.hp.hpl.jena.rdf.model.RDFNode> Performs a SPARQL query on the OpenRobots ontology.
For instance:void
registerEvent
(IWatcher watcher) Allows to register several events providers (typically, one by underlying middleware) which in turn provide access to watchers.void
remove
(com.hp.hpl.jena.rdf.model.Statement stmt) Deprecated.void
Removes a set of statements from the ontology.void
Saves the in-memory ontology model to a RDF/XML file.long
size()
Returns the number of statements in the model.void
step()
'Step' the model.void
Update the value of a property.
-
Method Details
-
createProperty
Helper to create ainvalid reference
property
This is a shortcut forOpenRobotOntology.getModel().createProperty(Namespaces.format(lex_property))
- Parameters:
lex_property
- the lexical form of the property (eg"rdf:type"
).- Returns:
- the corresponding Jena property.
- See Also:
-
createResource
Helper to create ainvalid reference
resource
This is a shortcut forOpenRobotOntology.getModel().createResource(Namespaces.format(lex_resource))
. If a resource with the same lexical form already exist, it is reused. ThegetResource(String)
method can be used to retrieve resource without creating a new one if it doesn't exist.- Parameters:
lex_resource
- the lexical form of the resource.- Returns:
- the corresponding Jena resource.
- See Also:
-
getResource
com.hp.hpl.jena.ontology.OntResource getResource(String lex_resource) throws com.hp.hpl.jena.shared.NotFoundException Try to retrieve a resource from the ontology, based on its lexical form.- Parameters:
lex_resource
- The URI of a resource in the ontology.- Returns:
- a RDF model containing all the statements related the the given resource.
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- thrown if the resource doesn't exist in the ontology.- See Also:
-
getSubmodel
com.hp.hpl.jena.rdf.model.Model getSubmodel(com.hp.hpl.jena.rdf.model.Resource node) throws com.hp.hpl.jena.shared.NotFoundException Returns the set of inferred and asserted statement involving a resource as a Jena Model..- Parameters:
resource
- A Jena resource.- Returns:
- a RDF model containing all the statements related the the given resource.
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- thrown if the resource doesn't exist in the ontology.- See Also:
-
createStatement
com.hp.hpl.jena.rdf.model.Statement createStatement(String statement) throws IllegalStatementException This static method acts as a Statement factory. It does some pre-processing to convert a string to a valid statement relative to the given ontology.
Formatting follows roughly the SPARQL syntax :- Literals follows the
"value"^^type
rule for the general case. Simple or double quotes can be used. Cf examples below. - Resources can be either isolated ("
individual1
"). It will then use the default namespace as defined in theinvalid reference
configuration file
- Or prefixed with the namespace prefix ("
rdf:type
"), - Or complete URIs ("
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
"). In this case, the URI must be enclosed between < and >.
Literals examples:- The boolean
true
can be represented either as"true"^^xsd:boolean
or astrue
, - The integer
123
can be represented either as123^^xsd:int
or as123
."123"^^xsd:int
is also acceptable. - The double
1.23
can be represented either as1.23^^xsd:double
or as1.23
."1.23"^^xsd:double
is also acceptable. - User-defined dataypes can be represented with
"xyz"^^<http://example.org/ns/userDatatype>
or"xyz"^^oro:userDatatype
.
invalid reference
laas.openrobots.ontology.tests.OpenRobotsOntologyTest#testLiterals()
- Parameters:
statement
- a string containing a statement. For example,"oro:individual rdf:type oro:Class1"
or"oro:individual <> oro:Class1"
- Returns:
- a new Jena statement
- Throws:
IllegalStatementException
- See Also:
- Literals follows the
-
createPartialStatement
This static method acts as a PartialStatement factory. It does some pre-processing to convert a string to a valid statement relative to the given ontology.
SeecreateStatement(java.lang.String)
for syntax details regarding literals.
To be valid, a partial statement must have at least one variable, prepended with a "?".- Parameters:
statement
- a string representing the partial statement. For instance:"?mysterious oro:objProperty2 oro:individual2"
- Returns:
- a new partially defined statement
- Throws:
IllegalStatementException
- See Also:
-
size
long size()Returns the number of statements in the model.- Returns:
- the number of statements in the model.
-
getModel
com.hp.hpl.jena.ontology.OntModel getModel()Returns the underlying Jena ontology model.- Returns:
- the current underlying Jena ontology model.
-
add
boolean add(Set<com.hp.hpl.jena.rdf.model.Statement> statements, MemoryProfile memProfile, boolean safe) throws IllegalStatementException Adds a set of new statements (assertion) to the ontology. If one of the statements already exists, it won't be inserted.
A memory profile is associated to all the statements: statements associated toinvalid reference
MemoryProfile.LONGTERM
invalid reference
MemoryProfile.DEFAULT
- Parameters:
statements
- A set of statements to be inserted in the model.memProfile
- The memory profile associated to this statement.safe
- If true, the statement is added only if it does not- Returns:
- True if all the statements have been actually added to the model
(actually useful only in conjunction with the
safe
parameter enabled). - Throws:
IllegalStatementException
- Currently only thrown if a concept is asserted to be both an instance and a class.
-
add
@Deprecated boolean add(com.hp.hpl.jena.rdf.model.Statement statement, MemoryProfile memProfile, boolean safe) throws IllegalStatementException Deprecated.Please useadd(Set, MemoryProfile, boolean)
insteadAdds a new statement (assertion) to the ontology.- Throws:
IllegalStatementException
- See Also:
-
check
boolean check(com.hp.hpl.jena.rdf.model.Statement statement) Checks if a statement is asserted or can be inferred from the ontology. The check is done in an open world (everything is true except if it's explicitely false). For instance, if only the following statement is asserted:bottle hasColor green
check("bottle hasColor orange")
would returntrue
. If the two following statements are added to the ontology:green owl:isDifferentFrom orange hasColor rdf:type owl:functionalProperty
thencheck("bottle hasColor orange")
would returnfalse
.- Parameters:
statement
- the statement to be evaluated- Returns:
- true if the statement is asserted in or can be inferred from the ontology
-
check
Checks if a pattern represented as a partial statement matches at least one asserted of inferred statement.
For instance:- A pattern like
[?object rdf:type Bottle]
would match all instances of the classBottle
. [anAgent sees ?something]
would match all objects seen by instance "anAgent
".
- Parameters:
statement
- the partial pattern to be evaluated- Returns:
- true if the pattern matches at least one asserted or inferred statement of the ontology.
- See Also:
- A pattern like
-
checkConsistency
boolean checkConsistency()Performs a consistency validation against the ontology. Returns false if the check fails. -
checkConsistency
Checks a set of statements (or partial statements) are not inconsistent with the current model. The method temporarily adds the given statements to the model, checks the whole model consistency, remove the statements and return the result of the consistency check (true or false).- See Also:
-
query
Performs a SPARQL query on the OpenRobots ontology.
For instance:IOntologyServer myOntology = new OpenRobotsOntology(); ResultSet result = myOntology.query( "PREFIX rdf: invalid input: '<'http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX owl: invalid input: '<'http://www.w3.org/2002/07/owl#> \n" + "SELECT ?instances \n" + "WHERE { \n" + "?instances rdf:type owl:Thing}\n"); for ( ; result.hasNext() ; ) { System.out.println(result.nextSolution().toString()); }
This example would print all the instances existing in the ontology.
Attention! Unlike other methods which take string representation of statements or resource, namespaces or namespace prefixes CAN NOT be omitted:SELECT ?instance WHERE {?instance eats bananas}
won't match the same things asSELECT ?instance WHERE {?instance oro:eats oro:bananas}
even iforo
is the prefix of the default namespace.- Parameters:
query
- A well-formed SPARQL query to perform on the ontology.PREFIX
statements may be omitted if they are the standard ones (namely, owl, rdf, rdfs) or the LAAS OpenRobots ontology (oro) one.query
-- Returns:
- The result of the query as a set of RDFNode (either resources or literals).
- Throws:
com.hp.hpl.jena.query.QueryParseException
- thrown if the argument is not a valid SPARQL query.InvalidQueryException
- See Also:
-
find
Set<com.hp.hpl.jena.rdf.model.RDFNode> find(String varName, Set<PartialStatement> statements, Set<String> filters) throws InvalidQueryException Tries to identify a resource given a set of partially defined statements (plus optional restrictions) about this resource.- Parameters:
varName
- The name of the variable to bind, as used in the partial statements.statements
- A set of partial statements that globaly define a search patternfilters
- a vector of string containing the various filters to be appended to the search. The syntax is the SPARQL one (as defined here: http://www.w3.org/TR/rdf-sparql-query/#tests).- Returns:
- a set of resources or literal (RDFNode) that match the statements.
- Throws:
InvalidQueryException
- See Also:
-
getSuperclassesOf
Set<com.hp.hpl.jena.ontology.OntClass> getSuperclassesOf(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
getSubclassesOf
Set<com.hp.hpl.jena.ontology.OntClass> getSubclassesOf(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
getInstancesOf
Set<com.hp.hpl.jena.ontology.OntResource> getInstancesOf(com.hp.hpl.jena.ontology.OntClass type, boolean onlyDirect) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
getClassesOf
Set<com.hp.hpl.jena.ontology.OntClass> getClassesOf(com.hp.hpl.jena.ontology.OntResource individual, boolean onlyDirect) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
lookup
Returns the set of all [id, type, label] (with type one of INSTANCE, CLASS, OBJECT_PROPERTY, DATATYPE_PROPERTY, UNDEFINED) of concepts whose labels or id match the given parameter.- Parameters:
label
- the label (in any language) or id to look for.- Returns:
- A list made of the id of the concept whose label matches the parameter followed by its type, or an empty set if nothing was found.
- See Also:
-
lookup
Returns the set of all id of concepts whose labels or ids match the given parameter and of the given type.- Parameters:
type
- the type of the resource that is looked for.label
- the label (in any language) or id to look for.- Returns:
- A set of ids whose label matches the parameter or an empty set.
- See Also:
-
clear
Remove all statements matching the partial statement. Usage example:
IOntologyServer myOntology = new OpenRobotsOntology(); Model results = myOntology.getInfos("ns:individual1"); NodeIterator types = results.listObjectsOfProperty(myOntology.createProperty("rdf:type")); for ( ; types.hasNext() ; ) { System.out.println(types.nextNode().toString()); }
- Parameters:
partialStmt
- The partial statement representing a "mask" of statements to delete.- Throws:
OntologyServerException
-
remove
Deprecated.Removes a given statement from the ontology. Does nothing if the statement doesn't exist.- Parameters:
stmt
- The statement to remove from the ontology.- Throws:
OntologyServerException
- See Also:
-
remove
Removes a set of statements from the ontology. It ignores statements that do not exist.- Parameters:
stmts
- The statements to remove from the ontology.- Throws:
OntologyServerException
- See Also:
-
update
void update(Set<com.hp.hpl.jena.rdf.model.Statement> stmts) throws IllegalStatementException, InconsistentOntologyException, OntologyServerException Update the value of a property. This method is equivalent to aremove(Statement)
followed by anadd(Set, MemoryProfile, boolean)
. ATTENTION: this method works only on functional properties (ie, properties that are subclasses ofowl:FunctionalProperty
. For non-functional properties (or if the subject or predicate does not exist), this method behaves likeinvalid reference
#add(Set)
- Parameters:
stmts
- The set of statements to update in the ontology.- Throws:
IllegalStatementException
InconsistentOntologyException
OntologyServerException
-
save
Saves the in-memory ontology model to a RDF/XML file.- Parameters:
path
- The path and name of the OWL file to save to (for instance./ontos/saved.owl
)- Throws:
OntologyServerException
- thrown when the output path is not valid or not accessible.- See Also:
-
registerEvent
Allows to register several events providers (typically, one by underlying middleware) which in turn provide access to watchers. Watchers expose a watch expression which is a SPARQLASK
query. Every time a change is made on the ontology, the ontology backend which implements this interface is expected to execute this query against the model and notify the watchers (throughinvalid reference
IWatcher#notifySubscriber()
- Parameters:
watcherProviders
- A set of event providers.- Throws:
EventRegistrationException
- See Also:
-
clearEvents
void clearEvents()Removes all registered event watchers for this model. -
clearEvent
Removes one specific event watcher.- Parameters:
watcher
- the watcher to remove- Throws:
OntologyServerException
-
getSupportedEvents
Set<IWatcher.EventType> getSupportedEvents()Return the list of event types implemented (hence usable) by this backend.- Returns:
- The list of event type supported by the backend
-
step
void step()'Step' the model. At each server main loop iteration, the 'step' method is called for each model. The model can do here its own internal homeworks. -
close
void close()Closes the model
-
add(Set, MemoryProfile, boolean)
instead