SPARQL BT Queries - aantakli/AJAN-service GitHub Wiki
SPARQL Queries are an essential part of SPARQL-BT, because SBT nodes use them to query or manipulate the agent knowledge or other RDF datasets. To query a repository or RDF dataset a "origin base" has to be selected. In ajan there are five internally defined repositories, which can be selected via the predicate bt:originBase:
Repository | Explanation | URL |
---|---|---|
Agent Knowledge | Agent knowledge refers to the knowledge base of the respective agent to which every initiated SBT of an agent has access. | http://www.ajan.de/ajan-ns#AgentKnowledge |
Execution Knowledge | Execution Knowledge refers to the knowledge base of the respective SBT to which only this SBT has access. | http://www.ajan.de/ajan-ns#ExecutionKnowledge |
Behavior Templates | Behavior Templates refers to the repository that contains all Behavior (SBT) templates. All initiated agents have access to this repository. | http://www.ajan.de/ajan-ns#BehaviorKnowledge |
Domain Information | Domain Information refers to the repository that contains domain specific information like ontologies, rules, mapping information. All initiated agents have access to this repository. | http://www.ajan.de/ajan-ns#DomainKnowledge |
Service Repository | Service refers to the repository that contains information about external and internal service actions. All initiated agents have access to this repository. | http://www.ajan.de/ajan-ns#ServiceKnowledge |
Other repositories (not AJAN-specific) can be referenced and used via their SPARQL endpoint URL if it follows the SPARQL standards (https://www.w3.org/TR/sparql11-protocol/).
All SPARQL 1.1 query types ASK, SELECT, CONSTRUCT and UPDATE are used in AJAN and described in RDF as follows:
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/query/BehaviorAskQuery.java
Result: boolean
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Ask Query (bt:AskQuery) |
Class (rdfs:subClassOf) | Query (bt:Query) |
Repository (bt:originBase) | URL (e.g. ajan:AgentKnowledge to access the agent KB) |
SPARQL Query (bt:sparql) | <Query string>" ("ASK ..."^^xsd:string)) |
Example ASK Query in Turtle/RDF
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix bt: <http://www.ajan.de/behavior/bt-ns#> .
@prefix ajan: <http://www.ajan.de/ajan-ns#> .
_:query
a bt:AskQuery ;
bt:originBase ajan:AgentKnowledge ;
bt:sparql """
PREFIX somePrefix: <some URI>
ASK
WHERE { ?s ?p ?o } """^^xsd:string .
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/query/BehaviorConstructQuery.java
Result: RDF Graph
Note: To create Named Graphs the predicates ajan:rdfContext
or ajan:rdfUUIDContext
are reserved and can be used in the Construct Graph. The statements with these predicates are automatically deleted and do not appear in the generated graph.
-
<S> ajan:rdfContext <O>
:
-> creates a named graph from the generated graph with the name<O>
, in the form of:
<O> { <O> rdf:type ajan:Context . <> <> <> . }
-
<S> ajan:rdfUUIDContext <O>
-> creates a named graph from the generated graph with the name<O+UUID>
where UUID is a Universally Unique Identifier, in the form of:
<O+UUID> { <O> rdf:type ajan:UUIDContext . <> <> <> . }
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Construct Query (bt:ConstructQuery) |
Class (rdfs:subClassOf) | Query (bt:Query) |
Repository (bt:originBase) | URL (e.g. ajan:AgentKnowledge to access the agent KB) |
SPARQL Query (bt:sparql) | <Query string>" ("CONSTRUCT ..."^^xsd:string)) |
Construct Query Example in Turtle/RDF
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix bt: <http://www.ajan.de/behavior/bt-ns#> .
@prefix ajan: <http://www.ajan.de/ajan-ns#> .
@prefix test: <http://test/> .
:ExampleConstructQuery
a bt:ConstructQuery ;
bt:targetBase ajan:AgentKnowledge ;
bt:sparql """
PREFIX sp: <http://spinrdf.org/sp#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX test: <http://test/>
CONSTRUCT {
test:GoalPart rdf:value ?partValue .
test:GoalTool rdf:value ?toolValue .
test:GoalOperation rdf:value ?operationValue .
test:Graph1 ajan:rdfContext test:Graph .
}
WHERE {
?part sp:varName "part".
?part rdf:value ?partValue .
?tool sp:varName "tool".
?tool rdf:value ?toolValue .
?operation sp:varName "operation".
?operation rdf:value ?operationValue .
}"""^^xsd:string ;
.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ajan: <http://www.ajan.de/ajan-ns#> .
@prefix test: <http://test/> .
test:Graph {
test:Graph rdf:type ajan:Context .
test:GoalPart rdf:value ?partValue .
test:GoalTool rdf:value ?toolValue .
test:GoalOperation rdf:value ?operationValue .
}
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/query/BehaviorSelectQuery.java
Result: Table
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Select Query (bt:SelectQuery) |
Class (rdfs:subClassOf) | Query (bt:Query) |
Repository (bt:originBase) | URL (e.g. ajan:AgentKnowledge to access the agent KB) |
SPARQL Query (bt:sparql) | <Query string>" ("SELECT ..."^^xsd:string)) |
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/query/BehaviorUpdateQuery.java
Result: updated Repository
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Update Query (bt:UpdateQuery) |
Class (rdfs:subClassOf) | Query (bt:Query) |
Repository (bt:originBase) | URL (e.g. ajan:AgentKnowledge to access the agent KB) |
SPARQL Query (bt:sparql) | <Query string>" ("INSERT ..."^^xsd:string)) |