SparqlClient Class
The SparqlClient class provides a ROS service to explore ontologenius with SPARQL-like queries. More...
| Ros1 Package: | ontologenius |
| Ros2 Package: | ontopy |
Methods
Detailed Description
The SparqlClient class provides a ROS service to explore ontologenius with SPARQL-like queries.
The variables start with the symbol ? (e.g. ?my_var) and each triplet is separated by a dot.
Methods Documentation
__init__(self, name)
Constructs a sparql client.
Can be used in a multi-ontology mode by specifying the name of the ontology name(str). For classic use, name should be defined as ''.
(str[], OntologeniusSparqlResponse[])call(self, query)
Basic query Examples
The general structure is always the same:
SELECT * // or ?x to get specific variables
WHERE {
// pattern
}
You can also add the DISTINCT keyword just after the SELECT to ensure unique results. The following blocks are examples of possible patterns.
Bedroom isA ?type
names: [type]
results:
- values: [Room]
Give to class of Bedroom.
?table isA Table
names: [table]
results:
- values: [Table2]
- values: [Table1]
Give all the tables.
Table1 isIn ?room
names: [room]
results:
- values: [Bedroom]
Give all the individuals for which the individual 'Table1' is in it.
?object isA Table. ?object isIn ?room
names: [object, room]
results:
- values: [Table2, LivingRoom]
- values: [Table1, Bedroom]
Give all the individuals that are tables and the room in which they are.
Query with negation
?object isA Table NOT EXISTS { ?object isIn LivingRoom }
names: [object]
results:
- values: [Table1]
Give all the individuals that are tables and not in the living room.