Search in sources :

Example 11 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class AbstractRDFInserter method handleStatement.

@Override
public void handleStatement(Statement st) throws RDFHandlerException {
    Resource subj = st.getSubject();
    IRI pred = st.getPredicate();
    Value obj = st.getObject();
    Resource ctxt = st.getContext();
    if (!preserveBNodeIDs) {
        if (subj instanceof BNode) {
            subj = mapBNode((BNode) subj);
        }
        if (obj instanceof BNode) {
            obj = mapBNode((BNode) obj);
        }
        if (!enforcesContext() && ctxt instanceof BNode) {
            ctxt = mapBNode((BNode) ctxt);
        }
    }
    try {
        addStatement(subj, pred, obj, ctxt);
    } catch (RDF4JException e) {
        throw new RDFHandlerException(e);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) BNode(org.eclipse.rdf4j.model.BNode) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) RDF4JException(org.eclipse.rdf4j.RDF4JException)

Example 12 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RepositoryUtil method statementsMatch.

private static boolean statementsMatch(Statement st1, Statement st2, Map<BNode, BNode> bNodeMapping) {
    IRI pred1 = st1.getPredicate();
    IRI pred2 = st2.getPredicate();
    if (!pred1.equals(pred2)) {
        // predicates don't match
        return false;
    }
    Resource subj1 = st1.getSubject();
    Resource subj2 = st2.getSubject();
    if (!(subj1 instanceof BNode)) {
        if (!subj1.equals(subj2)) {
            // subjects are not bNodes and don't match
            return false;
        }
    } else {
        // subj1 instanceof BNode
        BNode mappedBNode = bNodeMapping.get(subj1);
        if (mappedBNode != null) {
            // bNode 'subj1' was already mapped to some other bNode
            if (!subj2.equals(mappedBNode)) {
                // 'subj1' and 'subj2' do not match
                return false;
            }
        } else {
            // possible mapping candidate
            if (bNodeMapping.containsValue(subj2)) {
                // 'subj2' is already mapped to some other value.
                return false;
            }
        }
    }
    Value obj1 = st1.getObject();
    Value obj2 = st2.getObject();
    if (!(obj1 instanceof BNode)) {
        if (!obj1.equals(obj2)) {
            // objects are not bNodes and don't match
            return false;
        }
    } else {
        // obj1 instanceof BNode
        BNode mappedBNode = bNodeMapping.get(obj1);
        if (mappedBNode != null) {
            // bNode 'obj1' was already mapped to some other bNode
            if (!obj2.equals(mappedBNode)) {
                // 'obj1' and 'obj2' do not match
                return false;
            }
        } else {
            // possible mapping candidate
            if (bNodeMapping.containsValue(obj2)) {
                // 'obj2' is already mapped to some other value.
                return false;
            }
        }
    }
    return true;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) BNode(org.eclipse.rdf4j.model.BNode) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 13 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class ContextAwareConfig method export.

@Override
public Resource export(Model model) {
    Resource repImplNode = super.export(model);
    ValueFactory vf = SimpleValueFactory.getInstance();
    if (includeInferred != null) {
        Literal bool = vf.createLiteral(includeInferred);
        model.add(repImplNode, INCLUDE_INFERRED, bool);
    }
    if (maxQueryTime > 0) {
        model.add(repImplNode, MAX_QUERY_TIME, vf.createLiteral(maxQueryTime));
    }
    if (queryLanguage != null) {
        model.add(repImplNode, QUERY_LANGUAGE, vf.createLiteral(queryLanguage.getName()));
    }
    if (baseURI != null) {
        model.add(repImplNode, BASE_URI, vf.createIRI(baseURI));
    }
    for (IRI uri : readContexts) {
        model.add(repImplNode, READ_CONTEXT, uri);
    }
    for (IRI resource : addContexts) {
        model.add(repImplNode, ADD_CONTEXT, resource);
    }
    for (IRI resource : removeContexts) {
        model.add(repImplNode, REMOVE_CONTEXT, resource);
    }
    for (IRI resource : archiveContexts) {
        model.add(repImplNode, ARCHIVE_CONTEXT, resource);
    }
    if (insertContext != null) {
        model.add(repImplNode, INSERT_CONTEXT, insertContext);
    }
    return repImplNode;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Literal(org.eclipse.rdf4j.model.Literal) Resource(org.eclipse.rdf4j.model.Resource) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory)

Example 14 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class NotifyingRepositoryConnectionWrapper method removeWithoutCommit.

@Override
public void removeWithoutCommit(Resource subj, IRI pred, Value obj, Resource... ctx) throws RepositoryException {
    if (activated && reportDeltas()) {
        RepositoryResult<Statement> stmts;
        stmts = getDelegate().getStatements(subj, pred, obj, false, ctx);
        List<Statement> list = new ArrayList<Statement>();
        try {
            while (stmts.hasNext()) {
                list.add(stmts.next());
            }
        } finally {
            stmts.close();
        }
        getDelegate().remove(subj, pred, obj, ctx);
        for (RepositoryConnectionListener listener : listeners) {
            for (Statement stmt : list) {
                Resource s = stmt.getSubject();
                IRI p = stmt.getPredicate();
                Value o = stmt.getObject();
                Resource c = stmt.getContext();
                listener.remove(getDelegate(), s, p, o, c);
            }
        }
    } else if (activated) {
        getDelegate().remove(subj, pred, obj, ctx);
        for (RepositoryConnectionListener listener : listeners) {
            listener.remove(getDelegate(), subj, pred, obj, ctx);
        }
    } else {
        getDelegate().remove(subj, pred, obj, ctx);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener) Statement(org.eclipse.rdf4j.model.Statement) ArrayList(java.util.ArrayList) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 15 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class AbstractDelegatingRepositoryImplConfig method export.

@Override
public Resource export(Model model) {
    Resource resource = super.export(model);
    if (delegate != null) {
        Resource delegateNode = delegate.export(model);
        model.add(resource, DELEGATE, delegateNode);
    }
    return resource;
}
Also used : Resource(org.eclipse.rdf4j.model.Resource)

Aggregations

Resource (org.eclipse.rdf4j.model.Resource)90 IRI (org.eclipse.rdf4j.model.IRI)37 Value (org.eclipse.rdf4j.model.Value)30 Test (org.junit.Test)16 Statement (org.eclipse.rdf4j.model.Statement)15 Model (org.eclipse.rdf4j.model.Model)12 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)12 BNode (org.eclipse.rdf4j.model.BNode)11 IOException (java.io.IOException)9 Literal (org.eclipse.rdf4j.model.Literal)9 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7 StringWriter (java.io.StringWriter)6 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)6 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)6 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)6 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)5 ArrayList (java.util.ArrayList)4