use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method mapDeprecated.
public Map<String, String> mapDeprecated(Set<String> uris) {
Map<String, String> old_new = new HashMap<String, String>();
BigdataSailRepositoryConnection connection;
try {
connection = go_lego_repo.getReadOnlyConnection();
try {
String q = "VALUES ?c {";
for (String uri : uris) {
if (uri.startsWith("http")) {
q += "<" + uri + "> \n";
}
}
q += "} . ";
String query = "SELECT ?c ?replacement " + "WHERE { " + q + "?c <http://purl.obolibrary.org/obo/IAO_0100001> ?replacement . " + "} ";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value c = binding.getValue("c");
Value replacement = binding.getValue("replacement");
old_new.put(c.stringValue(), replacement.stringValue());
}
} catch (MalformedQueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (QueryEvaluationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
connection.close();
}
} catch (RepositoryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return old_new;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getLabel.
public String getLabel(String entity) throws IOException {
String label = null;
String query = "select ?label where { <" + entity + "> rdfs:label ?label } limit 1";
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
if (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("label");
label = 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 label;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getSuperCategoryMap.
public Map<String, Set<String>> getSuperCategoryMap(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) {
if (uri.startsWith("http")) {
q += "<" + uri + "> ";
}
}
q += "} . ";
String categories = "VALUES ?super {";
for (String c : root_types) {
categories += "<" + c + "> ";
}
categories += "} . ";
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 + categories + "?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