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

Jena model mapping



This method builds upong the batch update but simplify the correspondance between a Java model and the Ontology.
jenaupdate
An XML file allows to specify the mapping between an ontology and the model. Then a instances or properties creation can be processed as batches on this mapping.

Mappings structure

The schema is: objectsMapping.xsd.

The mappings has the following structure:
  • constants: allows to give names to values used in the other parts of the file
  • classTypes: specifies java classes which can be mapped to an ontology class
  • objects: specifies any elements which can be mapped to an ontology class

Constants

Constants allows to give names to values used in the other parts of the file. For each constant, the specification associates:
  • The name of the constant
  • The value of the constant
  • The type of the constant, which can be int, short, or string
For example:
      <constants>    
         <constant name="TaskZone" value="3" type="short" />  
         <constant name="RefuelZone" value="1" type="short" />   
         <constant name="JTACZone" value="6" type="short" />    
      </constants>

Object


The object elements allows to specify classes in the Owl ontology and their properties. It simplifies adding or updating individuals of these classes in the ontology.

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

It is possible to specify dependencies between objects in the mappings. 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 Jena model mapping dependencies for more information.

Example

      <object name="flightplan" className="FlightPlan" nameSuffix="_flightplan">         
         <dataProperty name="label" property="Label" isName="true"/>    
         <property name="waypoint" eltRef="waypoint"  property="hasWaypoint" inverseProperty="isWaypointFrom" cardinality="unbound" inverseCardinality="one" />  
      </object>       
      
      <object name="waypoint" className="Waypoint" nameSuffix="_waypoint"> 
         <geometry />       
         <dataProperty name="label" property="Label" isName="true"/>     
      </object>
In this example, 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.

The waypoint property models the list of waypoints of the FlightPlan:
  • The waypointproperty corresponds to the hasWaypoint object property in the Owl ontology. It is the inverse of the isWaypointFrom object property on the associated Waypoint element
  • The "unbound" value for the cardinality attribute specifies that there can be any number of the waypoint object properties. The inverse cardinality specifies that there can be only one FlightPlan for one waypoint

ClassTypes

The class elements allows to associated a Java object in the model to an associated object.

Cardinalities

property, dataProperty, and enumProperty elements define respectively for an object:
  • An Owl dataProperty on this object
  • An Owl dataProperty on this object which values correspond to an enumeration
  • An Owl datatypeProperty on this object which values correspond to an enumeration
All these elements can have the cardinality attribute which specifies if there can be more than one of these properties or data properties on the element. The ossible values for this property are:
  • "one" or "1": specifies that there can be only one of this property for the individual
  • "unbound": specifies that there can be only as many of this property for the individual

By default the cardinality value is "one".


For example, suppose that we have the following specification:
      <object name="person" className="Person" nameSuffix="_person">
         <dataProperty name="name" property="Name" isName="true"/>
         <dataProperty name="age" property="Age" cardinality="one"/>          
      </object>
Then with the following code:
      MappedElement personElt = envOp.addElement("person", "John");
      personElt.addDataProperty("age", 23);
      personElt.addDataProperty("age", 30);
There will be only one "Age" data property for the element in the Ontology.

DataProperty element example

      <object name="mission" className="TaskMission" nameSuffix="_mission">  
         <dataProperty name="id" property="MissionCode" isName="true" cardinality="one"/>
         <dataProperty name="alias" property="alias" cardinality="unbound"/>
      </object>
In this example, the "mission" element correspond to the "TaskMission" class. It has two datatype properties:
  • "id" which is the unique name of the mission
  • "alias" which are the alias names of the mission

Property element example

      <object name="JTACZone" className="JTACZone">    
         <dataProperty name="label" property="Label" isName="true" cardinality="one"/>  
         <property name="jtac" eltRef="jtac" property="underResponsabilityOf" inverseProperty="inResponsabilityOfZone"/>     
      </object>
In this example, the "JTACZone" element correspond to the "TaskMission" class. It has one property:
  • "underResponsabilityOf" which refer to a jtac element. This element itself has a "inResponsabilityOfZone" property which refer to this JTACZone

Using the mappings

Creating a mappings using the XML file is performed by the folllowing code:
         ObjectMappings mappings = new ObjectMappings();
      URL url = <the Mappings XML file URL>
      mappings.parse(module, url);    

Creating and using a batch of creations and updates

A batch of Jena operations can be specified using an existing ObjectMappings with the following code:
         ElementsOperations operationsBatch = new ElementsOperations(module, mappings);    
This batch has the following API:

public class org.da.protoframework.jena.common.mappings.ElementsOperations
The ElementsOperations working on a mappings.

Modifier and Type Method and Description
MappedElement addElement(Object element)
Add an element on the ontology using an object. The name of the individual and its class in the ontology will be generated automatically using the element name (and optionally its suffix)
MappedElement addElement(String type, String name)
Add an element on the ontology of a specified type and name

The MappedElement has the following API:

public class org.da.protoframework.jena.common.mappings.ElementsOperations
The ElementsOperations working on a mappings.

Modifier and Type Method and Description
void addDataProperty(String name, Object value)
Add a data property to the element
void addProperty(String name, String elementRef)
Add an object property to the element. The elementRef is the name of the reference element
void addProperty(String name, Object elementRef)
Add an object property to the element. The elementRef is the Java object which will be automatically mapped to the reference name

MappedElement updating options

By default MappedElement will be created if they don't exist. However the API allows to change what you will do with this element:
  • MappedElement.setBookmarked(true) will only use the element as a bookmark for subsequent operations
  • MappedElement.setUpdated(true) will not create the element if it does not already exist
  • MappedElement.setRemoved(true) will remove the element if it already exists

Example

Suppose the following specification:
      <object name="jtac" className="JTAC" nameSuffix="_jtac">
         <dataProperty name="label" property="Label" isName="true"/>
         <dataProperty name="nationality" property="Nationality" />        
         <property name="frequencyPlan" eltRef="frequencyPlan" property="hasFrequencyPlan"/>     
      </object>
If we want to create a JTAC, we can have the following code:
      MappedElement jtacElt = envOp.addElement("jtac", jtacname);
      jtacElt.addDataProperty("label", zoneName);
      jtacElt.addDataProperty("nationality", "French");
      jtacElt.addProperty("frequencyPlan", freqPlanName); 
If we want to remove an existing JTAC, we can have the following code:
      MappedElement jtacElt = envOp.addElement("jtac", jtacname);
      jtacElt.setRemoved(true);

See also


Categories: builtin-applis

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