Search in sources :

Example 1 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class ExJsonLD method write.

/**
     * Write RDF data as JSON-LD.
     * 
     * To get more control about the output,
     * we have to use a mechanism provided by jena to pass information
     * to the writing process (cf. org.apache.jena.riot.WriterDatasetRIOT and the "Context" mechanism).
     * For that, we have to create a WriterDatasetRIOT (a one-time use object)
     * and we pass a "Context" object (not to be confused with the "@context" in JSON-LD) as argument to its write method
     * 
     * @param out
     * @param f RDFFormat of the output, eg. RDFFormat.JSONLD_COMPACT_PRETTY
     * @param g the data that we want to output as JSON-LD
     * @param ctx the object that allows to control the writing process (a set of parameters)
     */
void write(OutputStream out, DatasetGraph g, RDFFormat f, Context ctx) {
    // create a WriterDatasetRIOT with the RDFFormat
    WriterDatasetRIOT w = RDFDataMgr.createDatasetWriter(f);
    PrefixMap pm = RiotLib.prefixMap(g);
    String base = null;
    w.write(out, g, pm, base, ctx);
}
Also used : WriterDatasetRIOT(org.apache.jena.riot.WriterDatasetRIOT) PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 2 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class BinRDF method protocolToStream.

/**
     * Decode the contents of the TProtocol and send to the {@link StreamRDF}.
     * @param protocol TProtocol
     * @param dest Sink
     */
public static void protocolToStream(TProtocol protocol, StreamRDF dest) {
    PrefixMap pmap = PrefixMapFactory.create();
    final Thrift2StreamRDF s = new Thrift2StreamRDF(pmap, dest);
    dest.start();
    // ** Java8
    //apply(protocol, z -> TRDF.visit(z, s)) ;
    applyVisitor(protocol, s);
    dest.finish();
// No need to flush - we read from the protocol ; 
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 3 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class TestPrefixLib method expand_2.

@Test
public void expand_2() {
    PrefixMap prefixes = create();
    prefixes.add(pref1, "http://example.net/ns#");
    String x2 = PrefixLib.expand(prefixes, "pref1z:abc");
    assertNull(x2);
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) Test(org.junit.Test)

Example 4 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class TestPrefixLib method abbrev_2.

@Test
public void abbrev_2() {
    PrefixMap prefixes = create();
    prefixes.add(pref1, "http://example.net/ns#");
    Pair<String, String> x = PrefixLib.abbrev(prefixes, "http://other/ns#xyz");
    assertNull(x);
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) Test(org.junit.Test)

Example 5 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class TestPrefixLib method expand_1.

@Test
public void expand_1() {
    PrefixMap prefixes = create();
    prefixes.add(pref1, "http://example.net/ns#");
    String x = PrefixLib.expand(prefixes, "pref1:abc");
    assertEquals("http://example.net/ns#abc", x);
    String x2 = PrefixLib.expand(prefixes, "pref1z:abc");
    assertNull(x2);
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) Test(org.junit.Test)

Aggregations

PrefixMap (org.apache.jena.riot.system.PrefixMap)33 Test (org.junit.Test)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 Map (java.util.Map)3 Node (org.apache.jena.graph.Node)2 QueryCancelledException (org.apache.jena.query.QueryCancelledException)2 QueryExecException (org.apache.jena.query.QueryExecException)2 NodeFormatter (org.apache.jena.riot.out.NodeFormatter)2 NodeFormatterTTL (org.apache.jena.riot.out.NodeFormatterTTL)2 JsonLdApi (com.github.jsonldjava.core.JsonLdApi)1 JsonLdOptions (com.github.jsonldjava.core.JsonLdOptions)1 RDFDataset (com.github.jsonldjava.core.RDFDataset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Iter (org.apache.jena.atlas.iterator.Iter)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonString (org.apache.jena.atlas.json.JsonString)1 StoragePrefixes (org.apache.jena.dboe.storage.StoragePrefixes)1