annotate 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
rev   line source
stevenh@70 1 package org.qmul.eecs.c4dm.sia;
stevenh@70 2
stevenh@70 3 import java.io.File;
stevenh@70 4 import java.io.FileNotFoundException;
stevenh@70 5 import java.io.FileOutputStream;
stevenh@70 6
stevenh@70 7 import org.apache.jena.web.DatasetGraphAccessorHTTP;
stevenh@70 8 import org.mindswap.pellet.jena.PelletReasonerFactory;
stevenh@70 9 import org.qmul.eecs.c4dm.sparql.utilities.SparqlWrapperMethods;
stevenh@70 10
stevenh@70 11 import com.hp.hpl.jena.ontology.OntModel;
stevenh@70 12 import com.hp.hpl.jena.ontology.OntModelSpec;
stevenh@70 13 import com.hp.hpl.jena.query.Dataset;
stevenh@70 14 import com.hp.hpl.jena.query.DatasetAccessor;
stevenh@70 15 import com.hp.hpl.jena.query.DatasetAccessorFactory;
stevenh@70 16 import com.hp.hpl.jena.query.QuerySolution;
stevenh@70 17 import com.hp.hpl.jena.query.ResultSet;
stevenh@70 18 import com.hp.hpl.jena.rdf.model.Model;
stevenh@70 19 import com.hp.hpl.jena.rdf.model.ModelFactory;
stevenh@70 20 import com.hp.hpl.jena.tdb.TDBFactory;
stevenh@70 21 import com.hp.hpl.jena.update.UpdateAction;
stevenh@70 22
stevenh@70 23 /**
stevenh@70 24 * @author stevenh
stevenh@70 25 * Utility class which converts an N3 file to RDF/XML
stevenh@70 26 */
stevenh@70 27 public class N3ToRdf {
stevenh@70 28
stevenh@70 29 // Ontology N3 file
stevenh@70 30 private static final String n3ontology = "file:src/rdf/siaTestDatapointOntology.n3";
stevenh@70 31 // private static final String n3ontology = "file:src/rdf/midiModel.n3";
stevenh@70 32
stevenh@70 33 // The RDF output file
stevenh@70 34 private static final String rdfFileName = "/Volumes/USB_DISK/mercurial/SiaSesame/ontology/siaTestDatapointOntology";
stevenh@70 35
stevenh@70 36 /**
stevenh@70 37 * @param args
stevenh@70 38 */
stevenh@70 39 public static void main(String[] args) {
stevenh@70 40
stevenh@70 41 // Create an ontology model
stevenh@70 42 OntModel ontModel = ModelFactory
stevenh@70 43 .createOntologyModel();
stevenh@70 44
stevenh@70 45 // Read the ontology and data from the file into the ontology model
stevenh@70 46 ontModel.read(n3ontology, "N3");
stevenh@70 47
stevenh@70 48 // Write the model to a file
stevenh@70 49 File outFileRdf = new File(rdfFileName + ".rdf");
stevenh@70 50 FileOutputStream outFileOutputStreamRdf;
stevenh@70 51
stevenh@70 52 // RDF/XML version
stevenh@70 53 try {
stevenh@70 54 outFileOutputStreamRdf = new FileOutputStream(outFileRdf);
stevenh@70 55 ontModel.writeAll(outFileOutputStreamRdf, "RDF/XML", null);
stevenh@70 56 } catch (FileNotFoundException e) {
stevenh@70 57 System.out.println("Unable to write to file: "
stevenh@70 58 + outFileRdf.getAbsolutePath());
stevenh@70 59 e.printStackTrace();
stevenh@70 60 System.exit(1);
stevenh@70 61 }
stevenh@70 62
stevenh@70 63 System.out.println("Model written to file: "
stevenh@70 64 + outFileRdf.getAbsolutePath());
stevenh@70 65
stevenh@70 66 }
stevenh@70 67
stevenh@70 68 }