/** * Return true if a given graph is an inference graph * @param g A graph * @return True if the graph is an inference graph, or is a union with an inference * base graph */ public boolean isInferenceGraph( Graph g ) { return (g instanceof InfGraph) || (g instanceof Polyadic && ((Polyadic) g).getBaseGraph() instanceof InfGraph); } }
private static String polyadicGraphToString(Polyadic poly) { Graph baseGraph = poly.getBaseGraph(); List<Graph> subGraphs = poly.getSubGraphs(); return simpleName(poly) + "[" + hashHex(poly) + ", base=" + graphToString(baseGraph) + ", subgraphs=" + subGraphsToString(subGraphs, baseGraph) + "]"; }
@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; }
public void testUpdatesOverridden() { g1.getPrefixMapping().setNsPrefix( "x", alpha ); poly.getPrefixMapping().setNsPrefix( "x", beta ); assertEquals( beta, poly.getPrefixMapping().getNsPrefixURI( "x" ) ); }
@Override public void setUp() { gBase = Factory.createDefaultGraph(); g1 = Factory.createDefaultGraph(); g2 = Factory.createDefaultGraph(); poly = new MultiUnion( new Graph[] {gBase, g1, g2} ); poly.setBaseGraph( gBase ); }
@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; }
/** 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 ) ); }
@Override public void setUp() { gBase = Factory.createDefaultGraph(); g1 = Factory.createDefaultGraph(); g2 = Factory.createDefaultGraph(); poly = new MultiUnion( new Graph[] {gBase, g1, g2} ); poly.setBaseGraph( gBase ); }
/** * Return true if a given graph is an inference graph * @param g A graph * @return True if the graph is an inference graph, or is a union with an inference * base graph */ public boolean isInferenceGraph( Graph g ) { return (g instanceof InfGraph) || (g instanceof Polyadic && ((Polyadic) g).getBaseGraph() instanceof InfGraph); } }
private void collectLeafGraphs(final Graph graph, final Set<Graph> prevLeaves) { if (graph instanceof Polyadic) { final Polyadic union = (Polyadic) graph; if (union.getBaseGraph() != null) collectLeafGraphs(union.getBaseGraph(), prevLeaves); for (final Graph graph2 : union.getSubGraphs()) collectLeafGraphs(graph2, prevLeaves); } else if (graph instanceof Dyadic) { final Dyadic dyadic = (Dyadic) graph; if (dyadic.getL() instanceof Graph) collectLeafGraphs((Graph) dyadic.getL(), prevLeaves); if (dyadic.getR() instanceof Graph) collectLeafGraphs((Graph) dyadic.getR(), prevLeaves); } else if (graph instanceof InfGraph) collectLeafGraphs(((InfGraph) graph).getRawGraph(), prevLeaves); else if (_leafGraphs.add(graph) && !prevLeaves.contains(graph)) { _changedGraphs.add(graph); graph.getEventManager().register(this); } }
/** Compress the URI using the prefix mapping. This version of the code looks through all the maplets and checks each candidate prefix URI for being a leading substring of the argument URI. There's probably a much more efficient algorithm available, preprocessing the prefix strings into some kind of search table, but for the moment we don't need it. */ @Override public String shortForm( String uri ) { String s = getBaseMapping().shortForm( uri ); if (s.equals( uri )) { List<Graph> graphs = poly.getSubGraphs(); for ( Graph graph : graphs ) { String ss = graph.getPrefixMapping().shortForm( uri ); if ( !ss.equals( uri ) ) { return ss; } } } return s; }
public void testUpdatesOverridden() { g1.getPrefixMapping().setNsPrefix( "x", alpha ); poly.getPrefixMapping().setNsPrefix( "x", beta ); assertEquals( beta, poly.getPrefixMapping().getNsPrefixURI( "x" ) ); }
/** * <p> * Answer a list of the graphs other than the updateable (base) graph * </p> * * @return A list of all of the sub-graphs, excluding the base graph. */ public List<Graph> getSubGraphs() { List<Graph> sg = new ArrayList<>( m_subGraphs ); if (getBaseGraph() != null) { sg.remove( getBaseGraph() ); } return sg; }
private void collectLeafGraphs(final Graph graph, final Set<Graph> prevLeaves) { if (graph instanceof Polyadic) { final Polyadic union = (Polyadic) graph; if (union.getBaseGraph() != null) collectLeafGraphs(union.getBaseGraph(), prevLeaves); for (final Graph graph2 : union.getSubGraphs()) collectLeafGraphs(graph2, prevLeaves); } else if (graph instanceof Dyadic) { final Dyadic dyadic = (Dyadic) graph; if (dyadic.getL() instanceof Graph) collectLeafGraphs((Graph) dyadic.getL(), prevLeaves); if (dyadic.getR() instanceof Graph) collectLeafGraphs((Graph) dyadic.getR(), prevLeaves); } else if (graph instanceof InfGraph) collectLeafGraphs(((InfGraph) graph).getRawGraph(), prevLeaves); else if (_leafGraphs.add(graph) && !prevLeaves.contains(graph)) { _changedGraphs.add(graph); graph.getEventManager().register(this); } }
/** Compress the URI using the prefix mapping. This version of the code looks through all the maplets and checks each candidate prefix URI for being a leading substring of the argument URI. There's probably a much more efficient algorithm available, preprocessing the prefix strings into some kind of search table, but for the moment we don't need it. */ @Override public String shortForm( String uri ) { String s = getBaseMapping().shortForm( uri ); if (s.equals( uri )) { List<Graph> graphs = poly.getSubGraphs(); for ( Graph graph : graphs ) { String ss = graph.getPrefixMapping().shortForm( uri ); if ( !ss.equals( uri ) ) { return ss; } } } return s; }
/** 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 ) ); }
/** * <p> * Answer a list of the graphs other than the updateable (base) graph * </p> * * @return A list of all of the sub-graphs, excluding the base graph. */ public List<Graph> getSubGraphs() { List<Graph> sg = new ArrayList<>( m_subGraphs ); if (getBaseGraph() != null) { sg.remove( getBaseGraph() ); } return sg; }
private void collectLeafGraphs(final Graph graph, final Set<Graph> prevLeaves) { if (graph instanceof Polyadic) { final Polyadic union = (Polyadic) graph; if (union.getBaseGraph() != null) collectLeafGraphs(union.getBaseGraph(), prevLeaves); for (final Graph graph2 : union.getSubGraphs()) collectLeafGraphs(graph2, prevLeaves); } else if (graph instanceof Dyadic) { final Dyadic dyadic = (Dyadic) graph; if (dyadic.getL() instanceof Graph) collectLeafGraphs((Graph) dyadic.getL(), prevLeaves); if (dyadic.getR() instanceof Graph) collectLeafGraphs((Graph) dyadic.getR(), prevLeaves); } else if (graph instanceof InfGraph) collectLeafGraphs(((InfGraph) graph).getRawGraph(), prevLeaves); else if (_leafGraphs.add(graph) && !prevLeaves.contains(graph)) { _changedGraphs.add(graph); graph.getEventManager().register(this); } }
/** Expand a prefixed URI. There's an assumption that any URI of the form Head:Tail is subject to mapping if Head is in the prefix mapping. So, if someone takes it into their heads to define eg "http" or "ftp" we have problems. */ @Override public String expandPrefix( String prefixed ) { String s = getBaseMapping().expandPrefix( prefixed ); if (s.equals( prefixed )) { List<Graph> graphs = poly.getSubGraphs(); for ( Graph graph : graphs ) { String ss = graph.getPrefixMapping().expandPrefix( prefixed ); if ( !ss.equals( prefixed ) ) { return ss; } } } return s; }
public void testPolyMapHandlesBase() { g1.getPrefixMapping().setNsPrefix( "", "eh:/U1" ); g2.getPrefixMapping().setNsPrefix( "", "eh:/U2" ); String a = poly.getPrefixMapping().getNsPrefixMap().get( "" ); assertEquals( poly.getPrefixMapping().getNsPrefixURI( "" ), a ); } }