SPARQL BT Events - aantakli/AJAN-service GitHub Wiki
SBTs are executed via events. Such an event can be created either by agent endpoints or by a SBT itself. Such an event contains RDF information that an executed behavior can use for decision making.
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/event/EventProducer.java
States: SUCCEEDED || FAILED
Description: A SBT Event Producer leaf node creates predefined events with RDF content. To create such content (bt:content) a SPARQL 1.1 CONSTRUCT query is used. The resulting graph is stored in the instantiated event. The complete SPARQL 1.1 language space with regard to CONSTRUCT operations can be used for this purpose. A SBT Event Producer node returns two states after execution: SUCCEEDED, if the specified event type is present and the query is valid; and FAILED, if the specified event type is not present or the query is invalid.
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Event Producer Node (bt:EventProducer) |
Class (rdfs:subClassOf) | Leaf Node (bt:Leaf) |
Label (rdfs:label) | <string> ("some label"^^xsd:string) |
Event (ajan:event) | URI of a predefiend AJAN Event (URI of rdf:type ajan:Event) |
Content (bt:content) | Construct Query (bt:ConstructQuery) |
Example in Turtle/RDF (comments strat with: #)
@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/> .
:SomeEventProducer
a bt:EventProducer;
rdfs:label "SomeEventProducer" ;
bt:event agents:ExampleEvent ;
bt:content [
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 .
}
WHERE {
?part sp:varName "part".
?part rdf:value ?partValue .
}
}"""^^xsd:string ;
] .
Result Example in TriG/RDF (Graph will be stored as displayed into the instantiated event)
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix test: <http://test/> .
{
test:GoalPart rdf:value ?partValue .
}
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/event/GoalProducer.java
States: SUCCEEDED || RUNNING || FAILED
Description: A SBT Goal Producer leaf node initiates a predefined event goal (with the keyword ajan:goal
) with RDF content. To create such content a SPARQL 1.1 SELECT query is used. The resulting binding set have to match (with names and data types) to the defined variableset in the goal definition (see AJAN Goal chapter in Agent Template). The complete SPARQL 1.1 language space with regard to SELECT operations can be used for this purpose. A SBT Goal Producer node returns three states after execution: RUNNING, if the specified goal type is present, the query result is valid in regard to the goal specification and the triggered SBT is in RUNNING state; SUCCEEDED, if the triggered and already finished SBT produced a agent state which fits to the goal postcondition definition; and FAILED, if the specified goal type is not present or the query result is invalid in regard to the goal specification or the triggered and already finished SBT produced a agent state which doesn't fit to the goal postcondition definition.
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Goal Producer Node (bt:GoalProducer) |
Class (rdfs:subClassOf) | Leaf Node (bt:Leaf) |
Label (rdfs:label) | <string> ("some label"^^xsd:string) |
Goal (ajan:goal) | URI of a predefiend AJAN Goal (URI of rdf:type ajan:Goal) |
Bindings (ajan:bindings) | URI of a predefiend AJAN Bindings (URI of rdf:type ajan:Bindings) |
Note: Bindings are a set of bound variables with a given data type. Which variables must be bound is defined in the selected (ajan:goal
) AJAN Goal definition. With a SPARQL SELECT query, the BindingSet defined in it must therefore match to the variable names and data types of that AJAN Goal definition. The resulting AJAN Goal event content is a named graph (graph name is the URI of the instantiated AJAN Goal), with statements consisting of the goal variable name (sp:varName
) and the corresponding value (rdf:value
).
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | AJAN Bindings (ajan:Bindings) |
Label (rdfs:label) | <string> ("some label"^^xsd:string) |
Query (ajan:bindingQuery) | Select Query (URI of rdf:type bt:SelectQuery) |
Example in Turtle/RDF (comments strat with: #)
@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/> .
:ProducePositionGoal
a bt:GoalProducer ;
rdfs:label "ProducePositionGoal" ;
ajan:goal agents:PositionGoal ;
ajan:bindings [
a ajan:Bindings ;
ajan:bindingQuery [
a bt:SelectQuery ;
bt:originBase ajan:AgentKnowledge ;
bt:sparql """
PREFIX mosim: <http://www.dfki.de/mosim-ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?part ?tool ?operation
WHERE {
?focus mosim:runningTask ?task .
?task rdf:type mosim:Task .
?task mosim:part ?part .
?task mosim:tool ?tool .
?task mosim:operation ?operation .
} LIMIT 1"""^^xsd:string ;
]
] .
Result Example in TriG/RDF (Graph will be stored as displayed into the instantiated goal)
PREFIX sp: <http://spinrdf.org/sp#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX agents: <http://localhost:8090/rdf4j/repositories/agents#>
{
?part sp:varName "part".
?part rdf:value ?partValue .
?tool sp:varName "tool".
?tool rdf:value ?toolValue .
?operation sp:varName "operation".
?operation rdf:value ?operationValue .
}
Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/event/HandleModelEvent.java
States: SUCCEEDED || FAILED
Description: A SBT Event Handler leaf node has access to incoming RDF based event information of the SBT in which the Event Handler is executed. To query such information a SPARQL 1.1 CONSTRUCT query is used. The complete SPARQL 1.1 language space with regard to CONSTRUCT operations can be used for this purpose. To read out information from a specific event, the predicate IRI bt:event
points to that event (see agent template definition). A SBT Event Handler node returns two states after execution: SUCCEEDED, if the CONSTRUCT query created a RDF graph with at least one statement; and FAILED, if the CONSTRUCT query created an empty RDF graph. If no query is defined the incoming Event dataset is stored as is. The resulting RDF graph is then stored in the specified knowledge base. To store the resulting RDF graph as a Named Graph, two reserved predicates can be used in the resulting Construct Graph: ajan:rdfContext
and ajan:rdfUUIDContext
(see Queries).
Property (RDF) | Value (RDF) |
---|---|
Namespace (@prefix bt:) | URL (http://www.ajan.de/behavior/bt-ns#) |
Type (rdf:type) | Handle Event Node (bt:HandleEvent) |
Class (rdfs:subClassOf) | Leaf Node (bt:Leaf) |
Label (rdfs:label) | <string> ("some label"^^xsd:string) |
Event (bt:event) | URL (URL to point to the event which has to be handeled) |
Validate Query (bt:validate) | Construct Query (URI of rdf:type bt:ConstructQuery with target base for storing) |
Example in Turtle/RDF (comments strat with: #)
@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/> .
:HandleCheckGoal
a bt:HandleEvent;
rdfs:label "HandleCheckGoal" ;
bt:event <http://localhost:8090/rdf4j/repositories/agents#CheckGoal> ;
bt:validate [
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 ;
] .
Result Example in TriG/RDF (Graph will be stored as displayed into the defined bt:targetBase)
@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 .
}