use of org.apache.jena.rdf.model.StmtIterator in project jena by apache.
the class QueryTest method runTestAsk.
void runTestAsk(Query query, QueryExecution qe) throws Exception {
boolean result = qe.execAsk();
if (results != null) {
if (results.isBoolean()) {
boolean b = results.getBooleanResult();
assertEquals("ASK test results do not match", b, result);
} else {
Model resultsAsModel = results.getModel();
StmtIterator sIter = results.getModel().listStatements(null, RDF.type, ResultSetGraphVocab.ResultSet);
if (!sIter.hasNext())
throw new QueryTestException("Can't find the ASK result");
Statement s = sIter.nextStatement();
if (sIter.hasNext())
throw new QueryTestException("Too many result sets in ASK result");
Resource r = s.getSubject();
Property p = resultsAsModel.createProperty(ResultSetGraphVocab.getURI() + "boolean");
boolean x = r.getRequiredProperty(p).getBoolean();
if (x != result)
assertEquals("ASK test results do not match", x, result);
}
}
return;
}
use of org.apache.jena.rdf.model.StmtIterator in project jena by apache.
the class TestModelSetOperations method testIntersection.
public void testIntersection() {
ModelHelper.modelAdd(model, "a P b; w R x");
ModelHelper.modelAdd(model2, "w R x; y S z");
final Model im = model.intersection(model2);
Assert.assertFalse(model.containsAll(model2));
Assert.assertFalse(model2.containsAll(model));
Assert.assertTrue(model.containsAll(im));
Assert.assertTrue(model2.containsAll(im));
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertTrue(model.contains(s) && model2.contains(s));
}
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
Assert.assertTrue(model.contains(it.nextStatement()));
}
for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
Assert.assertTrue(model2.contains(it.nextStatement()));
}
Assert.assertTrue(model.containsAll(im.listStatements()));
Assert.assertTrue(model2.containsAll(im.listStatements()));
}
use of org.apache.jena.rdf.model.StmtIterator in project jena by apache.
the class TestModelSetOperations method testDifference.
public void testDifference() {
ModelHelper.modelAdd(model, "a P b; w R x");
ModelHelper.modelAdd(model2, "w R x; y S z");
final Model dm = model.difference(model2);
for (final StmtIterator it = dm.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertTrue(model.contains(s) && !model2.contains(s));
}
for (final StmtIterator it = model.union(model2).listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
Assert.assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s));
}
Assert.assertTrue(dm.containsAny(model));
Assert.assertTrue(dm.containsAny(model.listStatements()));
Assert.assertFalse(dm.containsAny(model2));
Assert.assertFalse(dm.containsAny(model2.listStatements()));
Assert.assertTrue(model.containsAll(dm));
}
use of org.apache.jena.rdf.model.StmtIterator in project jena by apache.
the class TestAddModel method testAddByIterator.
public void testAddByIterator() {
ModelHelper.modelAdd(model, "a P b; c P d; x Q 1; y Q 2");
model2.add(model.listStatements());
Assert.assertEquals(model.size(), model2.size());
assertSameStatements(model, model2);
model.add(model.createResource(), RDF.value, model.createResource());
model.add(model.createResource(), RDF.value, model.createResource());
model.add(model.createResource(), RDF.value, model.createResource());
final StmtIterator s = model.listStatements();
model2.remove(s.nextStatement()).remove(s);
Assert.assertEquals(0, model2.size());
}
use of org.apache.jena.rdf.model.StmtIterator in project opentheso by miledrousset.
the class SynchroSparql method run.
@Override
public void run() {
System.out.println("dans le run saprtql");
String url = sparqlStruct.getAdresseServeur().replaceAll("http", "jdbc:virtuoso").trim() + ":1111";
VirtGraph graph = new VirtGraph(sparqlStruct.getGraph(), url, sparqlStruct.getNom_d_utilisateur(), sparqlStruct.getMot_de_passe());
String str = "CLEAR GRAPH <" + sparqlStruct.getGraph() + ">";
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, graph);
vur.exec();
Model m = ModelFactory.createDefaultModel();
DownloadBean db = new DownloadBean();
db.setConnect(conn);
StreamedContent file = db.thesoToFile(sparqlStruct.getThesaurus(), liste_lang, liste_group, 0);
try {
m.read(file.getStream(), null);
} catch (Exception e) {
// graph.close();
}
StmtIterator iter = m.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
Triple tri = new Triple(subject.asNode(), predicate.asNode(), object.asNode());
graph.add(tri);
}
graph.close();
}
Aggregations