use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class TestModelAssembler method testGetsPrefixMappings.
public void testGetsPrefixMappings() {
Assembler a = new FakeModelAssembler();
PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("my", "urn:secret:42/").setNsPrefix("your", "urn:public:17#");
Resource root = resourceInModel("x rdf:type ja:DefaultModel; x ja:prefixMapping p1; x ja:prefixMapping p2" + "; p1 rdf:type ja:PrefixMapping; p1 ja:prefix 'my'; p1 ja:namespace 'urn:secret:42/'" + "; p2 rdf:type ja:PrefixMapping; p2 ja:prefix 'your'; p2 ja:namespace 'urn:public:17#'");
Model m = (Model) a.open(Assembler.prefixMapping, root);
assertSamePrefixMapping(wanted, m);
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class PrefixMappingUtils method splitMethod.
// -------------------------------------------
/**
* Assume that prefixes:localName are in the normal places (after/ or #).
* i.e. node.getNameSpace() ; makes sense.
* @param m
*/
private static Set<String> splitMethod(Model m) {
/* Method:
*
* For each URI, split in in the usual place, after "/" or "#" for http URIs, and
* after the last ":" for URNs, then see if that is a declared prefix.
*
* Exit early if every prefix is accounted for.
*/
PrefixMapping prefixMapping = m;
// Map prefix -> URI.
Map<String, String> pmap = prefixMapping.getNsPrefixMap();
// All URIs used as prefixes in the prefix mapping.
Set<String> prefixURIs = new HashSet<>(pmap.values());
// Prefix URIs used.
Set<String> inUsePrefixURIs = new HashSet<>();
Iterator<Triple> iter = m.getGraph().find(null, null, null);
while (iter.hasNext()) {
Triple triple = iter.next();
processBySplit(prefixURIs, inUsePrefixURIs, triple.getSubject());
processBySplit(prefixURIs, inUsePrefixURIs, triple.getPredicate());
processBySplit(prefixURIs, inUsePrefixURIs, triple.getObject());
if (inUsePrefixURIs.size() == prefixURIs.size())
// Fast exit.
break;
}
return inUsePrefixURIs;
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class TestPrefixMappingAssembler method testIncludesSingleMapping.
public void testIncludesSingleMapping() {
PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("pre", "some:prefix/");
Assembler a = new PrefixMappingAssembler();
Resource root = resourceInModel("root rdf:type ja:PrefixMapping; root ja:includes pm" + "; pm rdf:type ja:PrefixMapping; pm ja:prefix 'pre'; pm ja:namespace 'some:prefix/'");
PrefixMapping pm = (PrefixMapping) a.open(root);
assertSamePrefixMapping(wanted, pm);
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class TestPrefixMappingUtils method prefixesN.
@Test
public void prefixesN() {
// All combinations.
// No "@prefix xsd: <"+XSD.getURI()+"> ." so not in output.
String data = StrUtils.strjoinNL("@prefix : <http://example/> .", "@prefix ex: <http://example/ex#> .", "@prefix notinuse: <http://example/whatever/> .", "@prefix indirect: <urn:foo:> .", "@prefix indirectx: <urn:ex:> .", "@prefix ns: <http://host/ns> .", "@prefix ns1: <http://host/ns1> .", "@prefix ns2: <http://host/nspace> .", "", ":s1 :p :x1 .", ":s1 ex:p :x1 .", "<urn:foo:bar> :p 1 . ", "<urn:ex:a:b> :p 2 . ", "<urn:ex:verybad#.> :p 1 . ", "ns:x ns1:p 'ns1' . ", "<http://examp/abberev> indirect:p 'foo' . ");
Graph graph = create(data);
PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph);
PrefixMapping pmapExpected = new PrefixMappingImpl();
pmapExpected.setNsPrefix("", "http://example/");
pmapExpected.setNsPrefix("ex", "http://example/ex#");
pmapExpected.setNsPrefix("indirect", "urn:foo:");
pmapExpected.setNsPrefix("ns", "http://host/ns");
pmapExpected.setNsPrefix("ns1", "http://host/ns1");
pmapExpected.setNsPrefix("indirectx", "urn:ex:");
// print("Expected:", pmapExpected) ;
// print("Got:", pmap) ;
Assert.assertTrue(sameMapping(pmapExpected, pmap));
Assert.assertTrue(pmap.getNsPrefixURI("notinuse") == null);
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class TestPrefixMappingUtils method prefixes4.
@Test
public void prefixes4() {
// No prefixes.
String data = StrUtils.strjoinNL("<http://other/s1> <http://example/p> 123 .");
Graph graph1 = create(data);
PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph1);
Assert.assertEquals(0, size(pmap));
PrefixMapping pmapExpected = new PrefixMappingImpl();
Assert.assertTrue(sameMapping(pmapExpected, pmap));
}
Aggregations