Mercurial > hg > semantic-sia
view src/org/qmul/eecs/c4dm/sia/N3ToRdf.java @ 94:fedf516f6a78 tip
test file
author | stevenh |
---|---|
date | Mon, 29 Dec 2014 15:16:22 +0000 |
parents | ba757f11f4b0 |
children |
line wrap: on
line source
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) { N3ToRdf n3ToRdf = new N3ToRdf(); n3ToRdf.run(n3ontology, rdfFileName); } public void run(String n3ontology, String rdfFileName) { // 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()); } }