Search in sources :

Example 71 with Resource

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

the class RDFCollectionsTest method testExtract.

@Test
public void testExtract() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    // add something to the model that is not part of the RDF collection.
    m.add(RDF.TYPE, RDF.TYPE, RDF.PROPERTY);
    Model collection = RDFCollections.getCollection(m, head, new TreeModel());
    assertNotNull(collection);
    assertFalse(collection.contains(RDF.TYPE, RDF.TYPE, RDF.PROPERTY));
    assertTrue(collection.contains(null, RDF.FIRST, a));
    assertTrue(collection.contains(null, RDF.FIRST, b));
    assertTrue(collection.contains(null, RDF.FIRST, c));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Example 72 with Resource

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

the class DAWGTestResultSetParser method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    try {
        Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET);
        List<String> bindingNames = getBindingNames(resultSetNode);
        tqrHandler.startQueryResult(bindingNames);
        Iterator<Value> solIter = GraphUtil.getObjectIterator(graph, resultSetNode, SOLUTION);
        while (solIter.hasNext()) {
            Value solutionNode = solIter.next();
            if (solutionNode instanceof Resource) {
                reportSolution((Resource) solutionNode, bindingNames);
            } else {
                throw new RDFHandlerException("Value for " + SOLUTION + " is not a resource: " + solutionNode);
            }
        }
        tqrHandler.endQueryResult();
    } catch (GraphUtilException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    } catch (TupleQueryResultHandlerException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) GraphUtilException(org.eclipse.rdf4j.model.util.GraphUtilException)

Example 73 with Resource

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

the class DAWGTestResultSetParser method reportSolution.

private void reportSolution(Resource solutionNode, List<String> bindingNames) throws RDFHandlerException, GraphUtilException {
    MapBindingSet bindingSet = new MapBindingSet(bindingNames.size());
    Iterator<Value> bindingIter = GraphUtil.getObjectIterator(graph, solutionNode, BINDING);
    while (bindingIter.hasNext()) {
        Value bindingNode = bindingIter.next();
        if (bindingNode instanceof Resource) {
            Binding binding = getBinding((Resource) bindingNode);
            bindingSet.addBinding(binding);
        } else {
            throw new RDFHandlerException("Value for " + BINDING + " is not a resource: " + bindingNode);
        }
    }
    try {
        tqrHandler.handleSolution(bindingSet);
    } catch (TupleQueryResultHandlerException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) SimpleBinding(org.eclipse.rdf4j.query.impl.SimpleBinding) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Value(org.eclipse.rdf4j.model.Value) Resource(org.eclipse.rdf4j.model.Resource) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet)

Example 74 with Resource

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

the class DAWGTestBooleanParser method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    try {
        Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET);
        Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN);
        if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) {
            value = true;
        } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) {
            value = false;
        } else {
            throw new RDFHandlerException("Invalid boolean value: " + booleanLit);
        }
    } catch (GraphUtilException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Literal(org.eclipse.rdf4j.model.Literal) Resource(org.eclipse.rdf4j.model.Resource) GraphUtilException(org.eclipse.rdf4j.model.util.GraphUtilException)

Example 75 with Resource

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

the class ModelsTest method testSubjectBNode.

public void testSubjectBNode() {
    model1.add(foo, bar, foo);
    model1.add(foo, foo, foo);
    model1.add(baz, foo, foo);
    model1.add(bar, foo, foo);
    Resource result = Models.subjectBNode(model1).orElse(null);
    assertNotNull(result);
    assertTrue(result.equals(baz));
}
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