org.deri.wsmo4j.examples
Class ParsingAndSerializingFile

java.lang.Object
  extended by org.deri.wsmo4j.examples.ParsingAndSerializingFile

public class ParsingAndSerializingFile
extends Object

Parsing and serializing a file

Description: Example - How to parse, create and serialize logical expressions

How to parse logical expressions from a file

A Parser is created using the Factory Pattern (org.wsmo.factory.Factory). In order to use the logical expression extension a LogicalExpressionFactory has to be created and passed as parameter when creating the parser.

If we don't pass specific parameters, the parser is created using wsmo4j default factories. The Logical Expressions factory used by default handles logical expressions as plain strings, instead of objects (variables, molecules, operators,...).

Now we we use the parser to parse the wsml file. As result we obtain an array of TopEntities (Ontologies, Goals, Mediators or Web Services). In our test case we can cast the first TopEntity to an ontology, which can be searched for specified concepts, axioms, instances, namespaces,...

How to create logical expressions

To create logical expressions, one needs to use the LogicalExpressionsFactory. This one allows to build logical expressions in two different ways. Either from a string (ex: ?x memberOf _"http://example.org/animal"), or by building it up directly using different objects like variables, IRIs, molecules, etc. No matter how an expression is created it will be equal.

How to serialize logical expressions

First we need to create a serializer. This one is, analogous to the parser, created by the Factory, with as parameter simply "null". The TopEntity, consisting of the ontology and the ontology items is serialized to a string. This one can be written into a wsml file.

With the toString(), it is also possible to convert a logical expression directly to a string, without using the serializer.

Author:
Nathalie.Steinmetz@deri.org

Field Summary
protected  org.wsmo.factory.WsmoFactory factory
           
protected  org.wsmo.factory.LogicalExpressionFactory leFactory
           
protected  org.omwg.ontology.Ontology ontology
           
protected  org.wsmo.wsml.Parser parser
           
protected  org.wsmo.wsml.Serializer serializer
           
 
Constructor Summary
ParsingAndSerializingFile()
           
 
Method Summary
 void addLogExp()
          A simple axiom is created and added to the ontology.
static void main(String[] args)
           
 void parseFile()
          Read a wsml-file and parse it.
 void serializeToFile()
          The ontology with the added axiom is serialized and written into the file "SerializedLocations.wsml"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected org.wsmo.wsml.Parser parser

serializer

protected org.wsmo.wsml.Serializer serializer

factory

protected org.wsmo.factory.WsmoFactory factory

leFactory

protected org.wsmo.factory.LogicalExpressionFactory leFactory

ontology

protected org.omwg.ontology.Ontology ontology
Constructor Detail

ParsingAndSerializingFile

public ParsingAndSerializingFile()
Method Detail

parseFile

public void parseFile()
Read a wsml-file and parse it. See how many concepts, axioms and instances are in the resulting ontology. Search for a specific axiom and for a specific namespace.


addLogExp

public void addLogExp()
               throws org.wsmo.wsml.ParserException
A simple axiom is created and added to the ontology. The axiom is defined by a binary logical expression. The LogicalExpressionFactory is used to build the axiom.

Throws:
org.wsmo.wsml.ParserException

serializeToFile

public void serializeToFile()
The ontology with the added axiom is serialized and written into the file "SerializedLocations.wsml"


main

public static void main(String[] args)


Copyright © 2004-2008 Ontotext Lab.. All Rights Reserved.