Search in sources :

Example 36 with Resource

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

the class XMLMetaDataWriter method getElement.

public static Element getElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
    Element element = new Element(XMLMetaData.VCMETADATA_TAG);
    Element elementRDF = metaData.createElement();
    // add RDF data
    if (elementRDF != null) {
        element.addContent(elementRDF);
    }
    Element elementNonRDFList = createNonRDFAnnotationElement(metaData, identifiableProvider);
    element.addContent(elementNonRDFList);
    // add resource binding table
    Element bindingListElement = new Element(XMLMetaData.URI_BINDING_LIST_TAG);
    Set<Registry.Entry> resources = metaData.getRegistry().getAllEntries();
    for (Registry.Entry entry : resources) {
        VCID vcid = identifiableProvider.getVCID(entry.getIdentifiable());
        Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
        if (identifiable != null && entry.getResource() != null) {
            Element entryElement = new Element(XMLMetaData.URI_BINDING_TAG);
            Resource resource = entry.getResource();
            if (resource != null) {
                entryElement.setAttribute(XMLMetaData.URI_ATTR_TAG, resource.stringValue());
            }
            entryElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
            bindingListElement.addContent(entryElement);
        }
    }
    element.addContent(bindingListElement);
    return element;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Element(org.jdom.Element) Resource(org.openrdf.model.Resource) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Registry(cbit.vcell.biomodel.meta.registry.Registry) Identifiable(org.vcell.util.document.Identifiable)

Example 37 with Resource

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

the class SailEdge method removeProperty.

public <T> T removeProperty(final String key) {
    if (key.equals(SailTokens.NAMED_GRAPH)) {
        try {
            Resource ng = this.rawEdge.getContext();
            SailHelper.removeStatement(this.rawEdge, this.graph.getSailConnection().get());
            this.rawEdge = new StatementImpl(this.rawEdge.getSubject(), this.rawEdge.getPredicate(), this.rawEdge.getObject());
            SailHelper.addStatement(this.rawEdge, this.graph.getSailConnection().get());
            return (T) ng;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } else {
        throw new IllegalArgumentException(NAMED_GRAPH_PROPERTY);
    }
}
Also used : StatementImpl(org.openrdf.model.impl.StatementImpl) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Resource(org.openrdf.model.Resource)

Example 38 with Resource

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

the class SailGraph method addEdge.

public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
    if (label == null)
        throw ExceptionFactory.edgeLabelCanNotBeNull();
    Value outVertexValue = ((SailVertex) outVertex).getRawVertex();
    Value inVertexValue = ((SailVertex) inVertex).getRawVertex();
    if (!(outVertexValue instanceof Resource)) {
        throw new IllegalArgumentException(outVertex.toString() + " is not a legal URI or blank node");
    }
    try {
        URI labelURI = new URIImpl(this.expandPrefix(label));
        Statement statement = new StatementImpl((Resource) outVertexValue, labelURI, inVertexValue);
        SailHelper.addStatement(statement, this.sailConnection.get());
        return new SailEdge(statement, this);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) Value(org.openrdf.model.Value) Resource(org.openrdf.model.Resource) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RDFHandlerException(org.openrdf.rio.RDFHandlerException)

Example 39 with Resource

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

the class GraphSailConnection method clearInternal.

private void clearInternal(final boolean inferred, final Resource... contexts) throws SailException {
    if (!canWrite()) {
        WriteAction a = new WriteAction(ActionType.CLEAR);
        a.inferred = inferred;
        a.contexts = contexts;
        queueUpdate(a);
        return;
    }
    if (0 == contexts.length) {
        deleteEdgesInIterator(inferred, store.matchers[0x0].match(null, null, null, null, inferred));
    } else {
        for (Resource context : contexts) {
            // Note: order of operands to the "or" is important here
            deleteEdgesInIterator(inferred, store.matchers[0x8].match(null, null, null, context, inferred));
        }
    }
}
Also used : Resource(org.openrdf.model.Resource)

Example 40 with Resource

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

the class GraphSailConnection method getStatementsInternal.

public CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final URI predicate, final Value object, final boolean includeInferred, final Resource... contexts) throws SailException {
    int index = 0;
    if (null != subject) {
        index |= 0x1;
    }
    if (null != predicate) {
        index |= 0x2;
    }
    if (null != object) {
        index |= 0x4;
    }
    if (0 == contexts.length) {
        return createIteration(store.matchers[index].match(subject, predicate, object, null, includeInferred));
    } else {
        Collection<CloseableIteration<Statement, SailException>> iterations = new LinkedList<CloseableIteration<Statement, SailException>>();
        // TODO: as an optimization, filter on multiple contexts simultaneously (when context is not used in the matcher), rather than trying each context consecutively.
        for (Resource context : contexts) {
            index |= 0x8;
            Matcher m = store.matchers[index];
            iterations.add(createIteration(m.match(subject, predicate, object, context, includeInferred)));
        }
        return new CompoundCloseableIteration<Statement, SailException>(iterations);
    }
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) CompoundCloseableIteration(net.fortytwo.sesametools.CompoundCloseableIteration) CompoundCloseableIteration(net.fortytwo.sesametools.CompoundCloseableIteration) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) LinkedList(java.util.LinkedList)

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