Search in sources :

Example 26 with BigdataSailRepositoryConnection

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;
}
Also used : BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) Value(org.openrdf.model.Value) RepositoryException(org.openrdf.repository.RepositoryException)

Example 27 with BigdataSailRepositoryConnection

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;
}
Also used : BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) Value(org.openrdf.model.Value) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException)

Example 28 with BigdataSailRepositoryConnection

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;
}
Also used : RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException) URI(org.openrdf.model.URI) BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) Value(org.openrdf.model.Value)

Aggregations

BigdataSailRepositoryConnection (com.bigdata.rdf.sail.BigdataSailRepositoryConnection)28 RepositoryException (org.openrdf.repository.RepositoryException)25 IOException (java.io.IOException)15 Value (org.openrdf.model.Value)12 URI (org.openrdf.model.URI)9 URIImpl (org.openrdf.model.impl.URIImpl)9 UnknownIdentifierException (org.geneontology.minerva.MolecularModelManager.UnknownIdentifierException)4 BlazegraphMutationCounter (org.geneontology.minerva.util.BlazegraphMutationCounter)4 StatementCollector (org.openrdf.rio.helpers.StatementCollector)4 RioMemoryTripleSource (org.semanticweb.owlapi.rio.RioMemoryTripleSource)4 RioRenderer (org.semanticweb.owlapi.rio.RioRenderer)4 BigdataSail (com.bigdata.rdf.sail.BigdataSail)3 BigdataSailRepository (com.bigdata.rdf.sail.BigdataSailRepository)3 java.util (java.util)3 Options (com.bigdata.journal.Options)2 Iterations (info.aduna.iteration.Iterations)2 java.io (java.io)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 FileUtils (org.apache.commons.io.FileUtils)2