Search in sources :

Example 56 with Resource

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

the class GraphImpl method add.

public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts) {
    OpenRDFUtil.verifyContextNotNull(contexts);
    boolean graphChanged = false;
    if (contexts.length == 0) {
        graphChanged = add(valueFactory.createStatement(subj, pred, obj));
    } else {
        for (Resource context : contexts) {
            graphChanged |= add(valueFactory.createStatement(subj, pred, obj, context));
        }
    }
    return graphChanged;
}
Also used : Resource(org.eclipse.rdf4j.model.Resource)

Example 57 with Resource

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

the class LinkedHashModel method add.

@Override
public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts) {
    if (subj == null || pred == null || obj == null)
        throw new UnsupportedOperationException("Incomplete statement");
    Value[] ctxs = notNull(contexts);
    if (ctxs.length == 0) {
        ctxs = NULL_CTX;
    }
    boolean changed = false;
    for (Value ctx : ctxs) {
        ModelNode<Resource> s = asNode(subj);
        ModelNode<IRI> p = asNode(pred);
        ModelNode<Value> o = asNode(obj);
        ModelNode<Resource> c = asNode((Resource) ctx);
        ModelStatement st = new ModelStatement(s, p, o, c);
        changed |= addModelStatement(st);
    }
    return changed;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Value(org.eclipse.rdf4j.model.Value) Resource(org.eclipse.rdf4j.model.Resource)

Example 58 with Resource

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

the class TreeModel method before.

private Statement before(Value subj, Value pred, Value obj, Value ctx) {
    Resource s = subj instanceof Resource ? (Resource) subj : BEFORE;
    IRI p = pred instanceof IRI ? (IRI) pred : BEFORE;
    Value o = obj instanceof Value ? obj : BEFORE;
    Resource c = ctx instanceof Resource ? (Resource) ctx : BEFORE;
    return new TreeStatement(s, p, o, c);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 59 with Resource

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

the class TreeModel method after.

private Statement after(Value subj, Value pred, Value obj, Value ctx) {
    Resource s = subj instanceof Resource ? (Resource) subj : AFTER;
    IRI p = pred instanceof IRI ? (IRI) pred : AFTER;
    Value o = obj instanceof Value ? obj : AFTER;
    Resource c = ctx instanceof Resource ? (Resource) ctx : AFTER;
    return new TreeStatement(s, p, o, c);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 60 with Resource

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

the class SPARQLConnection method createDataBody.

private void createDataBody(StringBuilder qb, Iterable<? extends Statement> statements, boolean ignoreContext) {
    for (Statement st : statements) {
        final Resource context = st.getContext();
        if (!ignoreContext) {
            if (context != null) {
                String namedGraph = context.stringValue();
                if (context instanceof BNode) {
                    // SPARQL does not allow blank nodes as named graph
                    // identifiers, so we need to skolemize
                    // the blank node id.
                    namedGraph = "urn:nodeid:" + context.stringValue();
                }
                qb.append("    GRAPH <" + namedGraph + "> { \n");
            }
        }
        if (st.getSubject() instanceof BNode) {
            qb.append("_:" + st.getSubject().stringValue() + " ");
        } else {
            qb.append("<" + st.getSubject().stringValue() + "> ");
        }
        qb.append("<" + st.getPredicate().stringValue() + "> ");
        if (st.getObject() instanceof Literal) {
            Literal lit = (Literal) st.getObject();
            qb.append("\"");
            qb.append(SPARQLUtil.encodeString(lit.getLabel()));
            qb.append("\"");
            if (Literals.isLanguageLiteral(lit)) {
                qb.append("@");
                qb.append(lit.getLanguage().get());
            } else {
                qb.append("^^<" + lit.getDatatype().stringValue() + ">");
            }
            qb.append(" ");
        } else if (st.getObject() instanceof BNode) {
            qb.append("_:" + st.getObject().stringValue() + " ");
        } else {
            qb.append("<" + st.getObject().stringValue() + "> ");
        }
        qb.append(". \n");
        if (!ignoreContext && context != null) {
            qb.append("    }\n");
        }
    }
}
Also used : BNode(org.eclipse.rdf4j.model.BNode) Statement(org.eclipse.rdf4j.model.Statement) Literal(org.eclipse.rdf4j.model.Literal) 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