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);
}
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);
}
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));
}
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;
}
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());
}
}
Aggregations