use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getAllSubClasses.
public Set<String> getAllSubClasses(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 ?sub " + "WHERE { " + "?sub rdfs:subClassOf* <" + uri + "> . " + "} ";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("sub");
// ignore anonymous sub classes
if (v instanceof URI) {
String superclass = binding.getValue("sub").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 getTaxaByGenes.
public Set<String> getTaxaByGenes(Set<String> genes) throws IOException {
String expansion = "VALUES ?gene { ";
for (String gene : genes) {
expansion += "<" + gene + "> \n";
}
expansion += " } . \n";
Set<String> taxa = new HashSet<String>();
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
String query = "select distinct ?taxon \n" + "where { \n" + expansion + " ?gene rdfs:subClassOf ?taxon_restriction .\n" + " ?taxon_restriction owl:onProperty <http://purl.obolibrary.org/obo/RO_0002162> .\n" + " ?taxon_restriction owl:someValuesFrom ?taxon \n" + "\n" + "}";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("taxon");
// ignore anonymous sub classes
if (v instanceof URI) {
String taxon = binding.getValue("taxon").stringValue();
taxa.add(taxon);
}
}
} 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 taxa;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class BlazegraphOntologyManager method getAllTaxaWithGenes.
public Set<String> getAllTaxaWithGenes() throws IOException {
Set<String> taxa = new HashSet<String>();
try {
BigdataSailRepositoryConnection connection = go_lego_repo.getReadOnlyConnection();
try {
String query = "select distinct ?taxon \n" + "where { \n" + " ?gene rdfs:subClassOf ?taxon_restriction .\n" + " ?taxon_restriction owl:onProperty <http://purl.obolibrary.org/obo/RO_0002162> .\n" + " ?taxon_restriction owl:someValuesFrom ?taxon \n" + "\n" + "}";
TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
Value v = binding.getValue("taxon");
// ignore anonymous sub classes
if (v instanceof URI) {
String taxon = binding.getValue("taxon").stringValue();
taxa.add(taxon);
}
}
} 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 taxa;
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class CommandLineInterface method sparqlUpdate.
/**
* Updates the journal with the provided update sparql statement.
* cli parameter --sparql-update
*
* @param journalFilePath
* @param updateFile
* @throws OWLOntologyCreationException
* @throws IOException
* @throws RepositoryException
* @throws MalformedQueryException
* @throws UpdateExecutionException
*/
public static void sparqlUpdate(String journalFilePath, String updateFile) throws OWLOntologyCreationException, IOException, RepositoryException, MalformedQueryException, UpdateExecutionException {
// minimal inputs
if (journalFilePath == null) {
System.err.println("No journal file was configured.");
System.exit(-1);
return;
}
if (updateFile == null) {
System.err.println("No update file was configured.");
System.exit(-1);
return;
}
String update = FileUtils.readFileToString(new File(updateFile), StandardCharsets.UTF_8);
Properties properties = new Properties();
properties.load(CommandLineInterface.class.getResourceAsStream("/org/geneontology/minerva/blazegraph.properties"));
properties.setProperty(com.bigdata.journal.Options.FILE, journalFilePath);
BigdataSail sail = new BigdataSail(properties);
BigdataSailRepository repository = new BigdataSailRepository(sail);
repository.initialize();
BigdataSailRepositoryConnection conn = repository.getUnisolatedConnection();
BlazegraphMutationCounter counter = new BlazegraphMutationCounter();
conn.addChangeLog(counter);
conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();
int changes = counter.mutationCount();
conn.removeChangeLog(counter);
System.out.println("\nApplied " + changes + " changes");
conn.close();
}
use of com.bigdata.rdf.sail.BigdataSailRepositoryConnection in project minerva by geneontology.
the class ReplaceObsoleteReferencesCommand method applySPARQLUpdate.
private static void applySPARQLUpdate(BigdataSailRepository repository, String update, Optional<IChangeLog> changeLog) throws RepositoryException, UpdateExecutionException, MalformedQueryException {
BigdataSailRepositoryConnection connection = repository.getUnisolatedConnection();
changeLog.ifPresent(connection::addChangeLog);
try {
connection.begin();
try {
connection.prepareUpdate(QueryLanguage.SPARQL, update).execute();
} catch (UpdateExecutionException | RepositoryException | MalformedQueryException e) {
connection.rollback();
throw e;
}
} finally {
connection.close();
}
changeLog.ifPresent(connection::removeChangeLog);
}
Aggregations