use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method exists.
public boolean exists(String entity) throws IOException {
boolean exists = false;
String query = "select * " + "WHERE {" + "{<" + entity + "> ?p ?o . } " + "UNION " + "{?s ?p <" + entity + "> . }" + "} limit 1";
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
if (result.hasNext()) {
exists = true;
return exists;
}
} catch (MalformedQueryException e) {
throw new IOException(e);
} catch (QueryEvaluationException e) {
throw new IOException(e);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
return exists;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method loadRepositoryFromOntology.
public void loadRepositoryFromOntology(OWLOntology ontology, String iri, boolean reset) throws OWLOntologyCreationException, RepositoryException, IOException, RDFParseException, RDFHandlerException {
synchronized (go_lego_repo) {
final BigdataSailRepositoryConnection connection = go_lego_repo.getUnisolatedConnection();
try {
connection.begin();
try {
URI graph = new URIImpl(iri);
if (reset) {
connection.clear(graph);
}
StatementCollector collector = new StatementCollector();
RioRenderer renderer = new RioRenderer(ontology, collector, null);
renderer.render();
connection.add(collector.getStatements(), graph);
connection.commit();
} catch (Exception e) {
connection.rollback();
throw e;
}
} finally {
connection.close();
}
}
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getClassDepth.
public int getClassDepth(String term, String root_term) throws IOException {
int depth = -1;
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "SELECT ?class (count(?mid) as ?depth) " + "WHERE { " + "values ?class {<" + term + ">} . " + "?class rdfs:subClassOf* ?mid . " + " ?mid rdfs:subClassOf* <" + root_term + "> ." + "filter ( ?class != ?mid )}" + "group by ?class " + " order by ?depth";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("depth");
depth = Integer.parseInt(v.stringValue());
}
} catch (MalformedQueryException e) {
throw new IOException(e);
} catch (QueryEvaluationException e) {
throw new IOException(e);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
return depth;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getAllSuperClasses.
public Set<String> getAllSuperClasses(String uri) throws IOException {
Set<String> supers = new HashSet<String>();
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "SELECT ?super " + "WHERE { " + "<" + uri + "> rdfs:subClassOf* ?super . " + "} ";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("super");
// ignore anonymous super classes
if (v instanceof URI) {
String superclass = binding.getValue("super").stringValue();
supers.add(superclass);
}
}
} catch (MalformedQueryException e) {
throw new IOException(e);
} catch (QueryEvaluationException e) {
throw new IOException(e);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
return supers;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getSuperClassMap.
public Map<String, Set<String>> getSuperClassMap(Set<String> uris) throws IOException {
Map<String, Set<String>> sub_supers = new HashMap<String, Set<String>>();
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
String q = "VALUES ?sub {";
for (String uri : uris) {
q += "<" + uri + "> ";
}
q += "} . ";
String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "SELECT ?sub ?super " + "WHERE { " + q + "?sub rdfs:subClassOf* ?super . " + "} ";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value parent = binding.getValue("super");
Value child = binding.getValue("sub");
// ignore anonymous super classes
if (parent instanceof URI && child instanceof URI) {
String superclass = binding.getValue("super").stringValue();
String subclass = binding.getValue("sub").stringValue();
Set<String> supers = sub_supers.get(subclass);
if (supers == null) {
supers = new HashSet<String>();
}
supers.add(superclass);
sub_supers.put(subclass, supers);
}
}
} catch (MalformedQueryException e) {
throw new IOException(e);
} catch (QueryEvaluationException e) {
throw new IOException(e);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
return sub_supers;
}
Aggregations