Search in sources :

Example 11 with StmtIterator

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;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 12 with StmtIterator

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()));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 13 with StmtIterator

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));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 14 with StmtIterator

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());
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator)

Example 15 with StmtIterator

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();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) VirtuosoUpdateRequest(virtuoso.jena.driver.VirtuosoUpdateRequest) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Triple(org.apache.jena.graph.Triple) VirtGraph(virtuoso.jena.driver.VirtGraph) Model(org.apache.jena.rdf.model.Model) StreamedContent(org.primefaces.model.StreamedContent) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

StmtIterator (org.apache.jena.rdf.model.StmtIterator)15 Statement (org.apache.jena.rdf.model.Statement)8 Model (org.apache.jena.rdf.model.Model)7 Resource (org.apache.jena.rdf.model.Resource)6 Property (org.apache.jena.rdf.model.Property)3 OntModel (org.apache.jena.ontology.OntModel)2 InfModel (org.apache.jena.rdf.model.InfModel)2 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 ExecutorService (java.util.concurrent.ExecutorService)1 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)1 Triple (org.apache.jena.graph.Triple)1 OntClass (org.apache.jena.ontology.OntClass)1 OntResource (org.apache.jena.ontology.OntResource)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Reasoner (org.apache.jena.reasoner.Reasoner)1 TransitiveReasoner (org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner)1 Store (org.apache.jena.sdb.Store)1 JenaException (org.apache.jena.shared.JenaException)1 ExtendedIterator (org.apache.jena.util.iterator.ExtendedIterator)1