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

Jena model mapping object elements



The object elements in the Jena model mapping allows to specify classes in the Owl ontology and their properties, and simplify filling the ontology.

Overview

Each object represents a class in the ontology and has the following attributes in the XML file:
  • name: The name which will be used to represent an individual of this class
  • className: The name of the associated class in the Ontology
  • nameSuffix: If this attribute is present, it will automatically add the associated suffix to the name of the element in the ontology
For example with the following declaration:
          <object name="flightplan" className="FlightPlan" nameSuffix="_flightplan">         
         <dataProperty name="label" property="Label" isName="true"/>    
         <property name="waypoint" eltRef="waypoint"  property="hasWaypoint" />  
      </object>
Individuals of the FlightPlan class can be created with the following code:
      MappedElement fp = envOp.addElement("flightplan", eltName);
The nameSuffix attribute ensures that the name of the individual will use the suffix. For example, if you have:
      MappedElement fp = envOp.addElement("flightplan", "FP1");
The individual will have the name FP1_flightplan.

Fill the ontology using Java objects

It is possible to associate a class in the ontology with a Java class. The syntax to specify this is the class element in the mappings file.

The nameMethod attribute specifies which method will be used to get the name of the instance.

For example, the following mappings specification associates the org.my.Waypoint Java class to the Waypoint class in the Ontology:
      <objectsMappings>
         <classTypes>                           
            <class path="org.my.Waypoint" nameMethod="getName">
               <type object="waypoint" />        
            </class>                          
         </classTypes>         
         <object name="waypoint" className="Waypoint">  
            <geometry />          
            <dataProperty name="label" property="Label" isName="true"/>
            <property name="hasWaypointType" eltRef="WaypointType"  property="hasWaypointType" cardinality="one" />          
         </object>                
      </objectsMappings>
The following code will allow to add a Waypoint to the Ontology:
      public class MyModule {
         private ElementsOperations wptOp = null;
      
         public void init(Module module) {
           ObjectMappings mappings = new ObjectMappings();
           URL url = <the Mappings XML file URL>
           mappings.parse(module, url);    
           wptOp = new ElementsOperations(module, mappings);  
         }
      
         public void subscribe(ServiceInstance<?, ?> service) {
            Waypoint waypoint = service.getData("waypoint");
            MappedElement elt = wptOp.addElement(waypoint);
            float latitude = waypoint.getLatitude();
            float longitude = waypoint.getLongitude();
            elt.setPosition(latitude, longitude);
            elt.addProperty("hasWaypointType", "NAV");       
         }
      }     

Associate a Java object with different Ontology classes

It is possible to associate a Java object to different Ontology Classes depending on a condition, using the selector syntax.

For example the following mappings specification allows to associate a org.my.Zone Java instance to a TaskZone or RefuelZone Ontology class depending on the return value of the getName() method:
      <objectsMappings>
         <constants>    
            <constant name="Task" value="1" type="short" />  
            <constant name="Refuel" value="2" type="short" />     
         </constants>   
         <classTypes>     
            <class path="org.my.Zone" nameMethod="getName">
               <selector method="getNature">
                  <type value="Task" object="TaskZone" />
                  <type value="Refuel" object="RefuelZone" />            
               </selector>
            </class>  
         </classTypes>
         <object name="TaskZone" className="TaskZone">
            <geometry />       
            <dataProperty name="label" property="Label" isName="true"/>       
         </object>
         <object name="RefuelZone" className="RefuelZone">
            <geometry />       
            <dataProperty name="label" property="Label" isName="true"/> 
         </object> 
      </objectsMappings>
The following code will allow to add a Zone to the Ontology:
      public class MyModule {
         private ElementsOperations wptOp = null;
      
         public void init(Module module) {
           ObjectMappings mappings = new ObjectMappings();
           URL url = <the Mappings XML file URL>
           mappings.parse(module, url);    
           wptOp = new ElementsOperations(module, mappings);  
         }
      
         public void subscribe(ServiceInstance<?, ?> service) {
            Waypoint waypoint = service.getData("zone");
            MappedElement elt = wptOp.addElement(zone);
            float latitude = waypoint.getLatitude();
            float longitude = waypoint.getLongitude();
            elt.setPosition(latitude, longitude);    
         }
      }     

Jena model mapping dependencies


It is possible to specify dependencies between objects in the mappings. It will allow to be sure that if you have to declare object properties between Classes in the Ontology, both the instances exist.

For example, suppose that you receive Waypoints through a Service, and a Flightplan referencing these Waypoints through another service. You need to be sure that the Waypoints have been added in the Ontology when you add the Flightplan. In the general case you will need to perform this at your module level, but the mappings specification allow you to do this automatically.

See also


Categories: builtin-applis

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