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