diff options
| author | yzhou <yujiao.zhou@gmail.com> | 2015-04-21 10:34:27 +0100 |
|---|---|---|
| committer | yzhou <yujiao.zhou@gmail.com> | 2015-04-21 10:34:27 +0100 |
| commit | 9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8 (patch) | |
| tree | 47511c0fb89dccff0db4b5990522e04f294d795b /src/org/semanticweb/simpleETL/SimpleETL.java | |
| parent | b1ac207612ee8b045244253fb94b866104bc34f2 (diff) | |
| download | ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip | |
initial version
Diffstat (limited to 'src/org/semanticweb/simpleETL/SimpleETL.java')
| -rw-r--r-- | src/org/semanticweb/simpleETL/SimpleETL.java | 71 |
1 files changed, 71 insertions, 0 deletions
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 @@ | |||
| 1 | package org.semanticweb.simpleETL; | ||
| 2 | import java.io.File; | ||
| 3 | import java.io.FileInputStream; | ||
| 4 | import java.io.FileOutputStream; | ||
| 5 | import java.util.regex.Pattern; | ||
| 6 | |||
| 7 | import org.openrdf.rio.RDFParser; | ||
| 8 | import org.openrdf.rio.RDFWriter; | ||
| 9 | import org.openrdf.rio.rdfxml.RDFXMLParser; | ||
| 10 | import org.openrdf.rio.turtle.TurtleWriter; | ||
| 11 | |||
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 13 | |||
| 14 | public 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 | } | ||
