public class BaseModule extends java.lang.Object implements IServiceProvider
Constructor and Description |
---|
BaseModule(IOntologyBackend oro) |
Modifier and Type | Method and Description |
---|---|
void |
add(java.util.Set<java.lang.String> rawStmts)
Like
#add(Set with the MemoryProfile.DEFAULT memory profile. |
void |
add(java.util.Set<java.lang.String> rawStmts,
java.lang.String memProfile)
Adds a set of statements (assertions) to the ontology from their string representation in the given memory profile.
This method does nothing if the statements already exist with the same memory profile. |
java.lang.Boolean |
check(java.util.Set<java.lang.String> stmts) |
java.lang.Boolean |
checkConsistency()
Checks if the ontology is consistent.
|
java.lang.Boolean |
checkConsistency(java.util.Set<java.lang.String> rawStmts)
Checks that a set of statements are consistent with the current model.
|
void |
clear(java.util.Set<java.lang.String> rawStmts)
Removes all statements matching any statements or partial statements in
the provided set.
|
java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
find(java.util.Set<java.lang.String> variables,
java.util.Set<java.lang.String> partialStatements) |
java.util.Set<java.lang.String> |
find(java.lang.String varName,
java.util.Set<java.lang.String> statements)
Tries to identify a resource given a set of partially defined statements about this resource.
This is a simpler form for find(String, Set, Set) , without filters. |
java.util.Set<java.lang.String> |
find(java.lang.String varName,
java.util.Set<java.lang.String> statements,
java.util.Set<java.lang.String> filters)
Tries to identify a resource given a set of partially defined statements (plus optional restrictions) about this resource.
First simple example: |
java.util.Map<java.lang.String,java.lang.String> |
getClassesOf(java.lang.String individual) |
java.util.Map<java.lang.String,java.lang.String> |
getDirectClassesOf(java.lang.String individual) |
java.util.Map<java.lang.String,java.lang.String> |
getDirectInstancesOf(java.lang.String type)
Returns all the direct instances of a given class (ie, the instances whose the given class is the direct parent), as asserted or inferred from the ontology.
|
java.util.Map<java.lang.String,java.lang.String> |
getDirectSubclassesOf(java.lang.String type)
Returns all the direct sub-classes of a given class (ie, the classes whose the given class is the direct parent), as asserted or inferred from the ontology.
|
java.util.Map<java.lang.String,java.lang.String> |
getDirectSuperclassesOf(java.lang.String type)
Returns all the direct super-classes of a given class (ie, the classes whose the given class is a direct descendant), as asserted or inferred from the ontology.
|
java.util.Set<java.lang.String> |
getInfos(java.lang.String lex_resource)
Returns the set of asserted and inferred statements whose the given node is part of.
|
java.util.Map<java.lang.String,java.lang.String> |
getInstancesOf(java.lang.String type)
Returns all the instances of a given class, as asserted or inferred from the ontology.
|
java.lang.String |
getLabel(java.lang.String id)
Returns the label associated to a concept whose name is 'id'.
|
ResourceDescription |
getResourceDetails(java.lang.String id)
Like
getResourceDetails(String, String) with language set to
default language (as set in the server config file). |
ResourceDescription |
getResourceDetails(java.lang.String id,
java.lang.String language_code)
Returns a complete description of a resource identified by
id ,
including its type, label (in a specified language, if available), plus:
- superclasses, subclasses and instances for classes
- class for instances
These data are sent as a JSON serialization. |
java.util.Map<java.lang.String,java.lang.String> |
getSubclassesOf(java.lang.String type)
Returns all the sub-classes of a given class, as asserted or inferred from the ontology.
|
java.util.Map<java.lang.String,java.lang.String> |
getSuperclassesOf(java.lang.String type)
Returns all the super classes of a given class, as asserted or inferred from the ontology.
|
java.util.Set<java.util.List<java.lang.String>> |
lookup(java.lang.String id) |
java.util.Set<java.lang.String> |
lookup(java.lang.String id,
java.lang.String type) |
java.util.Set<java.lang.String> |
query(java.lang.String key,
java.lang.String q)
Maps
IOntologyBackend.query(String, String) into a RPC call |
void |
remove(java.util.Set<java.lang.String> rawStmts)
Deprecated.
Use
clear(Set) instead. |
boolean |
safeAdd(java.util.Set<java.lang.String> rawStmts) |
boolean |
safeAdd(java.util.Set<java.lang.String> rawStmts,
java.lang.String memProfile)
Adds statements with a specific memory model, but only if the statement
doesn't cause any inconsistency.
|
void |
update(java.util.Set<java.lang.String> rawStmts)
Update the value of a property.
|
public BaseModule(IOntologyBackend oro)
@RPCMethod(desc="adds one or several statements (triplets S-P-O) to the robot model, in long term memory.") public void add(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException
#add(Set, String)
with the MemoryProfile.DEFAULT
memory profile.statements
- A set of string representing statements to be inserted in the ontology.IllegalStatementException
add(Set, String)
,
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(desc="try to add news statements in long term memory, if they don\'t lead to inconsistencies (return false if at least one stmt wasn\'t added).") public boolean safeAdd(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException
IllegalStatementException
@RPCMethod(desc="update the value of a functional property.") public void update(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException, InconsistentOntologyException, OntologyServerException
remove(Set)
followed by an add(Set)
.
ATTENTION: this method works only on functional properties (ie,
properties that are subclasses of owl:FunctionalProperty. For non-functional properties (or if the subject or predicate does not exist), this method behaves like
add(Set)
.
Example:
add(["alice isLost true"]) -> ontology contains the fact "alice isLost true" update(["alice isLost false"]) -> ontology contains the fact "alice isLost false"Please note that the newly created statement is put in the DEFAULT memory profile, usually the long-term one.
statements
- A set of string representing statements to be updated.IllegalStatementException
InconsistentOntologyException
OntologyServerException
IOntologyBackend#update(Set)}
,
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(desc="adds one or several statements (triplets S-P-O) to the robot model associated with a memory profile.") public void add(java.util.Set<java.lang.String> rawStmts, java.lang.String memProfile) throws IllegalStatementException
^^xsd:
and the XML schema datatype.
IOntologyServer myOntology = new OpenRobotsOntology(); myOntology.add("myIndividual myBooleanPredicate true^^xsd:boolean", MemoryProfile.SHORTTERM);Examples of statements:
"oro:instance1 rdf:type oro:Class1"
"oro:instance1 oro:dataProperty1 true^^xsd:boolean"
"instance1 dataProperty1 true"
(if no namespace is specified, it uses the default one)liboro
library:
#include "oro.h" #include "socket_connector.h" using namespace std; using namespace oro; int main(void) { SocketConnector connector("localhost", "6969"); Ontology* onto = Ontology::createWithConnector(connector); onto->add(Statement("gorilla rdf:type Monkey")); onto->add(Statement("gorilla age 12^^xsd:int")); onto->add(Statement("gorilla weight 75.2")); // You can as well send a set of statement. The transport will be optimized (all the statements are sent in one time). vectorThis method does nothing if the statement already exists with the same memory profile. If the same statement is added with a different memory profile, the shortest term memory container has priority.stmts; stmts.push_back("gorilla rdf:type Monkey"); stmts.push_back("gorilla age 12^^xsd:int"); stmts.push_back("gorilla weight 75.2"); onto->add(stmts); return 0; }
rawStmts
- A set of new statements.memProfile
- The memory profile associated with this statement.IllegalStatementException
Syntax details regarding the string describing the statement.
,
IOntologyBackend.add(Statement, MemoryProfile, boolean)
,
remove(Set)
@RPCMethod(desc="try to add news statements with a specific memory profile, if they don\'t lead to inconsistencies (return false if at least one stmt wasn\'t added).") public boolean safeAdd(java.util.Set<java.lang.String> rawStmts, java.lang.String memProfile) throws IllegalStatementException
rawStmts
- a set of statementsmemProfile
- the memory profileIllegalStatementException
@RPCMethod(desc="removes one or several statements (triplets S-P-O) from the ontology.") public void remove(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException, OntologyServerException
clear(Set)
instead.stmts
- A vector of strings representing the statements to remove from the ontology.OntologyServerException
IllegalStatementException
add(Set)
,
#remove(String)
@RPCMethod(desc="removes statements in the given set") public void clear(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException, OntologyServerException
stmts
- A set of statements, partial or not, to remove.IllegalStatementException
- thrown if the string does not represent
a valid statement or partial statement.OntologyServerException
PartialStatement
,
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(desc="checks that one or several statements are asserted or can be inferred from the ontology") public java.lang.Boolean check(java.util.Set<java.lang.String> stmts) throws IllegalStatementException
IllegalStatementException
@RPCMethod(desc="checks that the ontology is semantically consistent") public java.lang.Boolean checkConsistency()
@RPCMethod(desc="checks that a set of statements are consistent with the current model") public java.lang.Boolean checkConsistency(java.util.Set<java.lang.String> rawStmts) throws IllegalStatementException
IllegalStatementException
@RPCMethod(category="querying", desc="performs one SPARQL query on the ontology") public java.util.Set<java.lang.String> query(java.lang.String key, java.lang.String q) throws InvalidQueryException, OntologyServerException
IOntologyBackend.query(String, String)
into a RPC call@RPCMethod(category="querying", desc="tries to identify a resource given a set of partially defined statements plus restrictions about this resource.") public java.util.Set<java.lang.String> find(java.lang.String varName, java.util.Set<java.lang.String> statements, java.util.Set<java.lang.String> filters) throws IllegalStatementException, OntologyServerException
IOntologyServer myOntology = new OpenRobotsOntology(); SetSupposing your ontology defines the right properties and instances, you can expect this example to output something likeknowledge = new Set (); knowledge.add("?mysterious_object ns:isEdibleBy ns:monkey"); knowledge.add("?mysterious_object ns:color "yellow"^^ns:color"); Set results = myOntology.find("mysterious_object", knowledge); for (String res:results) System.out.println(res);
ns:banana
.IOntologyServer myOntology = new OpenRobotsOntology(); SetThis example would output all theknowledge = new Set (); Set filters = new Set (); knowledge.add("?mysterious_object ns:isEdibleBy ns:monkey"); knowledge.add("?mysterious_object ns:color "yellow"^^ns:color"); knowledge.add("?mysterious_object ns:size ?size); filters.add("?size >= 200.0"); filters.add("?size < 250.0"); Set results = myOntology.find("mysterious_object", knowledge, filters); for (String res:results) System.out.println(res);
ns:banana
s whose size is comprised between 200 and 250mm (assuming mm is the unit you are using...).
#include "oro.h" #include "yarp_connector.h" using namespace std; using namespace oro; int main(void) { set<Concept> result; set<string> partial_stmts; set<string> filters; YarpConnector connector("myDevice", "oro"); Ontology* onto = Ontology::createWithConnector(connector); partial_stmts.insert("?mysterious rdf:type oro:Monkey"); partial_stmts.insert("?mysterious oro:weight ?value"); filters.insert("?value >= 50"); onto->find("mysterious", partial_stmts, filters, result); //display the result copy(result.begin(), result.end(), ostream_iterator(cout, "\n")); return 0; }
varName
- The name of the variable to identify, as used in the statements.statements
- The partial statement statements defining (more or less) the resource your looking for.filters
- a vector of string containing the various filters you want to append to your search. The syntax is the SPARQL one (as defined here: http://www.w3.org/TR/rdf-sparql-query/#tests).IllegalStatementException
OntologyServerException
Syntax of partial statements
,
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="querying", desc="tries to identify a resource given a set of partially defined statements about this resource.") public java.util.Set<java.lang.String> find(java.lang.String varName, java.util.Set<java.lang.String> statements) throws IllegalStatementException, OntologyServerException
find(String, Set, Set)
, without filters.
#include "oro.h" #include "yarp_connector.h" using namespace std; using namespace oro; int main(void) { set<Concept> result; set<string> partial_stmts; YarpConnector connector("myDevice", "oro"); Ontology* onto = Ontology::createWithConnector(connector); partial_stmts.insert("?mysterious oro:eats oro:banana_tree"); partial_stmts.insert("?mysterious oro:isFemale true^^xsd:boolean"); onto->find("mysterious", partial_stmts, result); //display the result copy(result.begin(), result.end(), ostream_iterator(cout, "\n")); return 0; }
varName
- The name of the variable to identify, as used in the statements.statements
- The partial statement statements defining (more or less) the resource your looking for.IllegalStatementException
OntologyServerException
#find(String, Vector, Vector)
,
General syntax of RPCs for the oro-server socket connector.
public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> find(java.util.Set<java.lang.String> variables, java.util.Set<java.lang.String> partialStatements)
@RPCMethod(category="querying", desc="returns the set of asserted and inferred statements whose the given node is part of. It represents the usages of a resource.") public java.util.Set<java.lang.String> getInfos(java.lang.String lex_resource) throws com.hp.hpl.jena.shared.NotFoundException
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()); }This example would print all the types (classes) of the instance
ns:individual1
.lex_resource
- the lexical form of an existing resource.com.hp.hpl.jena.shared.NotFoundException
- thrown if the lex_resource doesn't exist in the ontology.General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of all asserted and inferred superclasses of a given class.") public java.util.Map<java.lang.String,java.lang.String> getSuperclassesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of all asserted and inferred direct superclasses of a given class.") public java.util.Map<java.lang.String,java.lang.String> getDirectSuperclassesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of all asserted and inferred subclasses of a given class.") public java.util.Map<java.lang.String,java.lang.String> getSubclassesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of all asserted and inferred direct subclasses of a given class.") public java.util.Map<java.lang.String,java.lang.String> getDirectSubclassesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {instance name, label} (or {instance name, instance name without namespace} is no label is available) of asserted and inferred instances of a given class.") public java.util.Map<java.lang.String,java.lang.String> getInstancesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {instance name, label} (or {instance name, instance name without namespace} is no label is available) of asserted and inferred direct instances of a given class.") public java.util.Map<java.lang.String,java.lang.String> getDirectInstancesOf(java.lang.String type) throws com.hp.hpl.jena.shared.NotFoundException
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)com.hp.hpl.jena.shared.NotFoundException
General syntax of RPCs for the oro-server socket connector.
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of asserted and inferred classes of a given individual.") public java.util.Map<java.lang.String,java.lang.String> getClassesOf(java.lang.String individual) throws com.hp.hpl.jena.shared.NotFoundException
com.hp.hpl.jena.shared.NotFoundException
@RPCMethod(category="taxonomy", desc="returns a map of {class name, label} (or {class name, class name without namespace} is no label is available) of asserted and inferred direct classes of a given individual.") public java.util.Map<java.lang.String,java.lang.String> getDirectClassesOf(java.lang.String individual) throws com.hp.hpl.jena.shared.NotFoundException
com.hp.hpl.jena.shared.NotFoundException
@RPCMethod(category="querying", desc="returns a serialized ResourceDescription object that describe all the links of this resource with others resources (sub and superclasses, instances, properties, etc.). The second parameter specify the desired language (following RFC4646).") public ResourceDescription getResourceDetails(java.lang.String id, java.lang.String language_code) throws com.hp.hpl.jena.shared.NotFoundException
id
,
including its type, label (in a specified language, if available), plus:
- superclasses, subclasses and instances for classes
- class for instances
These data are sent as a JSON serialization.
Reference for language code is available in RFC4646.id
- the concept whose description is queriedlanguage_code
- a standard language code.com.hp.hpl.jena.shared.NotFoundException
ResourceDescription
@RPCMethod(category="querying", desc="returns a serialized ResourceDescription object that describe all the links of this resource with others resources (sub and superclasses, instances, properties, etc.).") public ResourceDescription getResourceDetails(java.lang.String id) throws com.hp.hpl.jena.shared.NotFoundException
getResourceDetails(String, String)
with language set to
default language (as set in the server config file).id
- the concept whose description is queriedcom.hp.hpl.jena.shared.NotFoundException
getResourceDetails(String, String)
@RPCMethod(desc="try to identify a concept from its id or label, and return it, along with its type (class, instance, object_property, datatype_property).") public java.util.Set<java.util.List<java.lang.String>> lookup(java.lang.String id)
@RPCMethod(desc="try to identify a concept from its id or label and its type (class, instance, object_property, datatype_property).") public java.util.Set<java.lang.String> lookup(java.lang.String id, java.lang.String type)
@RPCMethod(desc="return the label of a concept, if available.") public java.lang.String getLabel(java.lang.String id) throws com.hp.hpl.jena.shared.NotFoundException
the
- id to look for.OntologyServerException
com.hp.hpl.jena.shared.NotFoundException
ORO is a part of the OpenRobots framework.
openrobots@laas.fr
LAAS-CNRS 2009-2011