SparqlClient Class

The SparqlClient class provides a ROS service to explore ontologenius with SPARQL-like queries. More...

Header: #include "ontologenius/clients/SparqlClient.h"
Namespace: onto

Methods

SparqlClient(const std::string& name)
std::pair<std::vector<std::string>, std::vector<OntologeniusSparqlResponse>> call(const std::string& query)

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

SparqlClient(const std::string& name)

Constructs a sparql client.

Can be used in a multi-ontology mode by specifying the name of the ontology name. For classic use, name should be defined as "".

std::pair<std::vector<std::string>, std::vector<OntologeniusSparqlResponse>> call(const std::string& 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.