1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| package com.ontotext.wsmo4j.examples; |
20 |
| |
21 |
| import java.io.*; |
22 |
| import java.util.*; |
23 |
| |
24 |
| import org.omwg.ontology.*; |
25 |
| import org.wsmo.common.*; |
26 |
| import org.wsmo.common.exception.*; |
27 |
| import org.wsmo.factory.*; |
28 |
| import org.wsmo.wsml.*; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| public class LoadOntologyExample { |
40 |
| |
41 |
| private WsmoFactory factory; |
42 |
| |
43 |
| private LogicalExpressionFactory leFactory; |
44 |
| |
45 |
| private DataFactory dataFactory; |
46 |
| |
47 |
| private Parser parser; |
48 |
| |
49 |
| private Serializer serializer; |
50 |
| |
51 |
0
| public static void showExample() throws InvalidModelException {
|
52 |
0
| LoadOntologyExample example = new LoadOntologyExample();
|
53 |
0
| example.createFactoryParserSerializer();
|
54 |
0
| example.serializeParseOntology();
|
55 |
| } |
56 |
| |
57 |
0
| private void createFactoryParserSerializer() {
|
58 |
0
| HashMap <String, Object> props = new HashMap <String, Object>();
|
59 |
| |
60 |
| |
61 |
0
| factory = Factory.createWsmoFactory(null);
|
62 |
0
| leFactory = Factory.createLogicalExpressionFactory(null);
|
63 |
0
| dataFactory = Factory.createDataFactory(null);
|
64 |
| |
65 |
0
| props.put(Factory.WSMO_FACTORY, factory);
|
66 |
0
| props.put(Factory.LE_FACTORY, leFactory);
|
67 |
0
| props.put(Factory.DATA_FACTORY, dataFactory);
|
68 |
| |
69 |
0
| parser = Factory.createParser(props);
|
70 |
0
| serializer = Factory.createSerializer(null);
|
71 |
| } |
72 |
| |
73 |
0
| private void serializeParseOntology() throws InvalidModelException {
|
74 |
| |
75 |
| |
76 |
0
| Ontology ontology = CreateOntologyExample.showExample();
|
77 |
| |
78 |
0
| try {
|
79 |
| |
80 |
0
| StringWriter writer = new StringWriter();
|
81 |
0
| serializer.serialize(new TopEntity[] { ontology }, writer);
|
82 |
0
| System.out.println(writer.getBuffer().toString());
|
83 |
| |
84 |
| |
85 |
0
| TopEntity[] entities = parser.parse(new StringReader(writer.getBuffer().toString()));
|
86 |
0
| if (entities.length != 1) {
|
87 |
0
| throw new RuntimeException("The number of parsed entities is not 1!");
|
88 |
| } |
89 |
| } |
90 |
| catch (IOException ex) { |
91 |
| |
92 |
| } |
93 |
| catch (ParserException ex) { |
94 |
0
| System.out.println("Invalid WSML token encountered at line " + ex.getErrorLine()
|
95 |
| + " position " + ex.getErrorPos()); |
96 |
| } |
97 |
| } |
98 |
| |
99 |
0
| public static void main(String[] args) throws InvalidModelException {
|
100 |
0
| showExample();
|
101 |
| } |
102 |
| } |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |