Search in sources :

Example 21 with PrefixMap

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

the class CompactWriter method prefixMapWithStd.

private static PrefixMap prefixMapWithStd(PrefixMapping prefixMapping) {
    PrefixMap pmap = SHACLC.withStandardPrefixes();
    prefixMapping.getNsPrefixMap().forEach((p, u) -> pmap.add(p, u));
    return pmap;
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 22 with PrefixMap

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

the class CompactWriter method formatterPrefixMap.

private static NodeFormatter formatterPrefixMap(PrefixMapping prefixMapping) {
    PrefixMap pmap = prefixMapWithStd(prefixMapping);
    NodeFormatter nodeFmt = new NodeFormatterTTL(null, pmap);
    return nodeFmt;
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) NodeFormatter(org.apache.jena.riot.out.NodeFormatter) NodeFormatterTTL(org.apache.jena.riot.out.NodeFormatterTTL)

Example 23 with PrefixMap

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

the class TestJsonLDWriter method atVocabJENA1292.

/**
 * setting @vocab and replacing @context
 * not really a test, sample code for JENA-1292
 */
@SuppressWarnings("unchecked")
@Test
public final void atVocabJENA1292() throws JsonParseException, JsonLdError, IOException {
    Model m = ModelFactory.createDefaultModel();
    String ns = "http://schema.org/";
    Resource person = m.createResource(ns + "Person");
    Resource s = m.createResource();
    m.add(s, m.createProperty(ns + "name"), "Jane Doe");
    m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
    m.add(s, m.createProperty(ns + "jobTitle"), "Professor");
    m.add(s, FOAF.nick, "jd");
    m.add(s, RDF.type, person);
    m.setNsPrefix("", ns);
    DatasetGraph g = DatasetFactory.wrap(m).asDatasetGraph();
    PrefixMap pm = g.prefixes();
    String base = null;
    Context jenaContext = null;
    // the JSON-LD API object. It's a map
    Map<String, Object> map = (Map<String, Object>) JsonLDWriter.toJsonLDJavaAPI((RDFFormat.JSONLDVariant) RDFFormat.JSONLD.getVariant(), g, pm, base, jenaContext);
    // get the @context:
    Map<String, Object> ctx = (Map<String, Object>) map.get("@context");
    // remove from ctx declaration of props in ns
    List<String> remove = new ArrayList<>();
    for (Entry<String, Object> e : ctx.entrySet()) {
        // is it the declaration of a prop in ns?
        Object o = e.getValue();
        if (o instanceof Map) {
            o = ((Map<String, Object>) o).get("@id");
        }
        if ((o != null) && (o instanceof String)) {
            if (((String) o).equals(ns + e.getKey())) {
                remove.add(e.getKey());
            }
        }
    }
    for (String key : remove) {
        ctx.remove(key);
    }
    // add to ctx the "@vocab" key
    ctx.put("@vocab", "http://schema.org/");
// JsonUtils.writePrettyPrint(new PrintWriter(System.out), map) ;
}
Also used : Context(org.apache.jena.sparql.util.Context) JsonLDWriteContext(org.apache.jena.riot.JsonLDWriteContext) PrefixMap(org.apache.jena.riot.system.PrefixMap) ArrayList(java.util.ArrayList) JsonString(org.apache.jena.atlas.json.JsonString) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) JsonObject(org.apache.jena.atlas.json.JsonObject) PrefixMap(org.apache.jena.riot.system.PrefixMap) Map(java.util.Map) Test(org.junit.Test)

Example 24 with PrefixMap

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

the class StoragePrefixesSimpleMem method get.

@Override
public String get(Node graphNode, String prefix) {
    graphNode = canonicalGraphName(graphNode);
    PrefixMap pmap = map.get(graphNode);
    if (pmap == null)
        return null;
    return pmap.get(prefix);
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 25 with PrefixMap

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

the class StoragePrefixesSimpleMem method get.

@Override
public Iterator<PrefixEntry> get(Node graphNode) {
    graphNode = canonicalGraphName(graphNode);
    PrefixMap pmap = map.get(graphNode);
    if (pmap == null)
        return Iter.nullIterator();
    return pmap.getMapping().entrySet().stream().map(e -> PrefixEntry.create(e.getKey(), e.getValue())).iterator();
}
Also used : PrefixEntry(org.apache.jena.riot.system.PrefixEntry) PrefixMap(org.apache.jena.riot.system.PrefixMap) PrefixMapZero(org.apache.jena.riot.system.PrefixMapZero) Iterator(java.util.Iterator) Node(org.apache.jena.graph.Node) Map(java.util.Map) StoragePrefixes(org.apache.jena.dboe.storage.StoragePrefixes) PrefixLib.canonicalGraphName(org.apache.jena.riot.system.PrefixLib.canonicalGraphName) HashMap(java.util.HashMap) Iter(org.apache.jena.atlas.iterator.Iter) PrefixMapFactory(org.apache.jena.riot.system.PrefixMapFactory) PrefixMap(org.apache.jena.riot.system.PrefixMap)

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