if (!AbstractNodeUtils.isLeaf(node)) { for (S child: node.getChildren()) { List<S> currentChildDependencyPaths = new ArrayList<S>();
/** * Adds a list of all dependency paths from the given node or a descendant of it, to a descendant node. * @param root [INPUT] the common ancestor of all the dependency paths that will be created. * @param currentDependencyPaths [OUTPUT] the dependency paths. */ protected void addDependencyPaths(S node, List<S> currentDependencyPaths) { // 1. Add all dependency paths from the given root: if (startNodePredicate.evaluate(node.getInfo())) currentDependencyPaths.addAll(dependencyPathsFromNode(node)); // 2. Recursively add all dependency paths from each child of root: if (!AbstractNodeUtils.isLeaf(node)) for (S child: node.getChildren()) addDependencyPaths(child, currentDependencyPaths); }
/** * Adds a list of all dependency paths from the given root node to a descendant node, that pass through the given current node. * @param root [INPUT] the common ancestor of all the dependency paths that will be created. * @param currentNode [INPUT] one of the descendants of root. * @param pathFromCurrentNodeToRoot [INPUT] list of info's on the dependency path from the currentNode to the root. * @param currentDependencyPaths [OUTPUT] list of node's - dependency paths from the root to a descendant node. */ protected void addDependencyPathsFromNodeThroughDescendant(S root, S currentNode, List<T> pathFromCurrentNodeToRoot, List<S> currentDependencyPaths) { // 1. Prepend the current node to the current path: pathFromCurrentNodeToRoot.add(0, currentNode.getInfo()); // 2. If the current path is complete - add it to the list of all paths: if (endNodePredicate.evaluate(currentNode.getInfo()) && pathFromCurrentNodeToRoot.size()>1) { //System.out.println("\tfound a path - add it to the list"); if (!filterPathsWithOnlyStopwords || !isListContainsOnlyStopwords(pathFromCurrentNodeToRoot)) { S newDependencyPath = AbstractNodeBuildUtils.buildTreeFromLeafToRoot(pathFromCurrentNodeToRoot, this.nodeConstructor); currentDependencyPaths.add(newDependencyPath); } } // 3. Whether the current path is complete or not - recursively add the paths through each of the children of the current node: if (!AbstractNodeUtils.isLeaf(currentNode) && (pathFromCurrentNodeToRoot.size()==1 || !stopNodePredicate.evaluate(currentNode.getInfo()))) { for (S child: currentNode.getChildren()) { addDependencyPathsFromNodeThroughDescendant(root, child, pathFromCurrentNodeToRoot, currentDependencyPaths); } } // 4. Cleanup - after adding all possible paths through the current node, remove the current node from the current path. pathFromCurrentNodeToRoot.remove(0); }