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 static ExtendedNode createNodeOfArtificialRoot() { ExtendedInfo rootInfo = new ExtendedInfo(AbstractBasicParser.ROOT_NODE_ID,new DefaultNodeInfo(null,null,0,null,new DefaultSyntacticInfo(null)),new DefaultEdgeInfo(null),ExtendedNodeConstructor.EMPTY_ADDITIONAL_NODE_INFORMATION); ExtendedNode root = new ExtendedNode(rootInfo); return root; }
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; } }
private NodeInfo fromStringNonVariable(String str) throws UnsupportedPosTagStringException { String[] components = str.split(SPLIT_NODE_COMPONENTS); String pos = posOf(components[0]); String lemma = components[1]; return new DefaultNodeInfo(lemma, lemma, 0, null, new DefaultSyntacticInfo(new MiniparPartOfSpeech(pos))); }
protected void setOverrideRelationToArtificialRoot(EdgeInfo overrideRelationToArtificialRoot) throws UnsupportedPosTagStringException { this.overrideRelationToArtificialRoot = new ExtendedInfo("", new DefaultNodeInfo("", "", 0, null, new DefaultSyntacticInfo(new BySimplerCanonicalPartOfSpeech(SimplerCanonicalPosTag.OTHER))), overrideRelationToArtificialRoot, ExtendedNodeConstructor.EMPTY_ADDITIONAL_NODE_INFORMATION); }
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); }
private static NodeInfo buildNodeInfo(JCas jcas, Token tokenAnno, int serial) throws CasTreeConverterException, UnsupportedPosTagStringException { String word = tokenAnno.getCoveredText(); String lemma = tokenAnno.getLemma().getValue(); String pos = tokenAnno.getPos().getPosValue(); // We rely on the fact the NamedEntity enum values have the same names as the ones // specified in the DKPro mapping (e.g. PERSON, ORGANIZATION) eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity namedEntity=null; List<NamedEntity> namedEntities = JCasUtil.selectCovered(NamedEntity.class, tokenAnno); switch (namedEntities.size()) { case 0: break; // if no NER - ignore and move on case 1: namedEntity = eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity.valueOf(namedEntities.get(0).getValue()); break; default: throw new CasTreeConverterException(String.format("Got %d NamedEntity annotations for token %s", namedEntities.size(), tokenAnno)); } return new DefaultNodeInfo(word, lemma, serial, namedEntity, new DefaultSyntacticInfo(new PennPartOfSpeech(pos))); }
throw new ParserRunException("empty output"); BasicNode root = new BasicNode(new DefaultInfo("0",new DefaultNodeInfo("ROOT", "ROOT", 0, null, new DefaultSyntacticInfo(new StuttgartTreeTaggerPartOfSpeech("ROOT"))),new DefaultEdgeInfo(new DependencyRelation("ROOT", null)))); mapIdToNode.put(0, root); new BasicNode(new DefaultInfo(serial,new DefaultNodeInfo(lemma, lemma, id, null, new DefaultSyntacticInfo(new StuttgartTreeTaggerPartOfSpeech(pos))),new DefaultEdgeInfo(new DependencyRelation(relation, null)))); mapIdToNode.put(id, node); int parentId = Integer.parseInt(parent);
/** * 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); } }
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())); }
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); }
new DefaultNodeInfo(lexicalRule.getLhsLemma(), lexicalRule.getLhsLemma(), 0, null, new DefaultSyntacticInfo(lexicalRule.getLhsPos())), new DefaultEdgeInfo(new DependencyRelation("", null))));
if(lemmaComponents.length==2 && pos.equalsIgnoreCase("v") && PREP_LIST.contains(lemmaComponents[1])) { //particles - "take over", "pick up", etc. NodeInfo verbNodeInfo = new DefaultNodeInfo(lemmaComponents[0], lemmaComponents[0], 0, null, new DefaultSyntacticInfo(new MiniparPartOfSpeech(pos))); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, verbNodeInfo, relationToParent)); NodeInfo rpNodeInfo = new DefaultNodeInfo(lemmaComponents[1], lemmaComponents[1], 0, null, new DefaultSyntacticInfo(new MiniparPartOfSpeech("prep"))); BasicNode child = new BasicNode(new DefaultInfo(DEFAULT_ID, rpNodeInfo, new DefaultEdgeInfo(new DependencyRelation("prt", null)))); ret.addChild(child); NodeInfo parentNodeInfo = new DefaultNodeInfo(lemmaComponents[1], lemmaComponents[1], 0, null, new DefaultSyntacticInfo(new MiniparPartOfSpeech(pos))); ret = new BasicNode(new DefaultInfo(DEFAULT_ID, parentNodeInfo, relationToParent)); NodeInfo childNodeInfo = new DefaultNodeInfo(lemmaComponents[0], lemmaComponents[0], 0, null, new DefaultSyntacticInfo(new MiniparPartOfSpeech(pos))); BasicNode child = new BasicNode(new DefaultInfo(DEFAULT_ID, childNodeInfo, new DefaultEdgeInfo(new DependencyRelation("nn", null)))); ret.addChild(child);
new DefaultNodeInfo(lemma, lemma, -1, null, syntacticInfo);
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); } } } }
private void findSpecs() throws TeEngineMlException, RuleBaseException { this.specs = new LinkedHashSet<RuleSubstituteNodeSpecification<T>>(); for (ExtendedNode node : TreeIterator.iterableTree(treeAndParentMap.getTree())) { if (isRelevantNode(node)) { if (InfoObservations.infoHasLemma(node.getInfo())) { LemmaAndPos lemmaAndPos = new LemmaAndPos(InfoGetFields.getLemma(node.getInfo()), InfoGetFields.getPartOfSpeechObject(node.getInfo())); ImmutableSet<T> rules = getRulesForLemmaAndPos(lemmaAndPos); for (T rule : rules) { if (isRelevantRule(rule)) { NodeInfo newNodeInfo = new DefaultNodeInfo(rule.getRhsLemma(), rule.getRhsLemma(), node.getInfo().getNodeInfo().getSerial(), node.getInfo().getNodeInfo().getNamedEntityAnnotation(), new DefaultSyntacticInfo(rule.getRhsPos())); RuleSubstituteNodeSpecification<T> spec = createSpec(node, newNodeInfo,ruleBaseName, rule); // new RuleSubstituteNodeSpecification<T>(node, newNodeInfo, node.getInfo().getAdditionalNodeInformation(), rule.getConfidence(), ruleBaseName, rule); addAdditionalDescription(spec,rule); specs.add(spec); } } } } } }
Info newInfo = new DefaultInfo(null, new DefaultNodeInfo(word, lemma, -1, null, syntacticInfo), new DefaultEdgeInfo(relation)); return newInfo;
/** * If rhsInfo has a POS (not {@link WildcardPartOfSpeech}), copy it to treeInfo. Return treeInfo * @param treeInfo * @param rhsInfo * @return */ public static NodeInfo combineNodeInfo(Info treeInfo, Info rhsInfo) { NodeInfo treeNodeInfo = treeInfo.getNodeInfo(); if (rhsInfo != null && rhsInfo.getNodeInfo() != null && rhsInfo.getNodeInfo().getSyntacticInfo() != null && rhsInfo.getNodeInfo().getSyntacticInfo().getPartOfSpeech() != null && !WildcardPartOfSpeech.isWildCardPOS(rhsInfo.getNodeInfo().getSyntacticInfo().getPartOfSpeech())) { // treeInfo with rhsInfo's syntactic info return new DefaultNodeInfo(treeNodeInfo.getWord(), treeNodeInfo.getWordLemma(), treeNodeInfo.getSerial(), treeNodeInfo.getNamedEntityAnnotation(), rhsInfo.getNodeInfo().getSyntacticInfo()); } else return treeNodeInfo; } }
NodeInfo newNodeInfo = new DefaultNodeInfo(word, normalizedLemma, node.getInfo().getNodeInfo().getSerial(), node.getInfo().getNodeInfo().getNamedEntityAnnotation(), node.getInfo().getNodeInfo().getSyntacticInfo()); Info newInfo = new DefaultInfo(node.getInfo().getId(), newNodeInfo, node.getInfo().getEdgeInfo()); node.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; }