@Test public void checkNodeMatches() { DependencyTree tree1 = new DependencyTree("pattern_NN"); DependencyTree tree2 = new DependencyTree("pattern_NN:id"); DependencyTree tree3 = new DependencyTree("differentPattern_NN:id"); DependencyTree tree4 = new DependencyTree("pattern_NNP:id"); assertTrue(tree1.matches(tree2)); assertFalse(tree1.matches(tree3)); assertFalse(tree2.matches(tree4)); }
public boolean matches(DependencyTree other) { if (this == other) { return true; } if (other == null) { return false; } if (root == null) { if (other.root != null) { return false; } } else if (!root.matches(other.root)) { return false; } if (dependencies.size() != other.dependencies.size()) { return false; } List<DependencyEdge> toMatch = new ArrayList<>(other.dependencies); for (DependencyEdge edge : dependencies) { Iterator<DependencyEdge> iterator = toMatch.iterator(); boolean matched = false; while (iterator.hasNext()) { DependencyEdge next = iterator.next(); if (edge.matches(next)) { iterator.remove(); matched = true; break; } } if (!matched) { return false; } } return true; }
DependencyTree { public boolean matches(DependencyTree other) { if (this == other) { return true; } if (other == null) { return false; } if (root == null) { if (other.root != null) { return false; } } else if (!root.matches(other.root)) { return false; } if (dependencies.size() != other.dependencies.size()) { return false; } List<DependencyEdge> toMatch = new ArrayList<>(other.dependencies); for (DependencyEdge edge : dependencies) { Iterator<DependencyEdge> iterator = toMatch.iterator(); boolean matched = false; while (iterator.hasNext()) { DependencyEdge next = iterator.next(); if (edge.matches(next)) { iterator.remove(); matched = true; break; } } if (!matched) { return false; } } return true; } }
DependencyTree { public boolean matches(DependencyTree other) { if (this == other) { return true; } if (other == null) { return false; } if (root == null) { if (other.root != null) { return false; } } else if (!root.matches(other.root)) { return false; } if (dependencies.size() != other.dependencies.size()) { return false; } List<DependencyEdge> toMatch = new ArrayList<>(other.dependencies); for (DependencyEdge edge : dependencies) { Iterator<DependencyEdge> iterator = toMatch.iterator(); boolean matched = false; while (iterator.hasNext()) { DependencyEdge next = iterator.next(); if (edge.matches(next)) { iterator.remove(); matched = true; break; } } if (!matched) { return false; } } return true; } DependencyTree(DependencyNode root, List<DependencyEdge> dependencies);  DependencyTree(DependencyNode root, DependencyEdge... dependencies);  DependencyTree(String rootNode, DependencyEdge... dependencies); }
DependencyTree { public boolean matches(DependencyTree other) { if (this == other) { return true; } if (other == null) { return false; } if (root == null) { if (other.root != null) { return false; } } else if (!root.matches(other.root)) { return false; } if (dependencies.size() != other.dependencies.size()) { return false; } List<DependencyEdge> toMatch = new ArrayList<>(other.dependencies); for (DependencyEdge edge : dependencies) { Iterator<DependencyEdge> iterator = toMatch.iterator(); boolean matched = false; while (iterator.hasNext()) { DependencyEdge next = iterator.next(); if (edge.matches(next)) { iterator.remove(); matched = true; break; } } if (!matched) { return false; } } return true; } DependencyTree(DependencyNode root, List<DependencyEdge> dependencies);  DependencyTree(DependencyNode root, DependencyEdge... dependencies);  DependencyTree(String rootNode, DependencyEdge... dependencies); List<DependencyEdge> getDependencies(); List<DependencyEdge> getDependencies(String type); DependencyNode getRoot(); Optional<DependencyNode> getNode(String id); Stream<DependencyTree> flattened(); int size(); DependencyTree addDependency(DependencyEdge edge); DependencyTree addDependency(String type, DependencyTree child); DependencyTree addDependency(String type, DependencyNode node); DependencyTree addDependency(String type, String node); @Override String toString(); boolean matches(DependencyTree other); void delexicalize(); void delexicalize(Collection<String> ids); void mapIds(Map<String, String> idMap); }
DependencyTree { public boolean matches(DependencyTree other) { if (this == other) { return true; } if (other == null) { return false; } if (root == null) { if (other.root != null) { return false; } } else if (!root.matches(other.root)) { return false; } if (dependencies.size() != other.dependencies.size()) { return false; } List<DependencyEdge> toMatch = new ArrayList<>(other.dependencies); for (DependencyEdge edge : dependencies) { Iterator<DependencyEdge> iterator = toMatch.iterator(); boolean matched = false; while (iterator.hasNext()) { DependencyEdge next = iterator.next(); if (edge.matches(next)) { iterator.remove(); matched = true; break; } } if (!matched) { return false; } } return true; } DependencyTree(DependencyNode root, List<DependencyEdge> dependencies);  DependencyTree(DependencyNode root, DependencyEdge... dependencies);  DependencyTree(String rootNode, DependencyEdge... dependencies); List<DependencyEdge> getDependencies(); List<DependencyEdge> getDependencies(String type); DependencyNode getRoot(); Optional<DependencyNode> getNode(String id); Stream<DependencyTree> flattened(); int size(); DependencyTree addDependency(DependencyEdge edge); DependencyTree addDependency(String type, DependencyTree child); DependencyTree addDependency(String type, DependencyNode node); DependencyTree addDependency(String type, String node); @Override String toString(); boolean matches(DependencyTree other); void delexicalize(); void delexicalize(Collection<String> ids); void mapIds(Map<String, String> idMap);  }