Search in sources :

Example 46 with Statement

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

the class LinkedHashModel method readObject.

private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in any hidden serialization magic
    s.defaultReadObject();
    // Read in size
    int size = s.readInt();
    values = new HashMap<Value, ModelNode>(size * 2);
    statements = new LinkedHashSet<ModelStatement>(size);
    // Read in all elements
    for (int i = 0; i < size; i++) {
        Statement st = (Statement) s.readObject();
        add(st);
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Value(org.eclipse.rdf4j.model.Value)

Example 47 with Statement

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

the class LinkedHashModel method remove.

@Override
public boolean remove(Object o) {
    if (o instanceof Statement) {
        Iterator iter = find((Statement) o);
        if (iter.hasNext()) {
            iter.next();
            iter.remove();
            return true;
        }
    }
    return false;
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Iterator(java.util.Iterator) PatternIterator(org.eclipse.rdf4j.model.util.PatternIterator)

Example 48 with Statement

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

the class TreeModel method pollLast.

public Statement pollLast() {
    try {
        Statement last = trees.get(0).tree.last();
        remove(last);
        return last;
    } catch (NoSuchElementException e) {
        return null;
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) NoSuchElementException(java.util.NoSuchElementException)

Example 49 with Statement

use of org.eclipse.rdf4j.model.Statement 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)

Example 50 with Statement

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

the class SPARQLConnection method getStatementGeneral.

private RepositoryResult<Statement> getStatementGeneral(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    GraphQueryResult gRes = null;
    RepositoryResult<Statement> result = null;
    boolean allGood = false;
    try {
        GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
        query.setIncludeInferred(includeInferred);
        setBindings(query, subj, pred, obj, contexts);
        gRes = query.evaluate();
        result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(gRes) {

            @Override
            protected RepositoryException convert(Exception e) {
                return new RepositoryException(e);
            }
        });
        allGood = true;
        return result;
    } finally {
        if (!allGood) {
            try {
                if (result != null) {
                    result.close();
                }
            } finally {
                if (gRes != null) {
                    gRes.close();
                }
            }
        }
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) ExceptionConvertingIteration(org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SPARQLGraphQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLGraphQuery) GraphQuery(org.eclipse.rdf4j.query.GraphQuery) GraphQueryResult(org.eclipse.rdf4j.query.GraphQueryResult) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UpdateExecutionException(org.eclipse.rdf4j.query.UpdateExecutionException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) UnknownTransactionStateException(org.eclipse.rdf4j.repository.UnknownTransactionStateException) UnsupportedQueryLanguageException(org.eclipse.rdf4j.query.UnsupportedQueryLanguageException) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Aggregations

Statement (org.eclipse.rdf4j.model.Statement)74 IRI (org.eclipse.rdf4j.model.IRI)17 Test (org.junit.Test)17 Model (org.eclipse.rdf4j.model.Model)16 Literal (org.eclipse.rdf4j.model.Literal)15 Resource (org.eclipse.rdf4j.model.Resource)15 Value (org.eclipse.rdf4j.model.Value)13 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ArrayList (java.util.ArrayList)10 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)8 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)8 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 StringWriter (java.io.StringWriter)7 BNode (org.eclipse.rdf4j.model.BNode)6 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)6 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)6 IOException (java.io.IOException)5