Search in sources :

Example 36 with Model

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

the class AbstractCompressedWholeFileTripleInputFormatTests method generateMixedTuples.

@Override
protected final void generateMixedTuples(OutputStream output, int num) throws IOException {
    // Write good data
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num / 2; i++) {
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    this.writeTuples(m, output);
    // Write junk data
    byte[] junk = "junk data\n".getBytes(utf8);
    for (int i = 0; i < num / 2; i++) {
        output.write(junk);
    }
    output.flush();
    output.close();
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 37 with Model

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

the class TestQuery method query_describe_01.

@Test
public void query_describe_01() {
    String query = "DESCRIBE ?s WHERE {?s ?p ?o}";
    try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
        Model result = qExec.execDescribe();
        assertFalse(result.isEmpty());
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Example 38 with Model

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

the class TestQuery method query_construct_02.

@Test
public void query_construct_02() {
    String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
    try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
        Model result = qExec.execConstruct();
        assertEquals(1, result.size());
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Example 39 with Model

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

the class TestQuery method query_describe_conneg.

@Test
public void query_describe_conneg() throws IOException {
    try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
        String query = "DESCRIBE ?s WHERE {?s ?p ?o}";
        for (MediaType type : rdfOfferTest.entries()) {
            String contentType = type.toHeaderString();
            try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
                qExec.setModelContentType(contentType);
                qExec.setClient(client);
                Model m = qExec.execDescribe();
                String x = qExec.getHttpResponseContentType();
                assertEquals(contentType, x);
                assertFalse(m.isEmpty());
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Model(org.apache.jena.rdf.model.Model) MediaType(org.apache.jena.atlas.web.MediaType) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Example 40 with Model

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

the class TestDatasetAccessorHTTP method post_01.

@Test
public void post_01() {
    DatasetAccessor du = connectToService();
    du.putModel(model1);
    // POST appends
    du.add(model2);
    Model graph = du.getModel();
    Model graph3 = ModelFactory.createDefaultModel();
    graph3.add(model1);
    graph3.add(model2);
    assertFalse(graph.isIsomorphicWith(model1));
    assertFalse(graph.isIsomorphicWith(model2));
    assertTrue(graph.isIsomorphicWith(graph3));
    // Empty it.
    du.deleteDefault();
    graph = du.getModel();
    assertTrue(graph.isEmpty());
}
Also used : Model(org.apache.jena.rdf.model.Model) DatasetAccessor(org.apache.jena.query.DatasetAccessor) Test(org.junit.Test) AbstractFusekiTest(org.apache.jena.fuseki.AbstractFusekiTest) FusekiTest(org.apache.jena.fuseki.FusekiTest)

Aggregations

Model (org.apache.jena.rdf.model.Model)920 Test (org.junit.Test)338 Dataset (org.apache.jena.query.Dataset)196 Resource (org.apache.jena.rdf.model.Resource)178 StringReader (java.io.StringReader)66 Statement (org.apache.jena.rdf.model.Statement)54 Property (org.apache.jena.rdf.model.Property)45 InfModel (org.apache.jena.rdf.model.InfModel)41 Ignore (org.junit.Ignore)38 RDFNode (org.apache.jena.rdf.model.RDFNode)35 Node (org.apache.jena.graph.Node)34 URI (java.net.URI)33 Graph (org.apache.jena.graph.Graph)33 QueryExecution (org.apache.jena.query.QueryExecution)31 Reader (java.io.Reader)30 StmtIterator (org.apache.jena.rdf.model.StmtIterator)27 RDFReaderI (org.apache.jena.rdf.model.RDFReaderI)25 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)24 RdfUtils (won.protocol.util.RdfUtils)24 InputStream (java.io.InputStream)22