JsonLDWriter extends WriterDatasetRIOTBase { static Object createJsonldContext(Graph g) { return createJsonldContext(g, PrefixMapFactory.create(g.getPrefixMapping()), true); } JsonLDWriter(RDFFormat syntaxForm); @Override Lang getLang(); @Override void write(Writer out, DatasetGraph dataset, PrefixMap prefixMap, String baseURI, Context context); @Override void write(OutputStream out, DatasetGraph dataset, PrefixMap prefixMap, String baseURI, Context context); static Object toJsonLDJavaAPI(RDFFormat.JSONLDVariant variant, DatasetGraph dataset, PrefixMap prefixMap, String baseURI, Context jenaContext); static final Symbol JSONLD_CONTEXT; static final Symbol JSONLD_CONTEXT_SUBSTITUTION; static final Symbol JSONLD_FRAME; static final Symbol JSONLD_OPTIONS; static final Symbol JSONLD_ADD_ALL_PREFIXES_TO_CONTEXT; }
@Test public void testSettingContextAsObjectExpectedByJsonldAPI() { String ns = "http: Model m = simpleModel(ns); m.setNsPrefix("ex", ns); String s1 = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, null); String prefixStringInResult = "\"ex\":\"" + ns + "\""; assertTrue(s1.contains(prefixStringInResult)); Model m1 = parse(s1); Object ctx = JsonLDWriter.createJsonldContext(m.getGraph()); m.removeNsPrefix("ex"); String s2 = toString(m, RDFFormat.JSONLD_COMPACT_PRETTY, null); assertFalse(s2.contains(prefixStringInResult)); Context jenaCtx = new Context(); jenaCtx.set(JsonLDWriter.JSONLD_CONTEXT, ctx); String s3 = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx); assertTrue(s3.length() == s1.length()); assertTrue(s3.contains(prefixStringInResult)); Model m3 = parse(s3); assertTrue(m3.isIsomorphicWith(m)); assertTrue(m3.isIsomorphicWith(m1)); }