|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.deri.wsmo4j.examples.ParsingAndSerializingFile
public class ParsingAndSerializingFile
Description: Example - How to parse, create and serialize logical expressions
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,...
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.
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.
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 |
---|
protected org.wsmo.wsml.Parser parser
protected org.wsmo.wsml.Serializer serializer
protected org.wsmo.factory.WsmoFactory factory
protected org.wsmo.factory.LogicalExpressionFactory leFactory
protected org.omwg.ontology.Ontology ontology
Constructor Detail |
---|
public ParsingAndSerializingFile()
Method Detail |
---|
public void parseFile()
public void addLogExp() throws org.wsmo.wsml.ParserException
org.wsmo.wsml.ParserException
public void serializeToFile()
public static void main(String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |