private BasicNode buildNode(JCas jcas, int serial, int id, Token token, String depType, Token parent) throws CasTreeConverterException, UnsupportedPosTagStringException { String idString = Integer.toString(id); NodeInfo nodeInfo = buildNodeInfo(jcas, token, serial); EdgeInfo edgeInfo = buildEdgeInfo(jcas, depType); BasicNode node = new BasicNode(new DefaultInfo(idString, nodeInfo, edgeInfo)); nodes.add(node); if (parent != null) { registerChild(parent, token, node); } // Note that the first this method is called for each token, we build its non-deep node. // So for every token, the first node is always the non-deep one. All subsequent nodes // may be deep (if any). Note that the value collection in this MultiMap is a List. tokenToNode.put(token, node); return node; }
protected static void createArtificialRoot(Set<Integer> roots,Map<Integer, BasicNode> id2node, Map<Integer, Integer> child2parent) { BasicNode root = new BasicNode(new DefaultInfo("EMPTY", new DefaultNodeInfo(null, null, 0, null, new DefaultSyntacticInfo(null)), new DefaultEdgeInfo(null))); int rootId = ARTIFICIAL_ROOT_ID; id2node.put(rootId,root); Iterator<Integer> it = roots.iterator(); while (it.hasNext()) { child2parent.put(it.next(),rootId); it.remove(); } roots.add(rootId); }
public Info newInfoRTT(Info nodeInfo, Info edgeInfo, Info additionalInformation) { return new DefaultInfo(nodeInfo.getId(), nodeInfo.getNodeInfo(), edgeInfo.getEdgeInfo()); }
public Info newInfoRT(Info nodeInfo, Info edgeInfo) { return new DefaultInfo(nodeInfo.getId(), nodeInfo.getNodeInfo(), edgeInfo.getEdgeInfo()); }
public Info newInfoFromTreeNodeAndRhsNodeAndRhsEdge(Info nodeInfo, Info ruleRhsNodeInfo, Info ruleRhsEdgeInfo) { return new DefaultInfo(nodeInfo.getId(), InfoServicesUtils.combineNodeInfo(nodeInfo, ruleRhsNodeInfo), ruleRhsEdgeInfo.getEdgeInfo()); }
public Info newInfoFromTreeNodeRhsNodeAndEdge(Info treeInfo, Info rhsInfo, Info edgeInfo) { return new DefaultInfo(treeInfo.getId(), InfoServicesUtils.combineNodeInfo(treeInfo, rhsInfo), edgeInfo.getEdgeInfo()); }
protected BasicNode getBasicNodeFromConll(String[] toks) throws Exception { /* * items[0]: ID * items[1]: word form * items[2]: lemma * items[4]: POS * items[6]: head ID * items[7]: dependency label */ if (toks.length < 8) throw new Exception("Number of columns for each word should be at least 8: " + toks); String lemma = toks[2]; if (lemma.equals(UNKNOWN)) lemma = toks[1]; NodeInfo nodeInfo = new DefaultNodeInfo(toks[1],lemma,Integer.parseInt(toks[0]),null, new DefaultSyntacticInfo(pos.createNewPartOfSpeech(toks[4]))); EdgeInfo edgeInfo = new DefaultEdgeInfo(new DependencyRelation(toks[7],null)); Info info = new DefaultInfo(null,nodeInfo,edgeInfo); return new BasicNode(info); }
if (parser.equals(PARSER.MINIPAR)) { NodeInfo nodeInfo = fromStringNonVariable(info); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, nodeInfo, relationToParent)); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, verbNodeInfo, relationToParent)); BasicNode child = new BasicNode(new DefaultInfo(DEFAULT_ID, rpNodeInfo, new DefaultEdgeInfo(new DependencyRelation("prt", null)))); ret.addChild(child); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, parentNodeInfo, relationToParent)); BasicNode child = new BasicNode(new DefaultInfo(DEFAULT_ID, childNodeInfo, new DefaultEdgeInfo(new DependencyRelation("nn", null)))); ret.addChild(child); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, nodeInfo, relationToParent));
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; }
public static BasicNode addArtificialRoot(BasicNode tree) { DefaultInfo rootInfo = new DefaultInfo(AbstractBasicParser.ROOT_NODE_ID,new DefaultNodeInfo(null,null,0,null,new DefaultSyntacticInfo(null)),new DefaultEdgeInfo(null)); BasicNode root = new BasicNode(rootInfo); root.addChild(tree); return root; } }
ret.addChild(new BasicNode(new DefaultInfo(DEFAULT_ID, childNodeInfo, childEdgeInfo))); ret.addChild(new BasicNode(new DefaultInfo(DEFAULT_ID, childNodeInfo, childEdgeInfo)));
@Override protected void generateTheTree() throws OperationException { affectedNodes = new LinkedHashSet<ExtendedNode>(); //BidirectionalMap<AbstractNode<Info,?>, EnglishNode> copyMap = AbstractNodeUtils.copyTreeReturnMap(textTree.getTree(), new EnglishNodeConstructor()); BidirectionalMap<ExtendedNode, ExtendedNode> copyMap = AbstractNodeUtils.strictTypeCopyTree(textTree.getTree(), new ExtendedNodeConstructor()); ExtendedNode duplicatedNode = new ExtendedNode(new ExtendedInfo(new DefaultInfo(nodeToMove.getInfo().getId(), nodeToMove.getInfo().getNodeInfo(), this.newEdgeInfo), nodeToMove.getInfo().getAdditionalNodeInformation()) ); ExtendedNode parentInGeneratedTree = copyMap.leftGet(newParent); parentInGeneratedTree.addChild(duplicatedNode); if (nodeToMove.getAntecedent()!=null) { ExtendedNode antecedentInOriginal = nodeToMove.getAntecedent(); ExtendedNode antecedentInGenerated = copyMap.leftGet(antecedentInOriginal); duplicatedNode.setAntecedent(antecedentInGenerated); } affectedNodes.add(duplicatedNode); this.generatedTree = copyMap.leftGet(textTree.getTree()); this.mapOriginalToGenerated = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode originalNode : copyMap.leftSet()) { mapOriginalToGenerated.put(originalNode,copyMap.leftGet(originalNode)); } mapOriginalToGenerated.put(nodeToMove,duplicatedNode); }
BasicConstructionNode node = new BasicConstructionNode( new DefaultInfo(nodeID.toString(), nodeInfo, new DefaultEdgeInfo(relation))); nodeID++; return node;
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); }
/** * Ctor * @throws EntailmentCompilationException */ private DefaultEntailmentRuleCompileServices() throws EntailmentCompilationException { try { PERIOD_NODE = new BasicNode(new DefaultInfo("", new DefaultNodeInfo(PERIOD, PERIOD, -1, null, new DefaultSyntacticInfo(new BySimplerCanonicalPartOfSpeech(SimplerCanonicalPosTag.PUNCTUATION))), new DefaultEdgeInfo(new DependencyRelation(StanfordDepedencyRelationType.punct.name(), null)))); } catch (UnsupportedPosTagStringException e) { throw new EntailmentCompilationException("Internal bug! could not instantiate a new UnspecifiedPartOfSpeech(SimplerCanonicalPosTag.PUNCTUATION)", e); } }
DefaultSyntacticInfo syntacticInfo = new DefaultSyntacticInfo(pos); DefaultNodeInfo defaultNodeInfo = new DefaultNodeInfo(lineParser.getWord(),lineParser.getRootForm(),this.serial,null,syntacticInfo); DefaultInfo info = new DefaultInfo(lineParser.getLabel(), defaultNodeInfo,defaultEdgeInfo);
public void makeOperation() { NodeInfo nodeInfo = null; try{nodeInfo = node.getInfo().getNodeInfo();}catch(Exception e){} String word = null; String lemma = null; int serial = 0; NamedEntity namedEntity = null; SyntacticInfo syntacticInfo = null; if (nodeInfo != null) { word = nodeInfo.getWord(); lemma = nodeInfo.getWordLemma(); serial = nodeInfo.getSerial(); syntacticInfo = nodeInfo.getSyntacticInfo(); } namedEntity = neWord.getNamedEntity(); Info oldInfo = node.getInfo(); node.setInfo(new DefaultInfo(oldInfo.getId(),new DefaultNodeInfo(word,lemma,serial,namedEntity,syntacticInfo),oldInfo.getEdgeInfo())); }
Info newInfo = new DefaultInfo(node.getInfo().getId(), newNodeInfo, node.getInfo().getEdgeInfo()); node.setInfo(newInfo);
private static void addNeToAntecedents(BasicConstructionNode mutableParseTree) { for (BasicConstructionNode mutableNode : TreeIterator.iterableTree(mutableParseTree)) { if (mutableNode.getAntecedent()!=null) { BasicConstructionNode antecedent = AbstractNodeUtils.getDeepAntecedentOf(mutableNode); if (antecedent.getInfo().getNodeInfo().getNamedEntityAnnotation()!=null) { NamedEntity ne = antecedent.getInfo().getNodeInfo().getNamedEntityAnnotation(); Info newInfo = new DefaultInfo(mutableNode.getInfo().getId(), new DefaultNodeInfo(mutableNode.getInfo().getNodeInfo().getWord(), mutableNode.getInfo().getNodeInfo().getWordLemma(), mutableNode.getInfo().getNodeInfo().getSerial(), ne, mutableNode.getInfo().getNodeInfo().getSyntacticInfo()), mutableNode.getInfo().getEdgeInfo()); mutableNode.setInfo(newInfo); } } } }
@Override public Info supplementRightInfoWithLeftInfo(Info leftInfo, Info rightInfo) throws EntailmentCompilationException { if (leftInfo == null) throw new EntailmentCompilationException("got null left info"); if (rightInfo == null) throw new EntailmentCompilationException("got null right info"); Info alphaAnnotatedInfo = rightInfo; Info betaAnnotatedInfo = leftInfo; // choose args: alphaObj != null ? alphaObj : betaObj String lemma = (String) RuleBuildingUtils.chooseAlphaBeta(alphaAnnotatedInfo.getNodeInfo().getWordLemma(), betaAnnotatedInfo.getNodeInfo().getWordLemma()); EdgeInfo newEdgeAnnotatedInfo = new DefaultEdgeInfo( (DependencyRelation) RuleBuildingUtils.chooseAlphaBeta(alphaAnnotatedInfo.getEdgeInfo().getDependencyRelation(), betaAnnotatedInfo.getEdgeInfo().getDependencyRelation())); SyntacticInfo syntacticInfo = (SyntacticInfo) RuleBuildingUtils.chooseAlphaBeta(alphaAnnotatedInfo.getNodeInfo().getSyntacticInfo(), betaAnnotatedInfo.getNodeInfo().getSyntacticInfo()); // decide if to construct a NodeInfo or a VariableNodeAnnotatedInfo by the type of the betaNode? NodeInfo newAnnotatedNodeInfo; if (betaAnnotatedInfo.getNodeInfo().isVariable()) // copied variable nodes get the word and lemma of their lhs originals newAnnotatedNodeInfo = DefaultNodeInfo.newVariableDefaultNodeInfo (betaAnnotatedInfo.getNodeInfo().getVariableId(), null, -1, null, syntacticInfo); else { String word = (String) RuleBuildingUtils.chooseAlphaBeta(alphaAnnotatedInfo.getNodeInfo().getWord(), betaAnnotatedInfo.getNodeInfo().getWord()); newAnnotatedNodeInfo = new DefaultNodeInfo(word, lemma, -1, null, syntacticInfo); } Info newAnnotatedInfo = new DefaultInfo(betaAnnotatedInfo.getId(), newAnnotatedNodeInfo, newEdgeAnnotatedInfo); return newAnnotatedInfo; }