view src/es/cbgp/galaxy/sparql/jena/OntologyManager.java @ 2:b8bf1af83841 draft

Paste query added, query engine improved, examples added
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Wed, 04 Dec 2013 08:17:00 +0100
parents 137f9a4a6337
children
line wrap: on
line source

package es.cbgp.galaxy.sparql.jena;

import java.io.File;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class OntologyManager {

	private String ontFile;
	private String sparqlFile;
	private Model model;
	private SPARQLQueryEngine sqe;

	public OntologyManager(String of, String sf) throws Exception {
		this.ontFile = of;
		this.sparqlFile = sf;
		init();
	}

	private void init() throws Exception {
		this.model = ModelFactory.createDefaultModel();
		this.model.read(new File(ontFile).toURI().toString());
	}

	public void executeQuery() throws Exception {
		this.sqe = new SPARQLQueryEngine(model);
		this.sqe.setQueryFile(sparqlFile);
		String ret = sqe.executeQuery();
		System.out.println(ret);
	}
}