diff options
Diffstat (limited to 'src/main/java/org/semanticweb/simpleETL/SimpleETL.java')
| -rw-r--r-- | src/main/java/org/semanticweb/simpleETL/SimpleETL.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main/java/org/semanticweb/simpleETL/SimpleETL.java b/src/main/java/org/semanticweb/simpleETL/SimpleETL.java new file mode 100644 index 0000000..cc91e1f --- /dev/null +++ b/src/main/java/org/semanticweb/simpleETL/SimpleETL.java | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | package org.semanticweb.simpleETL; | ||
| 2 | |||
| 3 | import org.openrdf.rio.RDFParser; | ||
| 4 | import org.openrdf.rio.RDFWriter; | ||
| 5 | import org.openrdf.rio.rdfxml.RDFXMLParser; | ||
| 6 | import org.openrdf.rio.turtle.TurtleWriter; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 8 | |||
| 9 | import java.io.File; | ||
| 10 | import java.io.FileInputStream; | ||
| 11 | import java.io.FileOutputStream; | ||
| 12 | import java.util.regex.Pattern; | ||
| 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 | FileOutputStream fos = new FileOutputStream(m_fileToExport); | ||
| 46 | try { | ||
| 47 | RDFWriter writer = new TurtleWriter(fos); | ||
| 48 | |||
| 49 | // String m_fileToExport = m_fileToImport.replace(".owl", ".ntriple"); | ||
| 50 | // RDFWriter writer = new NTriplesWriter(new FileOutputStream(m_fileToExport)); | ||
| 51 | |||
| 52 | RDFHandlerWriter multiHandler = new RDFHandlerWriter(writer); | ||
| 53 | parser.setRDFHandler(multiHandler); | ||
| 54 | File fileToImport = new File(m_fileToImport); | ||
| 55 | if(fileToImport.isDirectory()) { | ||
| 56 | for(File file : fileToImport.listFiles()) { | ||
| 57 | if(file.isFile() && (Pattern.matches(".*.owl", file.getName()) || Pattern.matches(".*.rdf", file.getName()))) { | ||
| 58 | Utility.logDebug("Parsing " + file.getName()); | ||
| 59 | parser.parse(new FileInputStream(file), m_prefix); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | else | ||
| 64 | parser.parse(new FileInputStream(fileToImport), m_prefix); | ||
| 65 | writer.endRDF(); | ||
| 66 | } | ||
| 67 | finally { | ||
| 68 | fos.close(); | ||
| 69 | } | ||
| 70 | Utility.logDebug("SimpleETL rewriting DONE: additional ontology data is saved in " + m_fileToExport + "."); | ||
| 71 | } | ||
| 72 | |||
| 73 | public String getExportedFile() { | ||
| 74 | return m_fileToExport; | ||
| 75 | } | ||
| 76 | } | ||
