1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package examples;
19
20 import java.io.File;
21 import java.io.FileReader;
22 import java.io.FileWriter;
23 import java.io.IOException;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.wsmo.common.TopEntity;
28 import org.wsmo.wsml.Serializer;
29
30 import com.ontotext.ordi.wsmo4rdf.WSMLTripleSerializer;
31
32 /**
33 * This class parses a user specified WSML file and save it in WSMLRDF format!
34 */
35 class ExportToWSMLRDF {
36 public static void main(String[] args) {
37
38
39 if (args.length == 0) {
40 System.out
41 .println("Specify WSML file to be transformed to WSMLRDF!");
42 System.exit(1);
43 }
44 File file = new File(args[0]);
45 if (file.exists() == false) {
46 System.out.println(String.format(
47 "The specified file name %s does not exist!", args[0]));
48 System.exit(1);
49 }
50
51
52 Map<String, Object> map = new HashMap<String, Object>();
53 map.put(org.wsmo.factory.Factory.PROVIDER_CLASS,
54 "org.deri.wsmo4j.io.parser.wsml.ParserImpl");
55 org.wsmo.wsml.Parser wsmlParser = org.wsmo.factory.Factory
56 .createParser(map);
57 TopEntity[] topEntities = null;
58 try {
59 topEntities = wsmlParser.parse(new FileReader(file));
60 } catch (Exception e) {
61 throw new RuntimeException("Could not parse the input file!", e);
62 }
63
64
65 File outputFile = null;
66 FileWriter writer = null;
67 try {
68 outputFile = new File(file.getAbsolutePath() + ".rdfxml");
69 writer = new FileWriter(outputFile);
70 } catch (IOException e) {
71 throw new RuntimeException("Could not create the output file!", e);
72 }
73
74
75 Map<String, Object> createParams = new HashMap<String, Object>();
76 createParams.put(org.wsmo.factory.Factory.PROVIDER_CLASS,
77 WSMLTripleSerializer.class.getName());
78 Serializer rdfparser = org.wsmo.factory.Factory
79 .createSerializer(createParams);
80
81
82 try {
83 rdfparser.serialize(topEntities, writer);
84 } catch (IOException e) {
85 throw new RuntimeException("Error while generating the WSMLRDF!", e);
86 }
87 System.out.println(String.format("Output has beed saved in %s!",
88 outputFile.getAbsolutePath()));
89 }
90 }