private static void mapItself(BidirectionalMap<ExtendedNode, ExtendedNode> map, ExtendedNode tree) { for (ExtendedNode node : AbstractNodeUtils.treeToLinkedHashSet(tree)) { map.put(node,node); } }
/** * Given a sub-tree - returns all its nodes as a list, sorted by their "serial" * * @param <T> The information on each node (e.g. ac.biu.nlp.nlp.instruments.parse.representation.english.Info) * @param <S> The nodes (e.g. EnglishNode) * @param tree The given sub-tree. * @return The nodes of the sub-tree as a sorted list (sorted by "serial" field of the nodes). */ public static <T extends Info, S extends AbstractNode<T,S>> List<S> treeToList(S tree) { Set<S> set = AbstractNodeUtils.treeToLinkedHashSet(tree); List<S> list = new ArrayList<S>(set.size()); list.addAll(set); Collections.sort(list, new BySerialComparator<T,S>()); return list; }
public static double missingNodesPortion(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { int totalNumberOfNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()).size(); int numberOfMissingNodes = findNodesNoMatch(text, hypothesis).size(); return ((double)numberOfMissingNodes)/((double)totalNumberOfNodes); }
public static double missingRelationsPortion(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { int totalNumberOfRelations = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()).size()-1; if (0==totalNumberOfRelations) return 0; else { int numberOfMissingRelations = findRelationsNoMatch(text, hypothesis).size(); return ((double)numberOfMissingRelations)/((double)totalNumberOfRelations); } }
public void find() { specs = new LinkedHashSet<SubstitutionSubtreeSpecification>(); Set<ExtendedNode> textTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); CollectionUtils.filter(textTreeNodes, textNodePredicate); if (textTreeNodes.isEmpty()) return; Set<ExtendedNode> hypothesisTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); CollectionUtils.filter(hypothesisTreeNodes, hypothesisNodePredicate); if (hypothesisTreeNodes.isEmpty()) return; for (ExtendedNode textNode: textTreeNodes) { for (ExtendedNode hypothesisNode: hypothesisTreeNodes) { specs.add(new SubstitutionSubtreeSpecification( description, textNode, hypothesisNode)); } } }
@Deprecated public static ValueSetMap<ExtendedNode, ExtendedNode> findSimilarContentNodes(ExtendedNode textTree, ExtendedNode hypothesisTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree); for (ExtendedNode hypothesisNode : hypothesisNodes) { for (ExtendedNode textNode : textNodes) { if (nodesSimilarContents(textNode.getInfo(),hypothesisNode.getInfo())) { ret.put(hypothesisNode,textNode); } } } return ret; }
private Set<S> getAllArgumentNodes(PredicateArgumentStructure<I, S> structure) { Set<S> ret = new LinkedHashSet<>(); for (TypedArgument<I, S> argument : structure.getArguments()) { ret.addAll(argument.getArgument().getNodes()); } for (ClausalArgument<I, S> argument : structure.getClausalArguments()) { ret.addAll(AbstractNodeUtils.treeToLinkedHashSet(argument.getClause())); } return ret; }
private void createMapSimilarNodesAndMissingSimilarNodes() { mapSimilarNodesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingSimilarNodes = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundSimilar = false; for (S textNode : textNodes) { if (alignmentCriteria.nodesSimilar(textTree, hypothesisTree, textNode, hypothesisNode)) { foundSimilar = true; mapSimilarNodesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundSimilar) { missingSimilarNodes.add(hypothesisNode); } } }
public static Set<ExtendedNode> findRelationsNoMatch(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { Set<ExtendedNode> ret = new LinkedHashSet<ExtendedNode>(); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(text.getTree()); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()); for (ExtendedNode hypothesisNode : hypothesisNodes) { boolean found = false; for (ExtendedNode textNode : textNodes) { if (Equalities.areEqualRelations(hypothesisNode, textNode, hypothesis.getParentMap(),text.getParentMap())) { found = true; break; } } if (!found) ret.add(hypothesisNode); } return ret; }
private void createMapAlignedTriplesAndMissingTriples() { mapAlignedTriplesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingTriples = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundAligned = false; for (S textNode : textNodes) { if (alignmentCriteria.triplesAligned(textTree, hypothesisTree, textNode, hypothesisNode)) { foundAligned = true; mapAlignedTriplesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundAligned) { missingTriples.add(hypothesisNode); } } }
@Deprecated public static ValueSetMap<ExtendedNode, ExtendedNode> findMatchingNodes(ExtendedNode textTree, ExtendedNode hypothesisTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree); for (ExtendedNode hypothesisNode : hypothesisNodes) { for (ExtendedNode textNode : textNodes) { if (nodesEqual(textNode.getInfo(),hypothesisNode.getInfo())) { ret.put(hypothesisNode,textNode); } } } return ret; }
private void createMapAlignedNodesAndMissingAlignedNodes() { mapAlignedNodesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingAlignedNodes = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundSimilar = false; for (S textNode : textNodes) { if (alignmentCriteria.nodesAligned(textTree, hypothesisTree, textNode, hypothesisNode)) { foundSimilar = true; mapAlignedNodesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundSimilar) { missingAlignedNodes.add(hypothesisNode); } } }
protected static Set<String> wordsInTree(ExtendedNode tree) { Set<String> ret = new LinkedHashSet<String>(); Set<ExtendedNode> setNodes = AbstractNodeUtils.treeToLinkedHashSet(tree); for (ExtendedNode node : setNodes) { if (InfoObservations.infoHasLemma(node.getInfo())) { String lemma = InfoGetFields.getLemma(node.getInfo()); ret.add(lemma); ret.addAll(StringUtil.stringToWords(lemma)); } } return ret; }
public static ValueSetMap<ExtendedNode, ExtendedNode> findAllMatchingNodes(ExtendedNode fromTree, ExtendedNode toTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> fromTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(fromTree); Set<ExtendedNode> toTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(toTree); for (ExtendedNode fromNode : fromTreeNodes) { for (ExtendedNode toNode : toTreeNodes) { if (Equalities.areEqualNodes(fromNode.getInfo(), toNode.getInfo())) { ret.put(fromNode, toNode); } } } return ret; }
/** * Returns a set of nodes in <tt>hypothesis</tt> that have no matching node in <tt>text</tt> * @param text * @param hypothesis * @return */ public static Set<ExtendedNode> findNodesNoMatch(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { Set<ExtendedNode> ret = new LinkedHashSet<ExtendedNode>(); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(text.getTree()); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()); for (ExtendedNode hypothesisNode : hypothesisNodes) { boolean found = false; for (ExtendedNode textNode : textNodes) { if (Equalities.areEqualNodes(hypothesisNode.getInfo(), textNode.getInfo())) { found = true; break; } } if (!found) ret.add(hypothesisNode); } return ret; }
Set<BasicNode> setNodes = AbstractNodeUtils.treeToLinkedHashSet(treeRoot); if (setNodes!=null)
@Override public void find() throws OperationException { specs = new LinkedHashSet<SubstitutionSubtreeSpecification>(); nodesAndTheirAntecedent = new LinkedHashMap<ExtendedNode, ExtendedNode>(); mapNodeToThoseWhoHaveItAsAntecedent = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> nodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (ExtendedNode node : nodes) { if (node.getAntecedent()!=null) { ExtendedNode antecedent = AbstractNodeUtils.getDeepAntecedentOf(node); nodesAndTheirAntecedent.put(node,antecedent); mapNodeToThoseWhoHaveItAsAntecedent.put(antecedent, node); } } for (ExtendedNode nodeThatHasAntecedent : nodesAndTheirAntecedent.keySet()) { specs.add(new SubstitutionSubtreeSpecification(nodeThatHasAntecedent, nodesAndTheirAntecedent.get(nodeThatHasAntecedent))); } if (parser.equals(PARSER.EASYFIRST)) { addCopyForRefRelation(); } }
@Override public void init() throws TeEngineMlException, OperationException, TreeAndParentMapException, AnnotatorException { super.init(); hypothesisTotalNumberOfNodes = (double)AbstractNodeUtils.treeToLinkedHashSet(operationsEnvironment.getHypothesis().getTree()).size(); hypothesisLemmasLowerCase = TreeUtilities.constructSetLemmasLowerCase(operationsEnvironment.getHypothesis()); this.initialized=true; initialFeatureVector = initialFeatureVector(); }
public static Set<LemmaAndPos> lemmasAndPosesInTree(ExtendedNode tree) throws TeEngineMlException { Set<LemmaAndPos> ret = new LinkedHashSet<LemmaAndPos>(); Set<ExtendedNode> setNodes = AbstractNodeUtils.treeToLinkedHashSet(tree); for (ExtendedNode node : setNodes) { if (InfoObservations.infoHasLemma(node.getInfo())) { String lemma = InfoGetFields.getLemma(node.getInfo()); PartOfSpeech pos = InfoGetFields.getPartOfSpeechObject(node.getInfo()); ret.add(new LemmaAndPos(lemma, pos)); for (String oneLemma : StringUtil.stringToWords(lemma)) { ret.add(new LemmaAndPos(oneLemma, pos)); } } } return ret; }
private void updateAntecedents() { Set<ExtendedNode> originalTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (ExtendedNode originalTreeNode : originalTreeNodes) { if (originalTreeNode.getAntecedent()!=null) { ExtendedNode originalTreeNodeAntecedent = originalTreeNode.getAntecedent(); mapOrigToGenerated.leftGet(originalTreeNode).setAntecedent(mapOrigToGenerated.leftGet(originalTreeNodeAntecedent)); } } }