View Javadoc

1   package org.deri.wsmo4j.examples;
2   
3   import java.io.InputStream;
4   import java.io.InputStreamReader;
5   import java.io.StringWriter;
6   import java.io.Writer;
7   import java.util.HashMap;
8   
9   import org.omwg.ontology.Ontology;
10  import org.wsmo.common.TopEntity;
11  import org.wsmo.factory.Factory;
12  import org.wsmo.wsml.Parser;
13  import org.wsmo.wsml.Serializer;
14  
15  /**
16   * This class is meant to be used as example for how to use the OWL Serializer 
17   * from the wsml2reasoner framework.
18   * The Serializer transforms a WSML-DL ontology to OWL DL.
19   * 
20   * !! Dependeny: wsml2reasoner package, including the OWL API, to retrieve from 
21   *    http://dev1.deri.at/wsml2reasoner/
22   * 
23   * !! To use this example, the wsmo4j project java compiler compliance level 
24   *    needs to be on Java 5.0.
25   * 
26   * <pre>
27   * Created on Sep 19, 2006
28   * Committed by $Author: morcen $
29   * $Source$,
30   * </pre>
31   * 
32   * @author nathalie.steinmetz@deri.org
33   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
34   *
35   */
36  public class OWLSerializerExample {
37  
38      private Parser parser;
39      
40      private Ontology ontology;
41      
42  	public OWLSerializerExample() {
43  		parser = Factory.createParser(null);
44  	}
45  	
46  	public static void main(String[] args) throws Exception {
47  		OWLSerializerExample ex = new OWLSerializerExample();
48  		ex.doTestRun();
49  
50  	}
51  	
52  	public void doTestRun() throws Exception {
53  		// read test file and parse it 
54          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
55                  "org/deri/wsmo4j/examples/wsml2owlExample.wsml");
56          // assuming first topentity in file is an ontology  
57          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0]; 
58  		
59  		/* create parameters for the parser */
60          HashMap <String, Object> createParams = new HashMap <String, Object> ();
61          createParams.put(Factory.PROVIDER_CLASS,
62                           "org.wsml.reasoner.serializer.owl.WsmlOwlSerializer");		
63  		Serializer serializer = Factory.createSerializer(createParams);
64  		
65  		/* use serializer */
66  		Writer writer = new StringWriter();
67  		TopEntity[] te = {ontology};
68  		serializer.serialize(te, writer);
69  		System.out.println(writer.toString());
70  	}
71  
72  }
73  /*
74   * $Log$
75   * Revision 1.3  2007/04/02 12:13:22  morcen
76   * Generics support added to wsmo-api, wsmo4j and wsmo-test
77   *
78   * Revision 1.2  2006/09/20 09:13:49  nathaliest
79   * *** empty log message ***
80   *
81   * 
82   */