wiki:AdapterDeveloping
How to create Adapters for your own data sources.

Authors: Leo Sauermann, Shen Jinping,

In brief, you will

  • Write an ontology
  • Write a Mapping
  • Implement the Class
  • Test it
  • Deploy it

Implementing an Adapter

Implement an adapter involves these steps

  1. Make a package to contain your implementation classes
  2. Name your ontology “ontology.rdfs” and copy to the new created package.
  3. Define the ontology mapping. In gnowsis the ontology elements from the RDFS ontology are mapped to Java classes (resource wrappers and property wrappers). This mapping must be explicitly defined with an RDF file mapping.rdf. Information contained in this file together with the ontology will be used as configuration information of an adapter and loaded when the adapter initializes itself.
  4. Create your adapter class as a subclass of class “AdapterImpl”. Define the resource wrappers and property wrappers as inner classes of your adapter class. Table 1 set out the method you must define or overload for each type of the classes.
  5. Test the package

Write an ontology

An ontology defines the vocabularies that represent the classes of the instances and their associated properties that are expected in a hosting application. The vocabularies can be defined using RDF Schema. For more information about RDF Schema see "http://www.w3.org/TR/rdf-primer/#rdfschema".

Name your ontology ontology.rdfs and put it into your java package.

For short: The class of an instance is modeled as an "rdfs:Class" and the its associated property is then modeled as an "rdf:Property". You can specify the "rang" and "doamin" of a property. The "rang" indicats that the values of that property are instances of a designated class, and the "doamin" indicats that the property should(can) apply to a designated class. Both "rdfs:Class" and"rdf:Property" can be a "subClass" or "subProperty" of another, which enables the modeling of inheritance hierarchy.

In gnowsis the ontology elements from the RDFS ontology are mapped to Java classes(resource wrappers and property wrappers). This mappiing must be explicitly defined with an RDF file mapping.rdf. Information contained in this file together with the ontology will be used as configuration information of an adapter and loaded when the adapter initializes itself

Make a package

For a clear management of the source code you should make a new pacakage to store your adapter code,which can be named as org.gnowsis.XXX.adapter where the "XXX" represents the application domain of the your adapter such as "email, mp3, etc.".

copy the ontology

copy the ontology and the mapping created in step 2 into the new created adapter package.

code your adapter

now it's the time to write your adapter code. all adapters do nothing other than extracting the data from a certain application. This commonality is encapsulated in the class "AdapterImpl",which serves as a super class for all type of adapter implementaions. So firstly you define a adapter class inherited from "AdapterImpl".

remeber the ontology you created in step 2? it defines the objects(resources) and the associated properties of a certain application. They sould be mapped to resource wrappers and property wrappers. you define now these wrapper classes according to the mapping definition. it is recommended to define the wrapper classes as inner classes of the adapter, since they will only be used within the adapter implementation.

copy / paste existing adapter and implement these things:

Class Type
subclass of
Must be defined
Must be overloaded
Description
adapter class
(e.g  “MailAdapter”)
AdapterImpl
constructor
getResourceWrapper
getGnowsisUrl
Get the resource wrapper from its uri
Get the uri from the resource
resource wrapper
(e.g  “ResPart”)
PropertyWrapperImpl
constructor
getWrapper
Wrap a resource and return the wrapper
property wrapper
(e.g  “PropFrom”)
ResourceWrapperImpl
constructor
addObject
addSubject
Add the property extracted from the resource as an RDF object
Add the property extracted from the resource as an RDF subject

At the run time the gnowsis framework will firstly check the ontology and its mapping, locate the corresponding resource wrappers and property wrappers, call the overloaded methods to extract the meta-information from the resource for each property and finally build a jena graph. For more implementation detail refer to the source code.

Performance Optimizing

Last section we demonstrated how to implement a standard adapter. This approach works properly for most local resource adapter (e.g. file adapter, outlook adapter). Whereas to an adapter that has many resource/property wrappers and accesses the network to extract meta-information, the standard approach is quite inefficient. Because it always switches from a property to another, for each property it must re-access the network. The performance is therefore unacceptable. We keep the standard styled implementation just to demonstrate how to implement a general adapter.

The base idea to improve the performance is that we keep the time consuming network access as few as possible. We extract the data for all properties within a single network access, and then directly create the jena graph. The new mail adapter is name “CBDMailAdapter”. The core of this adapter is the method “createCBD”. This method accepts an uri as input parameter, which uniquely represents the to be accessed resource. It access the specified resource extract all the property information, and then creates the jena graph. It is simple and quickly. The complicated ontology mapping is totally aborted.

Test

contents

Last modified 12 years ago Last modified on 12/08/05 11:42:51