Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Map ontology requestEngine module



This article presents the requestEngine module used in the second map ontology tutorial.

Overview

The requestEngine module is responsible to:

Specify the module interfaces

The requestEngine module has the following module configuration:
      <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.

Code the request UI

We will create a window to ask the requests:
mapontologyreqGUI
Several queries will be handled:
  • Alerts List: the query to return the list of alerts and their type
  • Waypoint Distance: the query to return the distance of a Waypoint
  • Closest ATT Waypoint: the query to return the name and the distance of the closest ATT Waypoint
The associated buttons will fire a listener interface which is implemented by the module:
      public interface RequestGUIListener {
         public void queryAlertsList();

         public void queryWaypointDistance(String waypointID);

         public void queryClosestATTWaypoint();
      }      

Code the request generation

The module implements the RequestGUIListener interface:
  • The queryAlertsList() method generates the query to return the list of alerts and their type
  • The queryWaypointDistance(String waypointID) method generates the query to return the distance of a Waypoint
  • The queryClosestATTWaypoint() method generates the query to return the name and the distance of the closest ATT Waypoint

Creating the query for the alerts list

The hand-written-query would be[1]
See alerts requests in the first tutorial
:
      SELECT ?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");      

Adding the variables in the query

As you can see there are two variables in the 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");

Implementing the query triple patterns

The 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");    

Finalizing and invoking the query

The full code is:
      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();      
      }

Creating the query for the waypoint distance

The hand-written-query would be (here for the 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");      

Adding the variables in the query

There are two variables again in the 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");

Implementing the query triple patterns

The 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");      

Implementing the geometry query

One unique construct will allow us to generate the part of the query which will compute the distance between the Waypoint and the Aircraft:
      request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true);      

Finalizing and invoking the query

The full code is:
      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();   
      } 

Creating the query for the closest ATT waypoint

The hand-written-query would be:
      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 i
First we will create a request with the ontology schema:
      SparqlRequest request = new SparqlRequest("inav");      

Adding the variables in the query

There are two variables again in the 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");

Implementing the query triple patterns

The 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");      

Implementing the geometry query

One unique construct will allow us to generate the part of the query which will compute the distance between the Waypoint and the Aircraft:
      request.addDistance("wpt", "ac", "distance", ISparqlRequest.DISTANCE_NM, true);      

Limit to the closest result

We will sort the results by ascending distance, and get only the first one, to get the closest:
      request.setLimit(1);
      request.setOrderBy("distance", true);  

Finalizing and invoking the query

The full code is:
      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(); 
      } 

Code the query result notification

Now we will write the code dealing with the object query result:
      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.

Handle the alert list query

First we will print the number of alerts:
      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);
      }

Handle the waypoint distance query

Here we have only one result, for which we will print the values for the 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");         

Handle the closest ATT waypoint query

Here we have only one result, for which we will print the values for the 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");       

Notes

  1. ^ See alerts requests in the first tutorial

See also


Categories: tutorials

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence