private boolean traverseFrom(String id, String goalid, Set<String> seen) { seen.add(id); if (links.get(id) == null) return false; for (Link link : links.get(id)) { // check that this is a SAME link if (link.getKind() != LinkKind.SAME) continue; // find the ID that is not 'id' (find the ID at the other end) String otherid = link.getID1(); if (otherid.equals(id)) otherid = link.getID2(); // if we haven't seen it, and it's not goalid, keep traversing if (otherid.equals(goalid)) return true; else if (!seen.contains(otherid)) { if (traverseFrom(otherid, goalid, seen)) return true; // found it! // else: keep trying } } return false; }
private boolean traverseFrom(String id, String goalid, Set<String> seen) { seen.add(id); if (links.get(id) == null) return false; for (Link link : links.get(id)) { // check that this is a SAME link if (link.getKind() != LinkKind.SAME) continue; // find the ID that is not 'id' (find the ID at the other end) String otherid = link.getID1(); if (otherid.equals(id)) otherid = link.getID2(); // if we haven't seen it, and it's not goalid, keep traversing if (otherid.equals(goalid)) return true; else if (!seen.contains(otherid)) { if (traverseFrom(otherid, goalid, seen)) return true; // found it! // else: keep trying } } return false; }
public Link inferLink(String id1, String id2) { // FIXME: it's possible that we find inconsistencies here. for now we // ignore that. if we've seen a link between these two IDs then that // means we're not going to ask the user about it. Collection<Link> ourlinks = links.get(id1); if (ourlinks != null) { for (Link link : ourlinks) if (link.getID1().equals(id2) || link.getID2().equals(id2)) return link; // if we get here it means we couldn't find a direct link. move on // to see if we can find an indirect one. } // can we prove that these belong to the same equivalence class? // basically, need to traverse graph outwards from ID1 to see if // we ever get to ID2. if (traverseFrom(id1, id2, new HashSet())) return new Link(id1, id2, LinkStatus.ASSERTED, LinkKind.SAME, 0.0); else return null; }