SPARQL BT Leaf Nodes - aantakli/AJAN-service GitHub Wiki

SPARQL-BT Condition

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Condition.java

States: SUCCEEDED || FAILED

Description: A SBT Condition is a BT leaf node that makes a binary statement about the presence of a graph-pattern in an RDF dataset. It returns two states after execution: SUCCEEDED or FAILED and can be used to formulate state conditions of an agent. Thereby, it performs one SPARQL 1.1 ASK query on a defined RDF dataset. The dataset can be a default graph or a named graph and is represented by its SPARQL endpoint URI. To define a SPARQL ASK query, the complete language space of the SPARQL 1.1 language with regard to ASK operations can be used.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Condition Node (bt:Condition)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Query (bt:query) ASK Query (bt:AskQuery)

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#> .

:CheckHandNeeded # Instance URI
	a bt:Condition;
	rdfs:label "CheckHandNeeded"^^xsd:string ;
	bt:query [
		a bt:AskQuery ;
		bt:originBase ajan:AgentKnowledge ;
		bt:sparql """
			PREFIX test: <http://test/>
			PREFIX mosim: <http://www.dfki.de/mosim-ns#>
			PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
			ASK
			WHERE {
				test:TightenGoalTool rdf:value ?tool .
				?tool mosim:type ?toolName .
				FILTER CONTAINS(STR(?toolName), "Hand" )
		}"""^^xsd:string ;
	] .

SPARQL-BT Update

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Update.java

States: SUCCEEDED || FAILED

Description: This leaf node returns two states after execution: SUCCEEDED or FAILED and can be used to create, delete or update RDF data. Thereby, it performs one SPARQL 1.1 UPDATE query on a defined RDF dataset. The dataset can be a default graph or a named graph and is represented by its SPARQL endpoint URI. To define a SPARQL UPDATE query, the complete language space of the SPARQL 1.1 UPDATE language can be used.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Update Node (bt:Update)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Query (bt:query) UPDATE Query (bt:UpdateQuery)

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#> .

:SetFocus # Instance URI
	a bt:Update ;
	rdfs:label "SetFocus?!"^^xsd:string ;
	bt:query [
		a bt:UpdateQuery ;
		bt:originBase ajan:AgentKnowledge ;
		bt:sparql """
			PREFIX mosim: <http://www.dfki.de/mosim-ns#>

			DELETE { ?running mosim:runningTask ?task . }
			INSERT { ?running mosim:runningTask ?newTask . }
			WHERE {
				?running mosim:runningTask ?task .
				?task mosim:step ?step .
				?newTask a mosim:Task .
				?newTask mosim:step ?newStep .
			
				FILTER (?newStep = ?step+1)
				FILTER (?newTask != ?task)
			}"""^^xsd:string ;
	] .

SPARQL-BT Action

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Action.java

States: SUCCEEDED || RUNNING || FAILED

Description: A SBT Action is a BT leaf node which performs an external service-based or 'internal' plugin-based action. Here, a SPARQL query is used to read the input data (bt:inputs) for the action and then execute it with that input based on its specified action definition (bt:definition). Possible returned action outputs are then stored in the specified target repository (b:targetBase). This node returns three states after execution: SUCCEEDED, RUNNING or FAILED. To define the action input, it performs one SPARQL 1.1 CONSTRUCT query to create a RDF dataset. The dataset can be a default graph or a named graph and is represented by its SPARQL endpoint URI. To define a SPARQL CONSTRUCT query, the complete language space of the SPARQL 1.1 language with regard to CONSTRUCT operations can be used.

When an action is executed, the input dataset and its output dataset, both represented as an RDF graph, are evaluated. This means that before the actual execution of the action and after receiving the action output, it is checked whether the input or output dataset contains all the required information. If one of the listed requirements (which are specified in the selected action definition) does not apply, the action fails, causing the SBT Action Node to return FAILED. This evaluation takes additional time and can be disabled with: 'bt:evaluate' "false"^^xsd:boolean

For more information about AJAN Actions and Action Definitions, please visit: https://github.com/aantakli/AJAN-service/wiki/AJAN-Actions

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Action Node (bt:Action)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Definition (bt:definition) <URI> ("http://..."^^xsd:anyUri)
Action Input (bt:inputs) CONSTRUCT Query (bt:ConstructQuery)
Evaluate (bt:evaluate) <boolean> ("false"^^xsd:boolean)
Target Base (bt:targetBase) <URI> ("http://..."^^xsd:anyUri)

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#> .

:CarryX # Instance URI
	a bt:Action;
	rdfs:label "Carry Action"^^xsd:string ;
	bt:evaluate "true"^^xsd:boolean ;
        bt:definition <http://localhost:8090/rdf4j/repositories/services#CarryInstruction> ;
        bt:targetBase ajan:AgentKnowledge ;
	bt:inputs [
		a bt:ConstructQuery ;
		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#>
			PREFIX test: <http://test/>

			CONSTRUCT {
				?avatar rdf:type mosim:Avatar .
				?avatar mosim:hand ?hand .
				?target rdf:type mosim:MSceneObject .
				?target mosim:id ?id .
				?cosim rdf:type mosim:CoSimulator .
				?cosim mosim:host ?host .
				?cosim mosim:port ?port .
			}
			WHERE {
				?avatar rdf:type mosim:Avatar .
				test:PositionGoalPart rdf:value ?part .
				?part mosim:type ?partName .
				?avatar mosim:hand ?hand .
				?target rdf:type mosim:MSceneObject .
				?target rdfs:label ?partName .
				?target mosim:id ?id .
				?cosim rdf:type mosim:CoSimulator .
				?cosim mosim:host ?host .
				?cosim mosim:port ?port .
			}"""^^xsd:string ;
	] .

SPARQL-BT Write

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Write.java

States: SUCCEEDED || FAILED

Description: This leaf node copies an RDF graph from one (origin base) repository to another (target base). It produces: SUCCEEDED or FAILED, if the copy operation can be stopped by a wrong query or if no connection to a repository can be established. During execution, it performs one SPARQL 1.1 CONSTRUCT query on a defined RDF dataset and stores this dataset in the specified target repository. The current content of the target repository is not taken into account. Data can become inconsistent accordingly. The dataset can be a default graph or a named graph. To define a SPARQL CONSTRUCT query, the complete language space of the SPARQL 1.1 language can be used.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Will wait node (bt:Wait)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Time (bt:query) 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 bt: <http://www.ajan.de/behavior/bt-ns#> .

_:WriteX # Instance URI
	a bt:Write ;
	rdfs:label "some Write"^^xsd:string ;
	bt:query [
		a bt:ConstructQuery ;
		bt:originBase ajan:AgentKnowledge ;
		bt:targetBase <http://localhost:8090/rdf4j/repositories/dummy_knowledge> ;
		bt:sparql """
			CONSTRUCT { ?s ?p ?o . }
			WHERE { ?s ?p ?o . }"""^^xsd:string ;
	] .

SPARQL-BT Evaluate

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Evaluate.java

States: SUCCEEDED || FAILED

Description: This leaf node simulates the further execution of the SPARQL-BT in which this leaf node is executed, from the time of that Evaluate node. For this, a defined RDF dataset ('initialKnowledge') is used to simulate all subsequent SPARQL-BT nodes without affecting the actual KB of the agent or the agent domain. When simulating a SPARQL-BT node, the said dataset is used as OriginBase and this is also used as TargetBase. No events or goals are generated! This node produces: SUCCEEDED or FAILED, due to a wrong query or if no connection to a repository can be established. During the simulation/evaluation, the states of the simulated SPARQL-BT nodes are collected as RDF data and stored as NamedGraph in the specified TargetBase with the context URI specified in the node definition. The execution of the SPARQL-BT after an Evaluate Node was successful is completed as usual. The dataset for the 'initialKnowledge' can be a default graph or a named graph. To define a SPARQL CONSTRUCT query, the complete language space of the SPARQL 1.1 language can be used.

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Evaluate node (bt:Evaluate)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)
Initial Knowledge (bt:initialKnowledge) CONSTRUCT Query (bt:ConstructQuery)
Context (bt:context) <URI> ("http://..."^^xsd:anyUri)
Target Base (bt:targetBase) <URI> ("http://..."^^xsd:anyUri)

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 bt: <http://www.ajan.de/behavior/bt-ns#> .

_:EvaluateX # Instance URI
	a bt:Evaluate ;
	rdfs:label "some Evaluate Node"^^xsd:string ;
	bt:initialKnowledge [
		a bt:ConstructQuery ;
		bt:originBase ajan:AgentKnowledge ;
		bt:targetBase <http://localhost:8090/rdf4j/repositories/dummy_knowledge> ;
		bt:sparql """
			CONSTRUCT { ?s ?p ?o . }
			WHERE { ?s ?p ?o . }"""^^xsd:string ;
	] ;
	bt:context <http://some/context/uri> .
	bt:targetBase <http://localhost:8090/rdf4j/repositories/dummy_knowledge> .

SPARQL-BT Breakpoint

Implementation: https://github.com/aantakli/AJAN-service/blob/master/behaviour/src/main/java/de/dfki/asr/ajan/behaviour/nodes/Breakpoint.java

States: SUCCEEDED

Description: This leaf node represents a breakpoint. With this the execution can be stopped at a defined point in the SPARQL-BT. If this is the case, AJAN listens for the HTTP parameter 'debug' on the endpoint of the BT with executed breakpoint. If the parameter 'debug' is set with 'resume' the execution of the said SPARQL-BT is continued. If the parameter 'debug' is set with 'step', the only next node in the execution order in the BT is executed.

Debug Step example endpoint: http://localhost:8090/rdf4j/repositories/agents#TestAgent/behaviors/TestBehavior?debug=step Debug Resume example endpoint: http://localhost:8090/rdf4j/repositories/agents#TestAgent/behaviors/TestBehavior?debug=resume

Properties

Property (RDF) Value (RDF)
Namespace (@prefix bt:) URL (http://www.ajan.de/behavior/bt-ns#)
Type (rdf:type) Breakpoint node (bt:Breakpoint)
Class (rdfs:subClassOf) Leaf Node (bt:Leaf)
Label (rdfs:label) <string> ("some label"^^xsd:string)

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 bt: <http://www.ajan.de/behavior/bt-ns#> .

_:BreakpointX # Instance URI
	a bt:Breakpoint ;
	rdfs:label "some Breakpoint"^^xsd:string .
⚠️ **GitHub.com Fallback** ⚠️