<application name="requestEngine"> <deployment> <lib url="RequestEngine.jar" /> </deployment> <modules> <module name="requestEngine"> <implementation path="org.da.request.RequestEngine" > <initEntryPoint method="init" /> <defaultReceiveEntryPoint method="subscribe" /> </implementation> <interfaces> <requestSend service="owlObjectRequest" uri="http://dassault-aviation.com/jena" /> </interfaces> </module> </modules> </application>It will be notified from the
http://dassault-aviation.com/jena:owlObjectRequest
service.
public interface RequestGUIListener { public void queryAlertsList(); public void queryWaypointDistance(String waypointID); public void queryClosestATTWaypoint(); }
RequestGUIListener
interface:queryAlertsList()
method generates the query to return the list of alerts and their typequeryWaypointDistance(String waypointID)
method generates the query to return the distance of a WaypointqueryClosestATTWaypoint()
method generates the query to return the name and the distance of the closest ATT WaypointSELECT ?number ?type WHERE { ?alarm rdf:type inav:Alarm . ?alarm inav:AlarmNumber ?number . ?alarm inav:hasAlarmType ?type . }First we will create a request with the ontology schema:
SparqlRequest request = new SparqlRequest("inav");
SELECT
construct. We must add these variables in the query:request.addSelect("number"); request.addSelect("type");We also have an additional
alarm
variable which is used but not included in the SELECT
:request.addAdditionalVariable("alarm");
alarm
variable is of the Alarm
type: request.addType("alarm", "Alarm");The
alarm
variable has the number
variable as the AlarmNumber
property:request.addPropertyRef("alarm", "AlarmNumber", "number");The
alarm
variable has the type
variable as the hasAlarmType
property:request.addPropertyRef("alarm", "hasAlarmType", "type");
public void queryAlertsList() { SparqlRequest request = new SparqlRequest("inav"); request.addSelect("number"); request.addSelect("type"); request.addAdditionalVariable("alarm"); request.addType("alarm", "Alarm"); request.addPropertyRef("alarm", "AlarmNumber", "number"); request.addPropertyRef("alarm", "hasAlarmType", "type"); objectRequestService.setDataStringValue("reqSchema", "inav"); objectRequestService.setDataStringValue("query", request.toString()); objectRequestService.invoke(); }
WPT6
waypoint):SELECT ?label ?distance WHERE { ?wpt rdf:type inav:Waypoint . ?wpt inav:Label ?label . ?wpt inav:Label "WPT6" . ?ac rdf:type inav:Aircraft . ?ac inav:Label "falcon" . ?wpt inav:hasExactGeometry ?auto_2 . ?auto_2 inav:asWKT ?auto_3 . ?ac inav:hasExactGeometry ?auto_4 . ?auto_4 inav:asWKT ?auto_5 . BIND (geof:distance(?auto_3, ?auto_5, <http://www.opengis.net/def/uom/OGC/1.0/nauticalMile>) as ?distance) }First we will create a request with the ontology schema:
SparqlRequest request = new SparqlRequest("inav");
SELECT
construct. We must add these variables in the query:request.addSelect("label"); request.addSelect("distance");We also have two additional
wpt
and ac
variables which represent respectively the Waypoint and the Aircraft:request.addAdditionalVariable("wpt"); request.addAdditionalVariable("ac");
wpt
variable represents a Waypoint:request.addType("wpt", "Waypoint");We use the Waypoint ID passed as an argument to the method to specify its label. As you can see, we use a
PropertyRef
for the wpt
variable to link to the label
variable, but we also use a PropertyValue
for the same variable to link to our Waypoint ID argument.request.addPropertyRef("wpt", "Label", "label"); request.addPropertyValue("wpt", "Label", waypointID);We must do the same thing for the Aircraft:
request.addType("ac", "Aircraft"); request.addPropertyValue("ac", "Label", "falcon");
request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true);
public void queryWaypointDistance(String waypointID) { SparqlRequest request = new SparqlRequest("inav"); request.addSelect("label"); request.addSelect("distance"); request.addAdditionalVariable("wpt"); request.addAdditionalVariable("ac"); request.addType("wpt", "Waypoint"); request.addPropertyRef("wpt", "Label", "label"); request.addPropertyValue("wpt", "Label", waypointID); request.addType("ac", "Aircraft"); request.addPropertyValue("ac", "Label", "falcon"); request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true); objectRequestService.setDataStringValue("reqSchema", "inav"); objectRequestService.setDataStringValue("query", request.toString()); objectRequestService.invoke(); }
SELECT ?label ?distance WHERE { ?wpt rdf:type inav:Waypoint . ?wpt inav:Label ?label . ?wpt inav:hasWaypointType <http://localhost/INAV#ATT> . ?ac rdf:type inav:Aircraft . ?ac inav:Label "falcon" . ?wpt inav:hasExactGeometry ?auto_2 . ?auto_2 inav:asWKT ?auto_3 . ?ac inav:hasExactGeometry ?auto_4 . ?auto_4 inav:asWKT ?auto_5 . BIND (geof:distance(?auto_3, ?auto_5, <http://www.opengis.net/def/uom/OGC/1.0/nauticalMile>) as ?distance) } ORDER BY ASC( ?distance ) LIMIT 1? ac rdf:type inav:Aircraft . ?ac iFirst we will create a request with the ontology schema:
SparqlRequest request = new SparqlRequest("inav");
SELECT
construct. We must add these variables in the query:request.addSelect("label"); request.addSelect("distance");We also have two additional
wpt
and ac
variables which represent respectively the Waypoint and the Aircraft:request.addAdditionalVariable("wpt"); request.addAdditionalVariable("ac");
wpt
variable represents a Waypoint:request.addType("wpt", "Waypoint");We only look for ATT Waypoint, so we will look for Waypoints which have an
ATT
type:request.addPropertyIndividualRef("wpt", "hasWaypointType", "ATT");We use a
PropertyRef
for the wpt
variable to link to the label
variable:request.addPropertyRef("wpt", "Label", "label");We must do the same thing for the Aircraft:
request.addType("ac", "Aircraft"); request.addPropertyValue("ac", "Label", "falcon");
request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true);
request.setLimit(1); request.setOrderBy("distance", true);
public void queryClosestATTWaypoint() { SparqlRequest request = new SparqlRequest("inav"); request.addSelect("label"); request.addSelect("distance"); request.addAdditionalVariable("wpt"); request.addAdditionalVariable("ac"); request.addType("wpt", "Waypoint"); request.addPropertyIndividualRef("wpt", "hasWaypointType", "ATT"); request.addPropertyRef("wpt", "Label", "label"); request.addType("ac", "Aircraft"); request.addPropertyValue("ac", "Label", "falcon"); request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true); request.setLimit(1); request.setOrderBy("distance", true); objectRequestService.setDataStringValue("reqSchema", "inav"); objectRequestService.setDataStringValue("query", request.toString()); objectRequestService.invoke(); }
public void subscribe(ServiceInstance service) { NamespaceKey JENA_OBJECT_REQUEST = NamespaceKey.createKey("http://dassault-aviation.com/jena", "owlObjectRequest"); NamespaceKey key = service.getKey(); if (key.equals(JENA_OBJECT_REQUEST)) { QueryResults results = (QueryResults) service.getData("response").getValue(); handleObjectResponse(results); } }We will handle the notification depending on the query we sent in the
handleObjectResponse(QueryResults results)
method.
System.out.println("Number of Alerts: " + results.countResults());Each result correspond to an Alert with two values for the
number
and type
variables:QueryResults results = (QueryResults) service.getData("response").getValue(); Iterator<QueryResults.Result> it = results.getOrderedResultsList().iterator(); while (it.hasNext()) { QueryResults.Result result = it.next(); int number = result.getValue("number").getValueAsInt(); String type = result.getValue("type").getValueAsString(); System.out.println("Alarm " + number + ": " + type); }
label
and distance
variables:QueryResults.Result result = results.getOrderedResultsList().iterator().next(); String label = result.getValue("label").getValueAsString(); double distance = result.getValue("distance").getValueAsDouble(); System.out.println("Distance of Waypoint " + label + " at " + distance + " NM");
label
and distance
variables:QueryResults.Result result = results.getOrderedResultsList().iterator().next(); String label = result.getValue("label").getValueAsString(); double distance = result.getValue("distance").getValueAsDouble(); System.out.println("Closest ATT Waypoint is " + label + " at " + distance + " NM");
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence