public void copy(int depth) { mapOriginalToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); generatedTree = copy(tree,depth,newRootEdgeInfo); }
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 generate() throws TeEngineMlException { mapOrigToGenerated = new SimpleBidirectionalMap<ST, ST>(); affectedNodes = new LinkedHashSet<ST>(); generatedTree = copyRuleSubTree(rule.getRightHandSide(),edgeInfoForRoot); }
/** * Build a {@link SyntacticRule} out of an LHS RHS and alignments. Convert them from {@link AbstractConstructionNode} to {@link AbstractNode}, first. * @param oldLhsRoot * @param oldRhsRoot * @param nodeAlignments * @param isExtraction * @return */ private SyntacticRule<I, N> buildRule(CN oldLhsRoot, CN oldRhsRoot, BidirectionalMap<CN, CN> nodeAlignments, boolean isExtraction) { BidirectionalMap<N, N> newAlignments = new SimpleBidirectionalMap<N, N>(); BidirectionalMap<N, CN> helpMap = new SimpleBidirectionalMap<N, CN>(); N newLhsRoot = convertLhsToNNodes(oldLhsRoot, nodeAlignments, helpMap ); N newRhsRoot = convertRhsToNNodes(oldRhsRoot, helpMap, newAlignments ); return new SyntacticRule<I, N>(newLhsRoot, newRhsRoot, newAlignments, isExtraction); }
@Override protected void generateTheTree() throws OperationException { affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); mapGeneratedToOrig = new LinkedHashMap<ExtendedNode, ExtendedNode>(); substitutionNodeEncountered = false; this.generatedTree = copySubTree(textTree.getTree(),null,null,false); updateAntecedents(); }
public void annotate() throws AnnotatorException { mapOriginalToAnnotated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode node : TreeIterator.iterableTree(this.tree)) { mapOriginalToAnnotated.put(node, node); } annotated=true; }
@Override protected void generateTheTree() throws OperationException { mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); affectedNodes = new LinkedHashSet<ExtendedNode>(); this.generatedTree = copySubTree(this.textTree.getTree()); updateAntecedents(); }
protected void initTraces() throws TeEngineMlException { if (Constants.TRACE_ORIGINAL_NODES) { logger.info("Setting initial trace information..."); BidirectionalMap<ExtendedNode, ExtendedNode> bidiFromOriginal = null; if (mapOriginalToInitialized!=null) bidiFromOriginal = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); List<ExtendedNode> newTextTrees = new ArrayList<ExtendedNode>(originalTextTrees.size()); Map<ExtendedNode,String> newMapTreeToSentence = new LinkedHashMap<ExtendedNode, String>(); for (ExtendedNode textTree : originalTextTrees) { SelfTraceSetter setter = new SelfTraceSetter(textTree); setter.set(); ExtendedNode newTree = setter.getNewTree(); newTextTrees.add(newTree); newMapTreeToSentence.put(newTree, originalMapTreesToSentences.get(textTree)); if (mapOriginalToInitialized!=null) DsUtils.BidiMapAddAll(bidiFromOriginal, setter.getMapping()); } originalTextTrees = newTextTrees; originalMapTreesToSentences = newMapTreeToSentence; if (mapOriginalToInitialized!=null) mapOriginalToInitialized = DsUtils.concatenateBidiMaps(mapOriginalToInitialized, bidiFromOriginal); logger.info("Setting initial trace information done."); } }
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(); } }
@Override protected void generateTheTree() throws OperationException { if (textTree.getTree()==nodeToMove) throw new OperationException("Moving the root is illegal."); affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToCopy = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); this.generatedTree = recursiveGenerate(textTree.getTree(),null,false); updateAntecedentInformation(); this.nodeToMoveNotExistInGeneratedTree = !nodeHasAlreadyBeenMoved; }
@Override protected void generateTheTree() throws OperationException { this.affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); this.generatedTree = copyTree(this.textTree.getTree()); updateAntecedents(); ExtendedNode parent = mapOrigToGenerated.leftGet(whereToInsert); ExtendedNode insertedNode = new ExtendedNode(nodeToInsert); // ExtendedNode insertedNode = new ExtendedNode(new ExtendedInfo(nodeToInsert.getId(),nodeToInsert.getNodeInfo(),nodeToInsert.getEdgeInfo(),AdditionalInformationServices.emptyInformation())); affectedNodes.add(insertedNode); parent.addChild(insertedNode); }
if (mapOriginalToInitialized!=null) bidiFromOriginal = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>();
public void initialize() throws TeEngineMlException, AnnotatorException, TreeCoreferenceInformationException { logStartInitialize(); mapOriginalToGenerated = new SimpleBidirectionalMap<BasicNode, ExtendedNode>(); BasicNode tree = getNextTree(); while (tree!=null) { createTree(tree); tree = getNextTree(); } if (originalCoreferenceInformation!=null) { createCorefInformation(); } logger.debug("DocumentInitializer: Initialization done."); }
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; } }
/** * Generates the tree * @throws CandCTreesGenerationException */ public void generateTree() throws CandCTreesGenerationException { try { mapCCNodeToTreeNode = new SimpleBidirectionalMap<CCNode, S>(); BfsDirectedGraphScan<CCNode, CCEdgeInfo> scan = new BfsDirectedGraphScan<CCNode, CCEdgeInfo>(new CCTreeGenerationScanOperation(), graph); scan.scan(startNode); if (exception != null) throw exception; } catch (DirectedGraphScanException e) { throw new CandCTreesGenerationException("graph scan error. see nested exception",e); } catch (DirectedGraphException e) { throw new CandCTreesGenerationException("graph error. see nested exception",e); } }
@Override protected void generateTheTree() throws OperationException { bidiMapOrigToGenerated = new SimpleBidirectionalMap<TN, TN>(); this.rootOfLhsInTree = mapLhsToTree.leftGet(rule.getLeftHandSide()); if (null==rootOfLhsInTree) { throw new OperationException("LHS root not mapped to any node in the original tree.\n" + "The map from LHS to the tree is:\n"+debug_print_mapLhsToTree()); } try { generatedTree = copySubTree(this.textTree.getTree()); } catch(TeEngineMlException e) { throw new OperationException("Rule application failed. See nested exception.",e); } }
private RuleSpecification convertRuleMatch(RuleMatch<Info,BasicNode> ruleMatch, BidirectionalMap<ExtendedNode, BasicNode> mapTextTree) throws OperationException BidirectionalMap<BasicNode, ExtendedNode> mapLhsToTree = new SimpleBidirectionalMap<>(); BidirectionalMap<BasicNode,BasicNode> mapLhsToTreeInRuleMatch = ruleMatch.getMapLHStoTree(); for (BasicNode lhsNode : mapLhsToTreeInRuleMatch.leftSet())
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); }
throw new AnnotatorException("bidiMap1 has " + bidiMap2.size() + " mappings while bidimap2 has "+ bidiMap2.size()); BidirectionalMap<N, P> intersectedBidiMap = new SimpleBidirectionalMap<N, P>();
public void construct() throws UnsupportedPosTagStringException { bidiMapOriginalToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); affectedNodes = new LinkedHashSet<ExtendedNode>(); copyEntities(); entity2.addChild(entity1); ExtendedNode beNode = new ExtendedNode(new ExtendedInfo( new DefaultInfo("IS_A_be", new DefaultNodeInfo("be", "be", 0, null, new DefaultSyntacticInfo(new PennPartOfSpeech(PennPosTag.VBZ))), new DefaultEdgeInfo(new DependencyRelation("cop", null))), AdditionalInformationServices.emptyInformation())); entity2.addChild(beNode); ExtendedNode punctNode = new ExtendedNode(new ExtendedInfo( new DefaultInfo("IS_A_punct", new DefaultNodeInfo(".", ".", 0, null, new DefaultSyntacticInfo(new PennPartOfSpeech("."))), new DefaultEdgeInfo(new DependencyRelation("punct", null))), AdditionalInformationServices.emptyInformation())); entity2.addChild(punctNode); generatedTree = entity2; affectedNodes.add(beNode); affectedNodes.add(punctNode); affectedNodes.add(entity1); affectedNodes.add(entity2); }