public Union union( Graph X ) { return new Union( this, X ); }
/** To find in the union, find in the components, concatenate the results, and omit duplicates. That last is a performance penalty, but I see no way to remove it unless we know the graphs do not overlap. */ @Override protected ExtendedIterator<Triple> _graphBaseFind( final Triple t ) { Set<Triple> seen = CollectionFactory.createHashedSet(); return recording( L.find( t ), seen ).andThen( rejecting( R.find( t ), seen ) ); // return L.find( t ) .andThen( rejecting( R.find( t ), L ) ); } }
@ContractTest public void testUnion() { Graph g1 = graphWith("x R y; p R q"); Graph g2 = graphWith("r Foo s; x R y"); Union u = new Union(g1, g2); assertContains("Union", "x R y", u); assertContains("Union", "p R q", u); assertContains("Union", "r Foo s", u); if (u.size() != 3) fail("oops: size of union is not 3"); u.add(triple("cats eat cheese")); assertContains("Union", "cats eat cheese", u); if (contains(g1, "cats eat cheese") == false && contains(g2, "cats eat cheese") == false) fail("oops: neither g1 nor g2 contains `cats eat cheese`"); }
public void testAdd() { Graph l = graphWith( "x R y" ); Graph r = graphWith( "x R y; p S q" ); Union u = new Union( l, r ); u.add( triple("x R y") ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.add( triple("p S q") ); assertIsomorphic( graphWith( "x R y; p S q" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.add( triple("r A s") ); assertIsomorphic( graphWith( "x R y; p S q; r A s" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); }
public void testDelete() { Graph l = graphWith( "x R y; x R z" ); Graph r = graphWith( "x R y; p S q" ); Union u = new Union( l, r ); u.delete( triple( "r A s" ) ); assertIsomorphic( graphWith( "x R y; x R z" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.delete( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.delete( triple ( "p S q" ) ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y" ), r); u.delete( triple ( "x R y" ) ); assertIsomorphic( graphWith( "" ), l); assertIsomorphic( graphWith( "" ), r); } }
/** * test that a union model is a model over the union of the two underlying * graphs. (We don't check that Union works - that's done in the Union * tests, we hope.) */ public void testCreateUnion() { final Model m1 = ModelFactory.createDefaultModel(); final Model m2 = ModelFactory.createDefaultModel(); final Model m = ModelFactory.createUnion(m1, m2); JenaTestBase.assertInstanceOf(Union.class, m.getGraph()); Assert.assertSame(m1.getGraph(), ((Union) m.getGraph()).getL()); Assert.assertSame(m2.getGraph(), ((Union) m.getGraph()).getR()); }
@ContractTest public void testUnion() { Graph g1 = graphWith("x R y; p R q"); Graph g2 = graphWith("r Foo s; x R y"); Union u = new Union(g1, g2); assertContains("Union", "x R y", u); assertContains("Union", "p R q", u); assertContains("Union", "r Foo s", u); if (u.size() != 3) fail("oops: size of union is not 3"); u.add(triple("cats eat cheese")); assertContains("Union", "cats eat cheese", u); if (contains(g1, "cats eat cheese") == false && contains(g2, "cats eat cheese") == false) fail("oops: neither g1 nor g2 contains `cats eat cheese`"); }
public void testAdd() { Graph l = graphWith( "x R y" ); Graph r = graphWith( "x R y; p S q" ); Union u = new Union( l, r ); u.add( triple("x R y") ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.add( triple("p S q") ); assertIsomorphic( graphWith( "x R y; p S q" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.add( triple("r A s") ); assertIsomorphic( graphWith( "x R y; p S q; r A s" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); }
public void testDelete() { Graph l = graphWith( "x R y; x R z" ); Graph r = graphWith( "x R y; p S q" ); Union u = new Union( l, r ); u.delete( triple( "r A s" ) ); assertIsomorphic( graphWith( "x R y; x R z" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.delete( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y; p S q" ), r); u.delete( triple ( "p S q" ) ); assertIsomorphic( graphWith( "x R y" ), l); assertIsomorphic( graphWith( "x R y" ), r); u.delete( triple ( "x R y" ) ); assertIsomorphic( graphWith( "" ), l); assertIsomorphic( graphWith( "" ), r); } }
/** * test that a union model is a model over the union of the two underlying * graphs. (We don't check that Union works - that's done in the Union * tests, we hope.) */ public void testCreateUnion() { final Model m1 = ModelFactory.createDefaultModel(); final Model m2 = ModelFactory.createDefaultModel(); final Model m = ModelFactory.createUnion(m1, m2); JenaTestBase.assertInstanceOf(Union.class, m.getGraph()); Assert.assertSame(m1.getGraph(), ((Union) m.getGraph()).getL()); Assert.assertSame(m2.getGraph(), ((Union) m.getGraph()).getR()); }
public Union union( Graph X ) { return new Union( this, X ); }
/** To find in the union, find in the components, concatenate the results, and omit duplicates. That last is a performance penalty, but I see no way to remove it unless we know the graphs do not overlap. */ @Override protected ExtendedIterator<Triple> _graphBaseFind( final Triple t ) { Set<Triple> seen = CollectionFactory.createHashedSet(); return recording( L.find( t ), seen ).andThen( rejecting( R.find( t ), seen ) ); // return L.find( t ) .andThen( rejecting( R.find( t ), L ) ); } }
public UnionTest() { graphProducer = new AbstractGraphProducer<Union>() { private Map<Graph, Graph[]> map = new HashMap<>(); @Override protected Union createNewGraph() { Graph[] g = { memGraph(), memGraph() }; Union u = new Union(g[0], g[1]); map.put(u, g); return u; } @Override public Graph[] getDependsOn(Graph d) { Graph[] dg = map.get(d); if (dg == null) { throw new IllegalStateException("graph not in map"); } return dg; } @Override public Graph[] getNotDependsOn(Graph g) { return new Graph[] { memGraph() }; } @Override protected void afterClose(Graph g) { map.remove(g); } }; }
public UnionTest() { graphProducer = new AbstractGraphProducer<Union>() { private Map<Graph, Graph[]> map = new HashMap<>(); @Override protected Union createNewGraph() { Graph[] g = { memGraph(), memGraph() }; Union u = new Union(g[0], g[1]); map.put(u, g); return u; } @Override public Graph[] getDependsOn(Graph d) { Graph[] dg = map.get(d); if (dg == null) { throw new IllegalStateException("graph not in map"); } return dg; } @Override public Graph[] getNotDependsOn(Graph g) { return new Graph[] { memGraph() }; } @Override protected void afterClose(Graph g) { map.remove(g); } }; }
/** Answer a new model that is the dynamic union of two other models. By <i>dynamic union</i>, we mean that changes to either <code>m1</code> or <code>m2</code> will be reflected in the result model, and <i>vice versa</i>: specifically, additions to and removals from the union will be implemented as operations on <code>m1</code> <strong>only</strong>. See also the behaviour of OntModel and the MultiUnion class. <p> <code>createUnion</code> only creates two-element unions. */ public static Model createUnion(Model m1, Model m2) { return createModelForGraph( new Union( m1.getGraph(), m2.getGraph() ) ); }
/** Answer a new model that is the dynamic union of two other models. By <i>dynamic union</i>, we mean that changes to either <code>m1</code> or <code>m2</code> will be reflected in the result model, and <i>vice versa</i>: specifically, additions to and removals from the union will be implemented as operations on <code>m1</code> <strong>only</strong>. See also the behaviour of OntModel and the MultiUnion class. <p> <code>createUnion</code> only creates two-element unions. */ public static Model createUnion(Model m1, Model m2) { return createModelForGraph( new Union( m1.getGraph(), m2.getGraph() ) ); }
@Override protected Union createNewGraph() { Graph[] g = { memGraph(), memGraph() }; Union u = new Union(g[0], g[1]); map.put(u, g); return u; }
@Override protected Union createNewGraph() { Graph[] g = { memGraph(), memGraph() }; Union u = new Union(g[0], g[1]); map.put(u, g); return u; }
@Override Graph getGraph() { return new Union(Factory.createGraphMem(), Factory.createGraphMem()); }};
@Override public Graph getGraph() { Graph gBase = graphWith( "" ), g1 = graphWith( "" ); return new Union( gBase, g1 ); }