Search in sources :

Example 91 with Model

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

the class QueryExecUtils method doDescribeQuery.

private static void doDescribeQuery(Prologue prologue, QueryExecution qe, ResultsFormat outputFormat) {
    if (outputFormat == null || outputFormat == ResultsFormat.FMT_UNKNOWN)
        outputFormat = ResultsFormat.FMT_RDF_TTL;
    Model r = qe.execDescribe();
    writeModel(prologue, r, outputFormat);
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 92 with Model

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

the class TestRiotWriterGraph method test.

private void test(String filename) {
    String displayname = filename.substring(0, filename.lastIndexOf('.'));
    Model m = readModel(filename);
    Lang lang = format.getLang();
    WriterGraphRIOT rs = RDFWriterRegistry.getWriterGraphFactory(format).create(format);
    assertEquals(lang, rs.getLang());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    RDFDataMgr.write(out, m, format);
    if (lang == Lang.RDFNULL)
        return;
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    String s = StrUtils.fromUTF8bytes(out.toByteArray());
    Model m2 = ModelFactory.createDefaultModel();
    try {
        RDFDataMgr.read(m2, in, lang);
    } catch (RiotException ex) {
        System.out.println(format);
        System.out.println(s);
        throw ex;
    }
    boolean b = m.isIsomorphicWith(m2);
    if (!b) {
        System.out.println("------[" + format + "]---------------------------------------------------");
        System.out.println("#### file=" + displayname);
        System.out.print(s);
    }
    assertTrue("Did not round-trip file=" + filename + " / format=" + format, b);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.apache.jena.rdf.model.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 93 with Model

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

the class TestTurtleWriter method blankNodeLang.

/** Read in N-Triples data, which is not empty,
     *  then write-read-compare using the format given.
     *  
     * @param testdata
     * @param lang
     */
static void blankNodeLang(String testdata, RDFFormat lang) {
    StringReader r = new StringReader(testdata);
    Model m = ModelFactory.createDefaultModel();
    RDFDataMgr.read(m, r, null, RDFLanguages.NTRIPLES);
    Assert.assertTrue(m.size() > 0);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    RDFDataMgr.write(output, m, lang);
    ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
    Model m2 = ModelFactory.createDefaultModel();
    RDFDataMgr.read(m2, input, lang.getLang());
    Assert.assertTrue(m2.size() > 0);
    Assert.assertTrue(m.isIsomorphicWith(m2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) Model(org.apache.jena.rdf.model.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 94 with Model

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

the class FileManager method loadModelWorker.

private Model loadModelWorker(String filenameOrURI, String baseURI, String rdfSyntax) {
    if (hasCachedModel(filenameOrURI)) {
        if (log.isDebugEnabled())
            log.debug("Model cache hit: " + filenameOrURI);
        return getFromCache(filenameOrURI);
    }
    Model m = ModelFactory.createDefaultModel();
    readModelWorker(m, filenameOrURI, baseURI, rdfSyntax);
    if (isCachingModels())
        addCacheModel(filenameOrURI, m);
    return m;
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 95 with Model

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

the class TestImportManager method testBadImportObjectFails.

private void testBadImportObjectFails(String object) {
    String string = "x ja:imports " + object;
    Model m = model(string);
    try {
        new ImportManager().withImports(m);
        fail("should trap bad import specification " + string);
    } catch (BadObjectException e) {
        assertEquals(resource("x"), e.getRoot());
        assertEquals(rdfNode(m, object), e.getObject());
    }
}
Also used : Model(org.apache.jena.rdf.model.Model)

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