diff src/org/qmul/eecs/c4dm/sia/N3ToRdf.java @ 70:fe08d8cdd150

new
author stevenh
date Fri, 02 Aug 2013 15:01:59 +0100
parents
children ba757f11f4b0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/qmul/eecs/c4dm/sia/N3ToRdf.java	Fri Aug 02 15:01:59 2013 +0100
@@ -0,0 +1,68 @@
+package org.qmul.eecs.c4dm.sia;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+
+import org.apache.jena.web.DatasetGraphAccessorHTTP;
+import org.mindswap.pellet.jena.PelletReasonerFactory;
+import org.qmul.eecs.c4dm.sparql.utilities.SparqlWrapperMethods;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.ontology.OntModelSpec;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetAccessor;
+import com.hp.hpl.jena.query.DatasetAccessorFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import com.hp.hpl.jena.update.UpdateAction;
+
+/**
+ * @author stevenh
+ * Utility class which converts an N3 file to RDF/XML
+ */
+public class N3ToRdf {
+	
+	// Ontology N3 file
+	private static final String n3ontology = "file:src/rdf/siaTestDatapointOntology.n3";
+//	private static final String n3ontology = "file:src/rdf/midiModel.n3";
+
+	// The RDF output file
+	private static final String rdfFileName = "/Volumes/USB_DISK/mercurial/SiaSesame/ontology/siaTestDatapointOntology";
+	
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		
+		// Create an ontology model
+		OntModel ontModel = ModelFactory
+				.createOntologyModel();
+		
+		// Read the ontology and data from the file into the ontology model
+		ontModel.read(n3ontology, "N3");
+		
+		// Write the model to a file
+		File outFileRdf = new File(rdfFileName  + ".rdf");
+		FileOutputStream outFileOutputStreamRdf;
+
+		// RDF/XML version
+		try {
+			outFileOutputStreamRdf = new FileOutputStream(outFileRdf);
+			ontModel.writeAll(outFileOutputStreamRdf, "RDF/XML", null);
+		} catch (FileNotFoundException e) {
+			System.out.println("Unable to write to file: "
+					+ outFileRdf.getAbsolutePath());
+			e.printStackTrace();
+			System.exit(1);
+		}
+
+		System.out.println("Model written to file: "
+				+ outFileRdf.getAbsolutePath());
+
+	}
+
+}