Search in sources :

Example 66 with Model

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

the class QueryTest method createDataset.

private static Dataset createDataset(List<String> defaultGraphURIs, List<String> namedGraphURIs) {
    // Allow "qt:data" to be quads in defaultGraphURIs.
    Dataset ds = DatasetFactory.createGeneral();
    if (defaultGraphURIs != null) {
        for (String sourceURI : defaultGraphURIs) {
            RDFDataMgr.read(ds, sourceURI);
        }
    }
    if (namedGraphURIs != null) {
        for (String sourceURI : namedGraphURIs) {
            String absSourceURI = IRIResolver.resolveString(sourceURI);
            Model m = ds.getNamedModel(absSourceURI);
            RDFDataMgr.read(m, sourceURI);
        }
    }
    return ds;
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model)

Example 67 with Model

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

the class GraphsTests method fillDataset.

protected void fillDataset(Dataset dataset) {
    // Load default model.
    // Load graph 1
    // Load graph 2.
    dataset.getDefaultModel().getGraph().add(SSE.parseTriple("(<x> <p> 'Default graph')"));
    Model m1 = dataset.getNamedModel(graph1);
    m1.getGraph().add(SSE.parseTriple("(<x> <p> 'Graph 1')"));
    m1.getGraph().add(SSE.parseTriple("(<x> <p> 'ZZZ')"));
    Model m2 = dataset.getNamedModel(graph2);
    m2.getGraph().add(SSE.parseTriple("(<x> <p> 'Graph 2')"));
    m2.getGraph().add(SSE.parseTriple("(<x> <p> 'ZZZ')"));
    calcUnion.add(m1);
    calcUnion.add(m2);
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 68 with Model

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

the class QueryTest method compareGraphResults.

private void compareGraphResults(Model resultsActual, Query query) {
    if (results != null) {
        try {
            if (!results.isGraph())
                fail("Expected results are not a graph: " + testItem.getName());
            Model resultsExpected = results.getModel();
            if (!resultsExpected.isIsomorphicWith(resultsActual)) {
                printFailedModelTest(query, resultsExpected, resultsActual);
                fail("Results do not match: " + testItem.getName());
            }
        } catch (Exception ex) {
            String typeName = (query.isConstructType() ? "construct" : "describe");
            fail("Exception in result testing (" + typeName + "): " + ex);
        }
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) QueryException(org.apache.jena.query.QueryException) IOException(java.io.IOException) JenaException(org.apache.jena.shared.JenaException)

Example 69 with Model

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

the class QueryTest method runTestDescribe.

void runTestDescribe(Query query, QueryExecution qe) {
    Model resultsActual = qe.execDescribe();
    compareGraphResults(resultsActual, query);
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 70 with Model

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

the class TestUpdateOperations method insert_where_01.

@Test
public void insert_where_01() {
    Model m = ModelFactory.createDefaultModel();
    Resource anon = m.createResource();
    anon.addProperty(RDF.type, OWL.Thing);
    assertEquals(1, m.size());
    UpdateRequest req = UpdateFactory.create("INSERT { ?s ?p ?o } WHERE { ?o ?p ?s }");
    UpdateAction.execute(req, m);
    assertEquals(2, m.size());
    assertEquals(1, m.listStatements(anon, null, (RDFNode) null).toList().size());
    assertEquals(1, m.listStatements(null, null, anon).toList().size());
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Model (org.apache.jena.rdf.model.Model)444 Test (org.junit.Test)177 BaseTest (org.apache.jena.atlas.junit.BaseTest)96 Resource (org.apache.jena.rdf.model.Resource)87 StringReader (java.io.StringReader)43 Dataset (org.apache.jena.query.Dataset)31 RDFReader (org.apache.jena.rdf.model.RDFReader)30 Property (org.apache.jena.rdf.model.Property)24 DatasetAccessor (org.apache.jena.query.DatasetAccessor)20 InfModel (org.apache.jena.rdf.model.InfModel)20 Node (org.apache.jena.graph.Node)19 Statement (org.apache.jena.rdf.model.Statement)18 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)15 Reader (java.io.Reader)14 JsonString (org.apache.jena.atlas.json.JsonString)14 AbstractFusekiTest (org.apache.jena.fuseki.AbstractFusekiTest)14 FusekiTest (org.apache.jena.fuseki.FusekiTest)14 Graph (org.apache.jena.graph.Graph)14 JenaException (org.apache.jena.shared.JenaException)14 Triple (org.apache.jena.graph.Triple)13