Search in sources :

Example 41 with Resource

use of org.openrdf.model.Resource in project blueprints by tinkerpop.

the class SailTest method testClear.

@Test
public void testClear() throws Exception {
    URI uriA = sail.getValueFactory().createURI("http://example.org/uriA");
    URI uriB = sail.getValueFactory().createURI("http://example.org/uriB");
    URI uriC = sail.getValueFactory().createURI("http://example.org/uriC");
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        sc.clear();
        assertEquals(0L, sc.size());
        sc.addStatement(uriA, uriB, uriC, uriA);
        sc.addStatement(uriC, uriA, uriB, uriA);
        sc.addStatement(uriB, uriC, uriA, uriA);
        assertEquals(3L, sc.size(uriA));
        sc.addStatement(uriA, uriB, uriC, uriB);
        sc.addStatement(uriB, uriC, uriA, uriB);
        assertEquals(2L, sc.size(uriB));
        sc.addStatement(uriA, uriB, uriC);
        assertEquals(1L, sc.size((Resource) null));
        sc.addStatement(uriA, uriB, uriC, uriC);
        sc.addStatement(uriB, uriC, uriA, uriC);
        sc.addStatement(uriC, uriA, uriB, uriC);
        sc.addStatement(uriA, uriB, uriB, uriC);
        assertEquals(4L, sc.size(uriC));
        assertEquals(10L, sc.size());
        sc.clear(uriA, uriC);
        assertEquals(1L, sc.size((Resource) null));
        assertEquals(0L, sc.size(uriA));
        assertEquals(2L, sc.size(uriB));
        assertEquals(0L, sc.size(uriC));
        assertEquals(3L, sc.size());
        sc.clear();
        assertEquals(0L, sc.size());
        sc.commit();
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 42 with Resource

use of org.openrdf.model.Resource in project backstage by zepheira.

the class Database method abbreviateItems.

protected synchronized void abbreviateItems() {
    if (_abbreviatedItems) {
        return;
    }
    _abbreviatedItems = true;
    getRepository();
    SailConnection sc = null;
    try {
        sc = _sail.getConnection();
    } catch (SailException e) {
        _logger.error("Failed to open sail connection in order to compute cached information", e);
    }
    if (sc != null) {
        try {
            CloseableIteration<? extends Statement, SailException> i;
            try {
                i = sc.getStatements(null, RDF.TYPE, null, true);
            } catch (SailException e) {
                _logger.error("Failed to get all statements in order to abbreviate items", e);
                return;
            }
            try {
                while (i.hasNext()) {
                    Statement s = i.next();
                    Resource r = s.getSubject();
                    if (r instanceof URI) {
                        getItemId((URI) r, sc);
                    }
                }
            } catch (SailException e) {
                _logger.warn("Failed to iterate through statements", e);
            } finally {
                try {
                    i.close();
                } catch (SailException e) {
                    _logger.warn("Failed to close statement iterator", e);
                }
            }
        } finally {
            try {
                sc.close();
            } catch (SailException e) {
                _logger.warn("Failed to close sail connection", e);
            }
        }
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI)

Example 43 with Resource

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

the class MIRIAMAnnotationViewer method printResourceMappings.

public static String printResourceMappings(VCMetaData metaData) {
    StringBuffer strBuffer = new StringBuffer();
    strBuffer.append("\n\n ResourceMappings : \n");
    Set<Registry.Entry> entrySet = metaData.getRegistry().getAllEntries();
    for (Registry.Entry entry : entrySet) {
        Resource resource = entry.getResource();
        if (resource != null) {
            strBuffer.append(resource.stringValue());
            Identifiable identifiable = entry.getIdentifiable();
            strBuffer.append(" ============= " + metaData.getIdentifiableProvider().getVCID(identifiable).toASCIIString());
            strBuffer.append("\n");
        }
    }
    return strBuffer.toString();
}
Also used : Resource(org.openrdf.model.Resource) Registry(cbit.vcell.biomodel.meta.registry.Registry) Identifiable(org.vcell.util.document.Identifiable)

Example 44 with Resource

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

the class VCMetaDataMiriamManager method addMiriamRefGroup.

public void addMiriamRefGroup(Identifiable identifiable, MIRIAMQualifier miriamQualifier, Set<MiriamResource> miriamResources) throws URNParseFailureException {
    Entry entry = vcMetaData.getRegistry().getEntry(identifiable);
    Resource resource = entry.getResource();
    if (resource == null) {
        String newURIString = vcMetaData.getRegistry().generateFreeURI(identifiable);
        resource = entry.setURI(vcMetaData.getRdfData(), newURIString);
    }
    MIRIAMizer miriamizer = new MIRIAMizer();
    RefGroup sybilRefGroup = miriamizer.newRefGroup(vcMetaData.getRdfData(), resource, miriamQualifier);
    Set<MIRIAMRef> sybilMiriamRefs = new HashSet<MIRIAMRef>();
    for (MiriamResource miriamResource : miriamResources) {
        sybilMiriamRefs.add(MIRIAMRef.createFromURN(miriamResource.getMiriamURN()));
    }
    for (MIRIAMRef sybilMiriamRef : sybilMiriamRefs) {
        sybilRefGroup.add(vcMetaData.getRdfData(), sybilMiriamRef);
    }
    invalidateCache(identifiable);
    vcMetaData.fireAnnotationEventListener(new VCMetaData.AnnotationEvent(identifiable));
}
Also used : MIRIAMRef(org.vcell.sybil.models.miriam.MIRIAMRef) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) MIRIAMizer(org.vcell.sybil.models.miriam.MIRIAMizer) Resource(org.openrdf.model.Resource) RefGroup(org.vcell.sybil.models.miriam.RefGroup) HashSet(java.util.HashSet)

Example 45 with Resource

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

the class VCMetaDataMiriamManager method getPrettyName.

public String getPrettyName(MiriamResource miriamResource) {
    Resource resource = vcMetaData.getRdfData().getValueFactory().createURI(miriamResource.getMiriamURN());
    Iterator<Statement> iter = vcMetaData.getRdfData().match(resource, ProtegeDC.description, null);
    while (iter.hasNext()) {
        Statement statement = iter.next();
        return statement.getObject().toString();
    }
    return null;
}
Also used : Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource)

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