Refine search
private PrefixMapping ensureRDFPrefix(PrefixMapping prefixes) { // Some prefix already registered for the RDF namespace -- good enough if (prefixes.getNsURIPrefix(RDF.getURI()) != null) return prefixes; // rdf: is registered to something else -- give up if (prefixes.getNsPrefixURI("rdf") != null) return prefixes; // Register rdf: PrefixMapping newPrefixes = new PrefixMappingImpl(); newPrefixes.setNsPrefixes(prefixes); newPrefixes.setNsPrefix("rdf", RDF.getURI()); return newPrefixes; } }
@Override public Map<String, String> getNsPrefixMap() { Map<String, String> result = CollectionFactory.createHashedMap(); List<Graph> graphs = poly.getSubGraphs(); for (int i = graphs.size(); i > 0;) result.putAll( graphs.get( --i ).getPrefixMapping().getNsPrefixMap() ); result.remove( "" ); result.putAll( getBaseMapping().getNsPrefixMap() ); return result; }
/** * Expand qnames to URIs. If the given URI appears * to start with one of the registered prefixes then * expand the prefix, otherwise return the original URI */ public static String expandQname(String uri) { return prefixMapping.expandPrefix( uri ); }
/** * Set the default prefix mappings. */ protected void setDefaultPrefixMappings() { m_prefixMap.setNsPrefixes( PrefixMapping.Standard ); // PrefixMapping.Standard includes dc:, which OntModels traditionally haven't included m_prefixMap.removeNsPrefix( "dc" ); }
/** @see org.apache.jena.shared.PrefixMapping#removeNsPrefix(java.lang.String) */ @Override public PrefixMapping removeNsPrefix(String prefix) { pmapLocal.removeNsPrefix(prefix) ; if ( pmapGlobal != null && pmapGlobal.getNsPrefixURI(prefix) != null ) throw new UnsupportedOperationException("PrefixMapping2: prefix '"+prefix+"' in the immutable map") ; return this ; }
public void testPolyDoesntSeeImportedDefaultPrefix() { String imported = "http://imported#"; g1.getPrefixMapping().setNsPrefix( "", imported ); assertEquals( null, poly.getPrefixMapping().getNsPrefixURI( "" ) ); }
public void testPolyMapHandlesBase() { g1.getPrefixMapping().setNsPrefix( "", "eh:/U1" ); g2.getPrefixMapping().setNsPrefix( "", "eh:/U2" ); String a = poly.getPrefixMapping().getNsPrefixMap().get( "" ); assertEquals( poly.getPrefixMapping().getNsPrefixURI( "" ), a ); } }
@Test public void prefix7() { String uri1 = "http://example/" ; String uri2 = "http://example/ns#" ; PrefixMapping pmap = create() ; pmap.setNsPrefix("ex1", uri1) ; pmap.setNsPrefix("ex2", uri2) ; assertEquals("ex2:foo", pmap.qnameFor("http://example/ns#foo")) ; }
public void testPolyMapOverridesFromTheLeft() { g1.getPrefixMapping().setNsPrefix( "a", "eh:/U1" ); g2.getPrefixMapping().setNsPrefix( "a", "eh:/U2" ); String a = poly.getPrefixMapping().getNsPrefixMap().get( "a" ); assertEquals( "eh:/U1", a ); }
private PrefixMapping getPrefixMapping() { PrefixMapping pmap = new PrefixMappingImpl() ; pmap.setNsPrefix("zz", aUri) ; return pmap ; }
public void testReturnsSelf() { PrefixMapping A = getMapping(); assertSame( A, A.setNsPrefix( "crisp", crispURI ) ); assertSame( A, A.setNsPrefixes( A ) ); assertSame( A, A.setNsPrefixes( new HashMap<String, String>() ) ); assertSame( A, A.removeNsPrefix( "rhubarb" ) ); }
/** Test that the default namespace of a sub-graph doesn't appear as a default namespace of the polyadic graph. */ public void testSubgraphsDontPolluteDefaultPrefix() { String imported = "http://imported#", local = "http://local#"; g1.getPrefixMapping().setNsPrefix( "", imported ); poly.getPrefixMapping().setNsPrefix( "", local ); assertEquals( null, poly.getPrefixMapping().getNsURIPrefix( imported ) ); }
public void testQNameComponents() { g1.getPrefixMapping().setNsPrefix( "x", alpha ); g2.getPrefixMapping().setNsPrefix( "y", beta ); assertEquals( "x:hoop", poly.getPrefixMapping().qnameFor( alpha + "hoop" ) ); assertEquals( "y:lens", poly.getPrefixMapping().qnameFor( beta + "lens" ) ); }
public void testSecondPrefixReplacesReverseMap() { PrefixMapping A = getMapping(); A.setNsPrefix( "a", crispURI ); A.setNsPrefix( "b", crispURI ); assertEquals( "b", A.getNsURIPrefix( crispURI ) ); }
@Override protected PrefixMapping createPrefixMapping() { PrefixMapping pmap = new PrefixMappingImpl() ; forEachGraph((g) -> { PrefixMapping pmapNamedGraph = g.getPrefixMapping() ; pmap.setNsPrefixes(pmapNamedGraph) ; }) ; return pmap ; }
public void testRemovePrefix() { String hURI = "http://test.remove.prefixes/prefix#"; String bURI = "http://other.test.remove.prefixes/prefix#"; PrefixMapping A = getMapping(); A.setNsPrefix( "hr", hURI ); A.setNsPrefix( "br", bURI ); A.removeNsPrefix( "hr" ); assertEquals( null, A.getNsPrefixURI( "hr" ) ); assertEquals( bURI, A.getNsPrefixURI( "br" ) ); }
@Test public void load_graph_06() { DatasetGraphTDB dsg = fresh() ; GraphTDB graph = dsg.getGraphTDB(g) ; TDBLoader.load(graph, DIR + "data-4.ttl", false) ; String uri1 = dsg.getGraph(g).getPrefixMapping().getNsPrefixURI("") ; assertEquals("http://example/", uri1) ; String uri2 = dsg.getDefaultGraph().getPrefixMapping().getNsPrefixURI("") ; assertNull(uri2) ; } }
/** Add triples into the destination (arg 1) from the source (arg 2)*/ public static void addInto(Graph dstGraph, Graph srcGraph ) { if ( dstGraph == srcGraph && ! dstGraph.getEventManager().listening() ) return ; dstGraph.getPrefixMapping().setNsPrefixes(srcGraph.getPrefixMapping()) ; addIteratorWorker(dstGraph, findAll( srcGraph )); dstGraph.getEventManager().notifyAddGraph( dstGraph, srcGraph ); }
public void testSecondPrefixDeletedUncoversPreviousMap() { PrefixMapping A = getMapping(); A.setNsPrefix( "x", crispURI ); A.setNsPrefix( "y", crispURI ); A.removeNsPrefix( "y" ); assertEquals( "x", A.getNsURIPrefix( crispURI ) ); }
public void testClear() { String hURI = "http://test.remove.prefixes/prefix#"; String bURI = "http://other.test.remove.prefixes/prefix#"; PrefixMapping A = getMapping(); A.setNsPrefix( "hr", hURI ); A.setNsPrefix( "br", bURI ); A.clearNsPrefixMap() ; assertEquals( null, A.getNsPrefixURI( "hr" ) ); assertEquals( null, A.getNsPrefixURI( "br" ) ); assertEquals( null, A.getNsURIPrefix(hURI) ) ; assertEquals( null, A.getNsURIPrefix(bURI) ) ; }