private static <I extends Info, N extends AbstractNode<I, N>, CN extends AbstractConstructionNode<I, CN>, A extends RuleAnnotations> N convertAnnotationTreeToRegularNodes(CN oldLhs, Map<CN, A> oldAnnotationAlignments, Map<N, A> newAnnotationAlignments, AnnotationRuleCompileServices<I, N, CN, A> compilationServices) { N newLhs = compilationServices.newNode(oldLhs.getInfo()); newAnnotationAlignments.put(newLhs, oldAnnotationAlignments.get(oldLhs)); if (oldLhs.hasChildren()) for (CN child : oldLhs.getChildren()) { N newChild = convertAnnotationTreeToRegularNodes(child, oldAnnotationAlignments, newAnnotationAlignments, compilationServices); newLhs.addChild(newChild); newChild.setAntecedent(newLhs); } return newLhs; } }
/** * For each <i>partial </i>mapping pair, replace only its specified attribute in the right node with the attribute value from the left node.<br> * Partial mappings take precedence over full mappings, so they run second! * @param idAlignments * @param lhsNodesMap * @param rhsNodesMap * @throws EntailmentCompilationException */ private void applyPartialAlignments(List<GenericAlignment> idAlignments, Map<Long, CN> lhsNodesMap, Map<Long, CN> rhsNodesMap) throws EntailmentCompilationException { for (GenericAlignment alignment : idAlignments) if (!REGULAR_ALIGNMENT.equalsIgnoreCase(alignment.getType())) { // partially reset the info on the RHS side Long lhsNodeId = alignment.getLeftId(); Long rhsNodeId = alignment.getRightId(); CN lhsNode = lhsNodesMap.get(lhsNodeId); CN rhsNode = rhsNodesMap.get(rhsNodeId); I newInfo = compilationServices.copyLeftParamToRight(lhsNode.getInfo(), rhsNode.getInfo(), alignment.getType()); rhsNode.setInfo(newInfo); } }
/** * @param rhs * @param helpMap * @param newMapping * @return */ private N convertRhsToNNodes( CN rhs, BidirectionalMap<N, CN> helpMap, BidirectionalMap<N, N> newMapping) { N newRhs = compilationServices.newNode(rhs.getInfo()); if (rhs.getChildren() != null) for (CN child : rhs.getChildren()) { N newChild = convertRhsToNNodes(child, helpMap, newMapping); newRhs.addChild(newChild); newChild.setAntecedent(newRhs); } // update the new mapping if necessary if (helpMap.rightContains(rhs)) newMapping.put(helpMap.rightGet(rhs), newRhs); return newRhs; }
root.addChild(child); child.setAntecedent(root);
/** * @param lhs * @param mappings * @param helpMap * @return */ private N convertLhsToNNodes( CN lhs, BidirectionalMap<CN, CN> mappings, BidirectionalMap<N, CN> helpMap) { N newLhs = compilationServices.newNode(lhs.getInfo()); if (lhs.getChildren() != null) for (CN child : lhs.getChildren()) { N newChild = convertLhsToNNodes(child, mappings, helpMap); newLhs.addChild(newChild); newChild.setAntecedent(newLhs); } // update the new mapping if necessary if (mappings.leftContains(lhs)) helpMap.put(newLhs, mappings.leftGet(lhs)); return newLhs; } }