Fopa Léon Constantin
Fopa Léon Constantin

Reputation: 12373

How to load a n-triple file in virtuoso using Jena API

Jena has the read method that helps loading an ontology from file in the model. Is there something similar for virtuoso using the Jena API?

That will greatly helps me test virtuoso on my already existing ontology store in n-triple format.

Upvotes: 0

Views: 2074

Answers (2)

Sergey Malinin
Sergey Malinin

Reputation: 166

The Jena read method may be used also with Virtuoso Jena provider. Like the next:

try {
  String nfile = "1.nt";
  Model model = VirtModel.openDatabaseModel("load:test", "jdbc:virtuoso://localhost:1111", "dba", "dba");
  InputStream in = FileManager.get().open( nfile );
  if (in == null) {
      throw new IllegalArgumentException( "File: " + nfile + " not found");
  }
  model.read(new InputStreamReader(in), null, "N-TRIPLE");
  model.close();

} catch (Exception e) {
  System.out.println("Ex="+e);
}

Upvotes: 1

Clemens Klein-Robbenhaar
Clemens Klein-Robbenhaar

Reputation: 3527

If you want to read an ontology from a Virtuoso server, you will need the "JDBC"-like drivers for Virtuoso, as explained here: http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtJenaProvider The download is at http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VOSDownload#Jena%20Provider though I preferred to compile it from source -

then you can do something like:

VirtDataset dataSet = new VirtDataset("jdbc:virtuoso://localhost:1111/charset=UTF-8/","user","pass");
Model baseModel = dataSet.getNamedModel("http://my.graph.name/");
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel);

This should allow access to all your RDF-Triples stored in Virtuoso (one graph at a time). If you just want the RDF, leave out the last line with the "OntModel" construction. Same if the store is very large, as it loads the complete ontology into RAM.

Upvotes: 2

Related Questions