Search in sources :

Example 56 with Resource

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

the class ModelComparer method recordIfBlankNode.

private void recordIfBlankNode(Value node, Statement statement, Set<Resource> bNodes, MultiMap<Resource, Statement> triples) {
    if (node instanceof BNode) {
        Resource resource = (Resource) node;
        bNodes.add(resource);
        triples.add(resource, statement);
    }
}
Also used : BNode(org.openrdf.model.BNode) Resource(org.openrdf.model.Resource)

Example 57 with Resource

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

the class RDFObjectCompositePool method getPrimaryResource.

public Resource getPrimaryResource(T object) {
    Class<T1> createdClass1 = pool1.getCreatedClass();
    if (createdClass1.isInstance(object)) {
        T1 object1 = createdClass1.cast(object);
        Resource primaryResource = pool1.getPrimaryResource(object1);
        if (primaryResource != null) {
            return primaryResource;
        }
    }
    Class<T2> createdClass2 = pool2.getCreatedClass();
    if (createdClass2.isInstance(object)) {
        T2 object2 = createdClass2.cast(object);
        Resource primaryResource = pool2.getPrimaryResource(object2);
        if (primaryResource != null) {
            return primaryResource;
        }
    }
    return null;
}
Also used : Resource(org.openrdf.model.Resource)

Example 58 with Resource

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

the class RDFObjectSimplePool method remove.

public void remove(T object) {
    Set<Resource> resourcesToDelete = new HashSet<Resource>();
    Set<Resource> resources = object2resources.get(object);
    if (resources != null) {
        object2resources.remove(object);
        resourcesToDelete.addAll(resources);
    }
    Resource primaryResource = object2primaryResource.get(object);
    if (primaryResource != null) {
        object2primaryResource.remove(object);
        resourcesToDelete.add(primaryResource);
    }
    for (Resource resourceToDelete : resourcesToDelete) {
        resource2object.remove(resourceToDelete);
    }
}
Also used : Resource(org.openrdf.model.Resource) HashSet(java.util.HashSet)

Example 59 with Resource

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

the class RDFResourceProjection method project.

public URI project(URI property) {
    Resource resourceMapped = map.get(property);
    URI propertyMapped = property;
    if (resourceMapped instanceof URI) {
        propertyMapped = (URI) resourceMapped;
    }
    return propertyMapped;
}
Also used : Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI)

Example 60 with Resource

use of org.openrdf.model.Resource 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

Resource (org.openrdf.model.Resource)60 Statement (org.openrdf.model.Statement)22 URI (org.openrdf.model.URI)20 Value (org.openrdf.model.Value)17 HashSet (java.util.HashSet)14 Graph (org.openrdf.model.Graph)7 Literal (org.openrdf.model.Literal)6 SailConnection (org.openrdf.sail.SailConnection)5 SailException (org.openrdf.sail.SailException)5 Entry (cbit.vcell.biomodel.meta.registry.Registry.Entry)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)4 Map (java.util.Map)3 Set (java.util.Set)3 Element (org.jdom.Element)3 HashGraph (org.sbpax.impl.HashGraph)3 VCID (cbit.vcell.biomodel.meta.VCID)2 Registry (cbit.vcell.biomodel.meta.registry.Registry)2 Edge (com.tinkerpop.blueprints.Edge)2