Class BaseModule
java.lang.Object
laas.openrobots.ontology.modules.base.BaseModule
- All Implemented Interfaces:
IServiceProvider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Likeadd(Set<String>, String)
with theMemoryProfile.DEFAULT
memory profile.void
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.Checks if the ontology is consistent.checkConsistency
(Set<String> rawStmts) Checks that a set of statements are consistent with the current model.void
Removes all statements matching any statements or partial statements in the provided set.Tries to identify a resource given a set of partially defined statements about this resource.
This is a simpler form forfind(String, Set, Set)
, without filters.Tries to identify a resource given a set of partially defined statements (plus optional restrictions) about this resource.
First simple example:getClassesOf
(String individual) getDirectClassesOf
(String individual) getDirectInstancesOf
(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.getDirectSubclassesOf
(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.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.Returns the set of asserted and inferred statements whose the given node is part of.getInstancesOf
(String type) Returns all the instances of a given class, as asserted or inferred from the ontology.Returns the label associated to a concept whose name is 'id'.LikegetResourceDetails(String, String)
with language set to default language (as set in the server config file).getResourceDetails
(String id, String language_code) Returns a complete description of a resource identified byid
, 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.getSubclassesOf
(String type) Returns all the sub-classes of a given class, as asserted or inferred from the ontology.getSuperclassesOf
(String type) Returns all the super classes of a given class, as asserted or inferred from the ontology.MapsIOntologyBackend.query(String, String)
into a RPC callvoid
Deprecated.boolean
boolean
Adds statements with a specific memory model, but only if the statement doesn't cause any inconsistency.void
Update the value of a property.
-
Constructor Details
-
BaseModule
-
-
Method Details
-
add
@RPCMethod(desc="adds one or several statements (triplets S-P-O) to the robot model, in long term memory.") public void add(Set<String> rawStmts) throws IllegalStatementException Likeadd(Set<String>, String)
with theMemoryProfile.DEFAULT
memory profile.- Parameters:
statements
- A set of string representing statements to be inserted in the ontology.- Throws:
IllegalStatementException
- See Also:
-
safeAdd
@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(Set<String> rawStmts) throws IllegalStatementException - Throws:
IllegalStatementException
-
update
@RPCMethod(desc="update the value of a functional property.") public void update(Set<String> rawStmts) throws IllegalStatementException, InconsistentOntologyException, OntologyServerException Update the value of a property. This method is equivalent to aremove(Set)
followed by anadd(Set)
. 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 likeadd(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.- Parameters:
statements
- A set of string representing statements to be updated.- Throws:
IllegalStatementException
InconsistentOntologyException
OntologyServerException
- See Also:
-
add
@RPCMethod(desc="adds one or several statements (triplets S-P-O) to the robot model associated with a memory profile.") public void add(Set<String> rawStmts, String memProfile) throws IllegalStatementException 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. If the same statements are added with a different memory profile, the shortest term memory container has priority. To create literals, you must suffix the value with^^xsd:
and the XML schema datatype.
For instance: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). vector
This 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; } - Parameters:
rawStmts
- A set of new statements.memProfile
- The memory profile associated with this statement.- Throws:
IllegalStatementException
- See Also:
-
Syntax details regarding the string describing the statement.
IOntologyBackend.add(Statement, MemoryProfile, boolean)
remove(Set)
-
safeAdd
@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(Set<String> rawStmts, String memProfile) throws IllegalStatementException Adds statements with a specific memory model, but only if the statement doesn't cause any inconsistency. If one statement cause an inconsistency, it won't be added, the return value will be "false", and the process continue with the remaining statements.- Parameters:
rawStmts
- a set of statementsmemProfile
- the memory profile- Returns:
- false if at least one statement was not added because it would lead to inconsistencies.
- Throws:
IllegalStatementException
-
remove
@RPCMethod(desc="removes one or several statements (triplets S-P-O) from the ontology.") public void remove(Set<String> rawStmts) throws IllegalStatementException, OntologyServerException Deprecated.Useclear(Set)
instead.Remove a set of statements (represented as a strings) from the ontology. Does nothing if the statements don't exist.- Parameters:
stmts
- A vector of strings representing the statements to remove from the ontology.- Throws:
OntologyServerException
IllegalStatementException
- See Also:
-
add(Set)
#remove(String)
-
clear
@RPCMethod(desc="removes statements in the given set") public void clear(Set<String> rawStmts) throws IllegalStatementException, OntologyServerException Removes all statements matching any statements or partial statements in the provided set. Complete statements (like 'bottle1 hasColor blue') and partial statements (like 'bottle1 hasColor ?val') can be freely mixed. Partial statements can be seen as 'statements with wildcards'. Attention, the implicit relation between each of the partial statements in the set is a OR: the ontology is matched against each of the provided partial statements, and for each of them, all matching statements are removed. If need, the "AND" behaviour can be added. Please drop a mail to openrobots@laas.fr- Parameters:
stmts
- A set of statements, partial or not, to remove.- Throws:
IllegalStatementException
- thrown if the string does not represent a valid statement or partial statement.OntologyServerException
- See Also:
-
check
@RPCMethod(desc="checks that one or several statements are asserted or can be inferred from the ontology") public Boolean check(Set<String> stmts) throws IllegalStatementException - Throws:
IllegalStatementException
-
checkConsistency
@RPCMethod(desc="checks that the ontology is semantically consistent") public Boolean checkConsistency()Checks if the ontology is consistent.- Returns:
- true if the ontology is consistent, false otherwise.
-
checkConsistency
@RPCMethod(desc="checks that a set of statements are consistent with the current model") public Boolean checkConsistency(Set<String> rawStmts) throws IllegalStatementException Checks that a set of statements are consistent with the current model. Statements are not added to the model.- Returns:
- true if the set of given statement is consistent with the ontology, false otherwise.
- Throws:
IllegalStatementException
-
query
@RPCMethod(category="querying", desc="performs one SPARQL query on the ontology") public Set<String> query(String key, String q) throws InvalidQueryException, OntologyServerException MapsIOntologyBackend.query(String, String)
into a RPC call -
find
@RPCMethod(category="querying", desc="tries to identify a resource given a set of partially defined statements plus restrictions about this resource.") public Set<String> find(String varName, Set<String> statements, Set<String> filters) throws IllegalStatementException, OntologyServerException Tries to identify a resource given a set of partially defined statements (plus optional restrictions) about this resource.
First simple example:IOntologyServer myOntology = new OpenRobotsOntology(); Set
Supposing 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
.
Example with restrictions:IOntologyServer myOntology = new OpenRobotsOntology(); Set
This 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...).
C++ code snippet using liboro:#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; } - Parameters:
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).- Returns:
- A vector of resources which match the statements. An empty vector is no matching resource is found.
- Throws:
IllegalStatementException
OntologyServerException
- See Also:
-
find
@RPCMethod(category="querying", desc="tries to identify a resource given a set of partially defined statements about this resource.") public Set<String> find(String varName, Set<String> statements) throws IllegalStatementException, OntologyServerException Tries to identify a resource given a set of partially defined statements about this resource.
This is a simpler form forfind(String, Set, Set)
, without filters.
C++ code snippet using liboro:#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; } - Parameters:
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.- Returns:
- A vector of resources which match the statements. An empty vector is no matching resource is found.
- Throws:
IllegalStatementException
OntologyServerException
- See Also:
-
#find(String, Vector, Vector)
General syntax of RPCs for the oro-server socket connector.
-
find
-
getInfos
@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 Set<String> getInfos(String lex_resource) throws com.hp.hpl.jena.shared.NotFoundException Returns the set of asserted and inferred statements whose the given node is part of. It represents the "usages" of a resource.
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()); }
This example would print all the types (classes) of the instancens:individual1
.- Parameters:
lex_resource
- the lexical form of an existing resource.- Returns:
- a RDF model containing all the statements related the the given resource.
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- thrown if the lex_resource doesn't exist in the ontology.- See Also:
-
getSuperclassesOf
@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 Map<String,String> getSuperclassesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException Returns all the super classes of a given class, as asserted or inferred from the ontology.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of classe ids associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getDirectSuperclassesOf
@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 Map<String,String> getDirectSuperclassesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException 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.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of classe ids associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getSubclassesOf
@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 Map<String,String> getSubclassesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException Returns all the sub-classes of a given class, as asserted or inferred from the ontology.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of classe ids associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getDirectSubclassesOf
@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 Map<String,String> getDirectSubclassesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException 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.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of classe ids associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getInstancesOf
@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 Map<String,String> getInstancesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException Returns all the instances of a given class, as asserted or inferred from the ontology.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of classe ids associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getDirectInstancesOf
@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 Map<String,String> getDirectInstancesOf(String type) throws com.hp.hpl.jena.shared.NotFoundException 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.- Parameters:
type
- A class, in its namespace (if no namespace is specified, the default namespace is assumed, as defined in the configuration file)- Returns:
- A map of instances ids (individuals) associated to their labels (in the default language, as defined in the configuration file).
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getClassesOf
@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 Map<String,String> getClassesOf(String individual) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
getDirectClassesOf
@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 Map<String,String> getDirectClassesOf(String individual) throws com.hp.hpl.jena.shared.NotFoundException - Throws:
com.hp.hpl.jena.shared.NotFoundException
-
getResourceDetails
@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(String id, String language_code) throws com.hp.hpl.jena.shared.NotFoundException Returns a complete description of a resource identified byid
, 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.- Parameters:
id
- the concept whose description is queriedlanguage_code
- a standard language code.- Returns:
- a ResourceDescription object, serializable as a JSON string
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
getResourceDetails
@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(String id) throws com.hp.hpl.jena.shared.NotFoundException LikegetResourceDetails(String, String)
with language set to default language (as set in the server config file).- Parameters:
id
- the concept whose description is queried- Returns:
- a ResourceDescription object, serializable as a JSON string
- Throws:
com.hp.hpl.jena.shared.NotFoundException
- See Also:
-
lookup
-
lookup
-
getLabel
@RPCMethod(desc="return the label of a concept, if available.") public String getLabel(String id) throws com.hp.hpl.jena.shared.NotFoundException Returns the label associated to a concept whose name is 'id'. The label language can be specified in the configuration file (option 'language') and default to English ('en'). If the concept has no label, the concept id is returned.- Parameters:
the
- id to look for.- Returns:
- One of the labels associated to this id or the id itself if no label has been defined.
- Throws:
OntologyServerException
com.hp.hpl.jena.shared.NotFoundException
-
clear(Set)
instead.