Search in sources :

Example 46 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class UniProtExtractor method extractBox.

public UniProtBox extractBox() {
    UniProtBoxImp box = new UniProtBoxImp();
    Iterator<Statement> stmtIter1 = model.match(null, UniProtConstants.replaces, null);
    while (stmtIter1.hasNext()) {
        Statement statement = stmtIter1.next();
        Resource subject = statement.getSubject();
        Value object = statement.getObject();
        if (subject instanceof URI && object instanceof URI) {
            String idSubject = id((URI) subject);
            String idObject = id((URI) object);
            if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
                UniProtBox.Entry entrySubject = box.entry(idSubject);
                UniProtBox.Entry entryObject = box.entry(idObject);
                box.setReplaces(entrySubject, entryObject);
            }
        }
    }
    Iterator<Statement> stmtIter2 = model.match(null, UniProtConstants.replacedBy, null);
    while (stmtIter2.hasNext()) {
        Statement statement = stmtIter2.next();
        Resource subject = statement.getSubject();
        Value object = statement.getObject();
        if (subject instanceof URI && object instanceof URI) {
            String idSubject = id((URI) subject);
            String idObject = id((URI) object);
            if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
                UniProtBox.Entry entrySubject = box.entry(idSubject);
                UniProtBox.Entry entryObject = box.entry(idObject);
                box.setReplaces(entryObject, entrySubject);
            }
        }
    }
    Iterator<Statement> stmtIter3 = model.match(null, UniProtConstants.recommendedName, null);
    if (stmtIter3.hasNext()) {
        while (stmtIter3.hasNext()) {
            Statement statement = stmtIter3.next();
            Resource entryNode = statement.getSubject();
            Value nameNode = statement.getObject();
            if (nameNode instanceof Resource) {
                Resource nameResource = (Resource) nameNode;
                Iterator<Statement> stmtIter4 = model.match(nameResource, UniProtConstants.fullName, null);
                // System.out.println("hello world");
                while (stmtIter4.hasNext()) {
                    Statement statement2 = stmtIter4.next();
                    Value objectNode = statement2.getObject();
                    // System.out.println("hello moon");
                    if (entryNode instanceof URI && objectNode instanceof Literal) {
                        String name = ((Literal) objectNode).stringValue();
                        UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
                        System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
                        entry.setRecommendedName(name);
                    }
                }
            }
        }
    } else {
        // sometimes, recommended name is not present for an uniprot id : check the full name
        stmtIter3 = model.match(null, UniProtConstants.fullName, null);
        while (stmtIter3.hasNext()) {
            Statement statement2 = stmtIter3.next();
            Resource entryNode = statement2.getSubject();
            Value objectNode = statement2.getObject();
            if (entryNode instanceof URI && objectNode instanceof Literal) {
                String name = ((Literal) objectNode).stringValue();
                UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
                entry.setRecommendedName(name);
                System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
            }
        }
    }
    return box;
}
Also used : UniProtBoxImp(org.vcell.sybil.util.http.uniprot.box.imp.UniProtBoxImp) Statement(org.openrdf.model.Statement) UniProtBox(org.vcell.sybil.util.http.uniprot.box.UniProtBox) Literal(org.openrdf.model.Literal) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) URI(org.openrdf.model.URI)

Aggregations

Value (org.openrdf.model.Value)46 Statement (org.openrdf.model.Statement)22 URI (org.openrdf.model.URI)22 Resource (org.openrdf.model.Resource)17 HashSet (java.util.HashSet)11 BindingSet (org.openrdf.query.BindingSet)10 TupleQueryResult (org.openrdf.query.TupleQueryResult)8 BNode (org.openrdf.model.BNode)6 Literal (org.openrdf.model.Literal)6 ExpressionQueryResult (edu.mit.simile.backstage.model.data.ExpressionQueryResult)5 ScriptableArrayBuilder (edu.mit.simile.backstage.util.ScriptableArrayBuilder)5 HashMap (java.util.HashMap)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 DefaultScriptableObject (edu.mit.simile.backstage.util.DefaultScriptableObject)4 ArrayList (java.util.ArrayList)4 Graph (org.openrdf.model.Graph)4 SailException (org.openrdf.sail.SailException)4 Map (java.util.Map)3 Set (java.util.Set)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3