@Test(expected = GraphUtils.NoSuchSubGraphException.class) public void removeIncompleteSubGraph() throws GraphUtils.NoSuchSubGraphException { Graph baseGraph = createBaseGraph(); Graph subGraph = new SimpleGraph(); { BlankNode bNode1 = new BlankNode(); BlankNode bNode2 = new BlankNode(); subGraph.add(new TripleImpl(u1, u2, bNode2)); subGraph.add(new TripleImpl(bNode2, u2, bNode2)); } GraphUtils.removeSubGraph(baseGraph, subGraph); }
public static void removeSubGraph(Graph mGraph, Graph subGraph) throws NoSuchSubGraphException { final Set<Triple> removingTriples = new HashSet<Triple>(); final Graph unGroundedTriples = new SimpleGraph(); for (Triple triple : subGraph) { if (isGrounded(triple)) { if (!mGraph.contains(triple)) { throw new NoSuchSubGraphException(); } removingTriples.add(triple); } else { unGroundedTriples.add(triple); } } OBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples); if (triple == null) { break; } final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples); BlankNodeOrIRI subject = triple.getSubject(); ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue OBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } SUBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples); if (triple == null) { break; } final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples); RDFTerm object = triple.getObject(); if (object instanceof BlankNode) { object = null; } ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue SUBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } mGraph.removeAll(removingTriples); }
GraphUtils { public static void removeSubGraph(Graph mGraph, Graph subGraph) throws NoSuchSubGraphException { final Set<Triple> removingTriples = new HashSet<Triple>(); final Graph unGroundedTriples = new SimpleGraph(); for (Triple triple : subGraph) { if (isGrounded(triple)) { if (!mGraph.contains(triple)) { throw new NoSuchSubGraphException(); } removingTriples.add(triple); } else { unGroundedTriples.add(triple); } } OBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples); if (triple == null) { break; } final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples); BlankNodeOrIRI subject = triple.getSubject(); ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue OBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } SUBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples); if (triple == null) { break; } final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples); RDFTerm object = triple.getObject(); if (object instanceof BlankNode) { object = null; } ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue SUBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } mGraph.removeAll(removingTriples); } }
GraphUtils { public static void removeSubGraph(Graph mGraph, Graph subGraph) throws NoSuchSubGraphException { final Set<Triple> removingTriples = new HashSet<Triple>(); final Graph unGroundedTriples = new SimpleGraph(); for (Triple triple : subGraph) { if (isGrounded(triple)) { if (!mGraph.contains(triple)) { throw new NoSuchSubGraphException(); } removingTriples.add(triple); } else { unGroundedTriples.add(triple); } } OBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples); if (triple == null) { break; } final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples); BlankNodeOrIRI subject = triple.getSubject(); ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue OBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } SUBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples); if (triple == null) { break; } final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples); RDFTerm object = triple.getObject(); if (object instanceof BlankNode) { object = null; } ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue SUBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } mGraph.removeAll(removingTriples); }  }
GraphUtils { public static void removeSubGraph(Graph mGraph, Graph subGraph) throws NoSuchSubGraphException { final Set<Triple> removingTriples = new HashSet<Triple>(); final Graph unGroundedTriples = new SimpleGraph(); for (Triple triple : subGraph) { if (isGrounded(triple)) { if (!mGraph.contains(triple)) { throw new NoSuchSubGraphException(); } removingTriples.add(triple); } else { unGroundedTriples.add(triple); } } OBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples); if (triple == null) { break; } final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples); BlankNodeOrIRI subject = triple.getSubject(); ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue OBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } SUBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples); if (triple == null) { break; } final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples); RDFTerm object = triple.getObject(); if (object instanceof BlankNode) { object = null; } ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue SUBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } mGraph.removeAll(removingTriples); }  static void removeSubGraph(Graph mGraph, Graph subGraph); }
GraphUtils { public static void removeSubGraph(Graph mGraph, Graph subGraph) throws NoSuchSubGraphException { final Set<Triple> removingTriples = new HashSet<Triple>(); final Graph unGroundedTriples = new SimpleGraph(); for (Triple triple : subGraph) { if (isGrounded(triple)) { if (!mGraph.contains(triple)) { throw new NoSuchSubGraphException(); } removingTriples.add(triple); } else { unGroundedTriples.add(triple); } } OBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples); if (triple == null) { break; } final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples); BlankNodeOrIRI subject = triple.getSubject(); ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue OBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } SUBJ_BNODE_LOOP: while (true) { final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples); if (triple == null) { break; } final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples); RDFTerm object = triple.getObject(); if (object instanceof BlankNode) { object = null; } ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { try { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode) potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); continue SUBJ_BNODE_LOOP; } } catch (ClassCastException e) { continue; } } throw new NoSuchSubGraphException(); } mGraph.removeAll(removingTriples); }  static void removeSubGraph(Graph mGraph, Graph subGraph);  }