Search in sources :

Example 26 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestItem method _getDefaultGraphURIs.

// ----------------------------------------------------
// ---- Query specific properties
/**
     * Get the data file (default graph): maybe unknown if part for the query
     * (FROM)
     * 
     * @return List
     */
private List<String> _getDefaultGraphURIs() {
    if (!_getAction().isAnon())
        // Action is a URI - data had better be in the query itself.
        return null;
    List<String> l = new ArrayList<>();
    ClosableIterator<Statement> cIter = _getAction().listProperties(VocabTestQuery.data);
    for (; cIter.hasNext(); ) {
        Statement stmt = cIter.next();
        String df = stmt.getResource().getURI();
        l.add(df);
    }
    cIter.close();
    return l;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 27 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class UpdateTest method getDataset.

static Dataset getDataset(Resource r) {
    //DataSource ds = DatasetFactory.create() ;
    DatasetGraph dsg = DatasetGraphFactory.create();
    // Growing. dataset.
    Dataset ds = DatasetFactory.wrap(dsg);
    List<String> dftData = getAll(r, TestManifestUpdate_11.data);
    for (String x : dftData) FileManager.get().readModel(ds.getDefaultModel(), x);
    ClosableIterator<Statement> cIter = r.listProperties(TestManifestUpdate_11.graphData);
    for (; cIter.hasNext(); ) {
        // An graphData entry can be a URI or a [ ut ... ; rdfs:label "foo" ] ;
        Statement stmt = cIter.next();
        Resource gn = stmt.getResource();
        if (gn.isAnon()) {
            if (!gn.hasProperty(TestManifestUpdate_11.graph))
                System.err.println("No data for graphData");
            String fn = gn.getProperty(TestManifestUpdate_11.graph).getResource().getURI();
            String name = gn.getProperty(RDFS.label).getString();
            Model m = FileManager.get().loadModel(fn);
            ds.addNamedModel(name, m);
        } else {
            String x = gn.getURI();
            Model m = FileManager.get().loadModel(x);
            ds.addNamedModel(x, m);
        }
    }
    cIter.close();
    return ds;
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 28 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class UpdateTest method getAll.

static List<String> getAll(Resource r, Property p) {
    List<String> l = new ArrayList<>();
    ClosableIterator<Statement> cIter = r.listProperties(p);
    for (; cIter.hasNext(); ) {
        Statement stmt = cIter.next();
        String df = stmt.getObject().asResource().getURI();
        l.add(df);
    }
    cIter.close();
    return l;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 29 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelEvents method testAddSingleStatements.

public void testAddSingleStatements() {
    final Statement S1 = ModelHelper.statement(model, "S P O");
    final Statement S2 = ModelHelper.statement(model, "A B C");
    Assert.assertFalse(SL.has(new Object[] { "add", S1 }));
    model.register(SL);
    model.add(S1);
    SL.assertHas(new Object[] { "add", S1 });
    model.add(S2);
    SL.assertHas(new Object[] { "add", S1, "add", S2 });
    model.add(S1);
    SL.assertHas(new Object[] { "add", S1, "add", S2, "add", S1 });
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Example 30 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelEvents method testTwoListeners.

public void testTwoListeners() {
    final Statement S = ModelHelper.statement(model, "S P O");
    final RecordingModelListener SL1 = new RecordingModelListener();
    final RecordingModelListener SL2 = new RecordingModelListener();
    model.register(SL1).register(SL2);
    model.add(S);
    SL2.assertHas(new Object[] { "add", S });
    SL1.assertHas(new Object[] { "add", S });
}
Also used : Statement(org.apache.jena.rdf.model.Statement) RecordingModelListener(org.apache.jena.rdf.model.test.helpers.RecordingModelListener)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)37 Model (org.apache.jena.rdf.model.Model)17 Resource (org.apache.jena.rdf.model.Resource)14 Test (org.junit.Test)9 StmtIterator (org.apache.jena.rdf.model.StmtIterator)7 ArrayList (java.util.ArrayList)6 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Triple (org.apache.jena.graph.Triple)6 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Property (org.apache.jena.rdf.model.Property)3 IOException (java.io.IOException)2 Dataset (org.apache.jena.query.Dataset)2 TextIndexException (org.apache.jena.query.text.TextIndexException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Files.createTempFile (java.nio.file.Files.createTempFile)1 Path (java.nio.file.Path)1