aboutsummaryrefslogtreecommitdiff
path: root/src/org/semanticweb/simpleETL
diff options
context:
space:
mode:
authoryzhou <yujiao.zhou@gmail.com>2015-04-21 10:34:27 +0100
committeryzhou <yujiao.zhou@gmail.com>2015-04-21 10:34:27 +0100
commit9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8 (patch)
tree47511c0fb89dccff0db4b5990522e04f294d795b /src/org/semanticweb/simpleETL
parentb1ac207612ee8b045244253fb94b866104bc34f2 (diff)
downloadACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz
ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip
initial version
Diffstat (limited to 'src/org/semanticweb/simpleETL')
-rw-r--r--src/org/semanticweb/simpleETL/RDFHandlerWriter.java45
-rw-r--r--src/org/semanticweb/simpleETL/SimpleETL.java71
2 files changed, 116 insertions, 0 deletions
diff --git a/src/org/semanticweb/simpleETL/RDFHandlerWriter.java b/src/org/semanticweb/simpleETL/RDFHandlerWriter.java
new file mode 100644
index 0000000..e5e2e2a
--- /dev/null
+++ b/src/org/semanticweb/simpleETL/RDFHandlerWriter.java
@@ -0,0 +1,45 @@
1package org.semanticweb.simpleETL;
2import org.openrdf.model.Statement;
3import org.openrdf.rio.RDFHandler;
4import org.openrdf.rio.RDFHandlerException;
5import org.openrdf.rio.RDFWriter;
6
7
8public class RDFHandlerWriter implements RDFHandler {
9 protected RDFWriter m_writer;
10 protected boolean m_started;
11
12 public RDFHandlerWriter(RDFWriter writer){
13 m_writer = writer;
14 m_started = false;
15 }
16
17 @Override
18 public void endRDF() throws RDFHandlerException {
19 // Do not end
20 }
21
22 @Override
23 public void handleComment(String arg0) throws RDFHandlerException {
24 m_writer.handleComment(arg0);
25
26 }
27
28 @Override
29 public void handleNamespace(String arg0, String arg1) throws RDFHandlerException {
30 m_writer.handleNamespace(arg0, arg1);
31 }
32
33 @Override
34 public void handleStatement(Statement arg0) throws RDFHandlerException {
35 m_writer.handleStatement(arg0);
36 }
37
38 @Override
39 public void startRDF() throws RDFHandlerException {
40 if(!m_started) {
41 m_started = true;
42 m_writer.startRDF();
43 }
44 }
45}
diff --git a/src/org/semanticweb/simpleETL/SimpleETL.java b/src/org/semanticweb/simpleETL/SimpleETL.java
new file mode 100644
index 0000000..4d4a193
--- /dev/null
+++ b/src/org/semanticweb/simpleETL/SimpleETL.java
@@ -0,0 +1,71 @@
1package org.semanticweb.simpleETL;
2import java.io.File;
3import java.io.FileInputStream;
4import java.io.FileOutputStream;
5import java.util.regex.Pattern;
6
7import org.openrdf.rio.RDFParser;
8import org.openrdf.rio.RDFWriter;
9import org.openrdf.rio.rdfxml.RDFXMLParser;
10import org.openrdf.rio.turtle.TurtleWriter;
11
12import uk.ac.ox.cs.pagoda.util.Utility;
13
14public class SimpleETL {
15
16 protected final static String m_prefix_LUBM = "http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#";
17 protected final static String m_prefix_UOBM = "http://semantics.crl.ibm.com/univ-bench-dl.owl#";
18 protected final static String m_prefix_FLY= "http://www.virtualflybrain.org/ontologies/individual_neurons/FC_neuron_GF_an.owl#";
19
20 String m_prefix;
21 String m_fileToImport;
22 String m_fileToExport;
23
24 public SimpleETL(String prefix, String fileToImport) {
25 m_prefix = prefix;
26 m_fileToImport = fileToImport;
27 m_fileToExport = m_fileToImport.replace(".owl", ".ttl");
28 }
29
30 public SimpleETL(String prefix, String fileToImport, String outPath) {
31 m_prefix = prefix;
32 m_fileToImport = fileToImport;
33 File file = new File(outPath);
34 if (file.exists() && file.isDirectory())
35 m_fileToExport = outPath + Utility.FILE_SEPARATOR + "data.ttl";
36 else
37 m_fileToExport = outPath;
38// + Utility.FILE_SEPARATOR + m_fileToImport.substring(m_fileToImport.lastIndexOf(Utility.FILE_SEPARATOR), m_fileToImport.lastIndexOf(".")) + ".ttl";
39 }
40
41 public void rewrite() throws Exception {
42// RDFParser parser = new TurtleParser();
43 RDFParser parser = new RDFXMLParser();
44
45 RDFWriter writer = new TurtleWriter(new FileOutputStream(m_fileToExport));
46
47// String m_fileToExport = m_fileToImport.replace(".owl", ".ntriple");
48// RDFWriter writer = new NTriplesWriter(new FileOutputStream(m_fileToExport));
49
50 RDFHandlerWriter multiHandler = new RDFHandlerWriter(writer);
51 parser.setRDFHandler(multiHandler);
52 File fileToImport = new File(m_fileToImport);
53 if(fileToImport.isDirectory()) {
54 for(File file : fileToImport.listFiles()) {
55 if(file.isFile() && (Pattern.matches(".*.owl", file.getName()) || Pattern.matches(".*.rdf", file.getName()))) {
56 Utility.logDebug("Parsing " + file.getName());
57 parser.parse(new FileInputStream(file), m_prefix);
58 }
59 }
60 }
61 else
62 parser.parse(new FileInputStream(fileToImport), m_prefix);
63 writer.endRDF();
64 Utility.logInfo("SimpleETL rewriting DONE",
65 "additional ontology data is saved in " + m_fileToExport + ".");
66 }
67
68 public String getExportedFile() {
69 return m_fileToExport;
70 }
71}