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

Jena tutorial



In this tutorial, we will use the Jena application on a test Owl Schema. We will use the pizza schema which defines an Ontology of pizzas, which is often used to teach Owl.

Architecture

In this tutorial, we will specify an architecture with two modules:
jenatutorial
The configuration of the applications will be:
      <applications>
         <application name="jena">
            <deployment>
               <lib url="JenaModule.jar" />
            </deployment>
         </application>
         <application name="userInputs">
            <deployment>
               <lib url="userInputs.jar" />
            </deployment>
            <modules>
               <module name="userInputs">
                  <interfaces>
                     <requestSend service="owlRequest" timeOut="200ms" />
                  </interfaces>
               </module>
            </modules>
         </application>
      </applications>
We will specify the pizza schema for the Jena module properties:
      <properties>
         <application name="jena">
            <module name="jena" >
               <moduleArrayGroupProperty key="schemas">
                  <moduleArrayValue>
                     <moduleProperty key="name" value="pizza" />
                     <moduleProperty key="owlData" value="pizza.owl.rdf" />
                     <moduleProperty key="prefixNS" value="pizza:" />
                     <moduleProperty key="owlNS" value="http://www.co-ode.org/ontologies/pizza/pizza.owl#" />
                  </moduleArrayValue>
               </moduleArrayGroupProperty>
            </module>
         </application>
      </properties>
The pizza.owl.rdf file will contain the pizza Owl Schema.

We have only one service:
      <services>
         <requestResponse name="owlRequest" id="30" >
            <request>
               <data name="reqSchema" desc="Schema key" type="string" />
               <data name="query" desc="JENA query" type="string" />
               <data name="responseType" desc="Response Type" type="responseType" />
            </request>
            <response>
               <data name="respSchema" desc="Schema key" type="string" />
               <data name="response" desc="JENA query response" type="string" />
               <data name="xmlResponse" desc="JENA XML query response" type="xml" />
               <data name="requestStatus" desc="Request status" type="requestStatus" />
            </response>
         </requestResponse>
      </services>
And a very simple types definition:
      <types>
         <simpleType name="string" baseType="string" />
         <xmlType name="xml" />
         <enumType name="requestStatus" >
            <enumValue name="VALID" />
            <enumValue name="INVALID" />
            <enumValue name="NO_SCHEMA" />
         </enumType>
         <enumType name="responseType" >
           <enumValue name="FORMATTED" />
           <enumValue name="XML" />
         </enumType>
      </types>
Now we have our configuration: We will have the following filelist.xml file:
      <files>
         <file url="applications.xml" />
         <file url="services.xml" />
         <file url="types.xml" />
         <file url="properties.xml" />
      </files>

Starting the framework

To start the framework, we must start the framework with our filelist.xml file for our configuration[1]
We can also forget the config argument and specify the filelist after the start
:
      java -jar protoframework.jar config=filelist.xml
One Window for the userInputs application will appear:
jenaTutoUserInputs

Sending a Request

We will now send a request for the "pizza" Ontology. We need to specify:
  • reqSchema: The Ontology Schema key: pizza
  • query: The query
  • responseType: The type of response

Setting the Schema key

Directly type the text "pizza" in the reqSchema field:
jenatutoFieldKey

Setting the query

Click on the button on the query field to edit the query. The text should be for our example:
      select ?pizza where {?pizza a owl:Class ;
        rdfs:subClassOf ?restriction.
        ?restriction owl:onProperty pizza:hasTopping ;
        owl:someValuesFrom pizza:PeperoniSausageTopping
      }
We will look for pizzas which have a PeperoniSausageTopping.

Invoking the owlRequest Service

Now click on the "Invoke" button to send the request. We will see a Service owlRequest notified message wich indicates that we received a response:
jenatutoInvoked
If we click on the hyperlink, we will go to the content of the returned response for the Service:
jenatutoResponse
We can see that:
  • The "requestStatus" field is "VALID", which means that the request was valid
  • The "schemaKey" field is "pizza", as it was the key we used for the request
The response field contains the response from Jena:
      ------------------------------------------------------------------
      | pizza                                                          |
      ==================================================================
      | <http://www.co-ode.org/ontologies/pizza/pizza.owl#AmericanHot> |
      | <http://www.co-ode.org/ontologies/pizza/pizza.owl#FourSeasons> |
      | <http://www.co-ode.org/ontologies/pizza/pizza.owl#American>    |
      ------------------------------------------------------------------
We can see here that the response if formatted as text, and clearly not usable in another module. For the next request, we will ask to format the request as XML.

Sending another Request

Setting the response type to XML

We will not changed anything, except the type of the response, to XML:
jenatutoTypeKey

Invoking the owlRequest Service

Click again on the "Invoke" button to send the request. We will see another Service owlRequest notified message.

Again we can see that:
  • The "requestStatus" field is "VALID", which means that the request was valid
  • The "schemaKey" field is "pizza", as it was the key we used for the request
The xmlResponse field contains the response from Jena, formatted as XML:
      <sparql xmlns="http://www.w3.org/2005/sparql-results#">
         <head>
            <variable name="pizza"/>
         </head>
         <results>
            <result>
               <binding name="pizza">
                  <uri>http://www.co-ode.org/ontologies/pizza/pizza.owl#AmericanHot</uri>
               </binding>
            </result>
            <result>
               <binding name="pizza">
                  <uri>http://www.co-ode.org/ontologies/pizza/pizza.owl#FourSeasons</uri>
               </binding>
            </result>
            <result>
               <binding name="pizza">
                  <uri>http://www.co-ode.org/ontologies/pizza/pizza.owl#American</uri>
               </binding>
            </result>
         </results>
      </sparql>

Notes

  1. ^ We can also forget the config argument and specify the filelist after the start

See also


Categories: builtin-applis | tutorials

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