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));
}
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);
}
}
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);
}
}
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);
}
}
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));
}
Aggregations