private static void mapItself(BidirectionalMap<ExtendedNode, ExtendedNode> map, ExtendedNode tree) { for (ExtendedNode node : AbstractNodeUtils.treeToLinkedHashSet(tree)) { map.put(node,node); } }
public MapLocalScorer(Set<String> component, double unknownScore, boolean convertProb2Score) { m_desc2idMap = new SimpleBidirectionalMap<String,Integer>(); int id = 1; for(String predicate:component) m_desc2idMap.put(predicate, id++); m_rule2ScoreMap = new LinkedHashMap<Pair<Integer,Integer>, Double>(); m_entailing = new HashSet<Pair<String,String>>(); m_nonEntailing = new HashSet<Pair<String,String>>(); m_convertProb2Score = convertProb2Score; m_unknownScore = prob2Score(unknownScore); }
public void annotate() throws AnnotatorException { mapOriginalToAnnotated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode node : TreeIterator.iterableTree(this.tree)) { mapOriginalToAnnotated.put(node, node); } annotated=true; }
public void createMapTemplateToId() throws SQLException, RuleBaseException { mapTemplateToId = new SimpleBidirectionalMap<String, Integer>(); String query = "SELECT id,description FROM "+dbParameters.getTemplatesTableName(); Statement statement = connection.createStatement(); try { ResultSet resultSet = statement.executeQuery(query); while(resultSet.next()) { int id = resultSet.getInt("id"); String description = resultSet.getString("description"); if (description.isEmpty()) ; // ignore rows with an empty pattern-description - they represent duplicates of another row that represents their pattern. else { if (mapTemplateToId.leftContains(description)) throw new RuleBaseException("Malformed rule base. Template "+description+" appears more than once."); mapTemplateToId.put(description, id); } } } finally { statement.close(); } }
/** * Adds all (L,R) keys-values from <code>mapToAdd</code> to <code>map</code> * @param <L> * @param <R> * @param map * @param mapToAdd */ public static <L,R> void BidiMapAddAll(BidirectionalMap<L, R> map, BidirectionalMap<L, R> mapToAdd) { for (L l : mapToAdd.leftSet()) { if (!map.leftContains(l)) { map.put(l, mapToAdd.leftGet(l)); } } }
protected SyntacticRule<Info, BasicNode> ruleFromTemplates(TemplateToTree entailing, TemplateToTree entailed, double score) throws TemplateToTreeException { BidirectionalMap<BasicNode, BasicNode> mapLhsRhs = new SimpleBidirectionalMap<BasicNode, BasicNode>(); mapLhsRhs.put(entailing.getTree(), entailed.getTree()); if ( (entailing.getLeftVariableNode()!=null) && (entailed.getLeftVariableNode()!=null) ) { mapLhsRhs.put(entailing.getLeftVariableNode(),entailed.getLeftVariableNode()); } if ( (entailing.getRightVariableNode()!=null) && (entailed.getRightVariableNode()!=null) ) { mapLhsRhs.put(entailing.getRightVariableNode(),entailed.getRightVariableNode()); } return new SyntacticRule<Info, BasicNode>(entailing.getTree(), entailed.getTree(), mapLhsRhs); }
private ExtendedNode copyTree(ExtendedNode subtree) { ExtendedNode ret = new ExtendedNode(subtree.getInfo()); if (subtree.getChildren()!=null) { for (ExtendedNode child : subtree.getChildren()) { ExtendedNode generatedChild = copyTree(child); ret.addChild(generatedChild); } } mapOrigToGenerated.put(subtree, ret); return ret; }
rhsNode.setInfo(newInfo); alignmentsMap.put(lhsNode, rhsNode);
mergedOutput.put(foundNode, new ArkrefMention(beginMarker.getMentionId(), beginMarker.getEntityId()));
public static <L, R, M> BidirectionalMap<L, R> concatenateBidiMaps(BidirectionalMap<L, M> map1,BidirectionalMap<M, R> map2) throws TeEngineMlException { boolean failed = false; BidirectionalMap<L, R> ret = new SimpleBidirectionalMap<L, R>(); for (L l : map1.leftSet()) { M m = map1.leftGet(l); if (!map2.leftContains(m)) failed=true; ret.put(l, map2.leftGet(m) ); } if (failed) throw new TeEngineMlException("Concatenation failed."); else return ret; } }
mapOrigToGenerated.put(root, generatedRoot); if (root==nodeToSubstitute)
protected ST copyNonRuleSubTree(ST subtree) { ST ret = nodeConstructor.newNode(subtree.getInfo()); if (subtree.getChildren()!=null) { for (ST child : subtree.getChildren()) { if (!mapRuleLhsToTree.rightContains(child)) { ret.addChild(copyNonRuleSubTree(child)); } } } mapOrigToGenerated.put(subtree, ret); return ret; }
mapLhsRhs.put(entailing.getTree(), entailed.getTree()); if ( (entailing.getLeftVariableNode()!=null) && (entailed.getLeftVariableNode()!=null) ) mapLhsRhs.put(entailing.getLeftVariableNode(),entailed.getLeftVariableNode()); mapLhsRhs.put(entailing.getRightVariableNode(),entailed.getRightVariableNode());
/** * @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; }
/** * @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; } }
mapLhsToTree.put(lhsNode, treeNodeInExtendedTree);
intersectedBidiMap.put(bidiMap1.rightGet(node), bidiMap2.leftGet(node));
private ExtendedNode copy (ExtendedNode subtree, int depth, EdgeInfo edgeInfo) { ExtendedNode ret; if (null==edgeInfo) { ret = nodeConstructor.newNode(subtree.getInfo()); } else { ExtendedInfo originalInfo = subtree.getInfo(); if (null==originalInfo) originalInfo = ExtendedNodeConstructor.EMPTY_EXTENDED_INFO; ret = new ExtendedNode(new ExtendedInfo(new DefaultInfo(originalInfo.getId(), originalInfo.getNodeInfo(), edgeInfo), originalInfo.getAdditionalNodeInformation())); } mapOriginalToGenerated.put(subtree,ret); if ( (subtree.hasChildren()) && (depth>0) ) { for (ExtendedNode child : subtree.getChildren()) { ret.addChild(copy(child,depth-1,null)); } } return ret; }
bidiMapOrigToGenerated.put(subtree, ret);