public int compare(S o1, S o2) { boolean serial1Found = false; boolean serial2Found = false; int serial1=0; int serial2=0; try { serial1 = o1.getInfo().getNodeInfo().getSerial(); serial1Found=true; }catch(NullPointerException e){} try { serial2 = o2.getInfo().getNodeInfo().getSerial(); serial2Found=true; }catch(NullPointerException e){} if (serial1Found&&serial2Found) { if (serial1<serial2)return-1; else if (serial1==serial2)return 0; else return 1; } else { if (serial1Found)return -1; else if (serial2Found) return 1; else return 0; } } }
@Override public int compare(BasicNode o1, BasicNode o2) { if (o1.getAntecedent() != null && o2.getAntecedent() == null) { return 1; } else if (o1.getAntecedent() == null && o2.getAntecedent() != null) { return -1; } else { return o1.getInfo().getNodeInfo().getSerial() - o2.getInfo().getNodeInfo().getSerial(); } }
int serial = node.getInfo().getNodeInfo().getSerial(); String word = node.getInfo().getNodeInfo().getWord(); if (word != null)
/*** * Return the token relevant to given node, from given token list. * @param tokenAnnotations a list of tokens, by their order in text * @param node a node from a parse tree * @return * @throws AbstractNodeCasException in case the text covered by the token doesn't match the text in the node */ public static Token nodeToToken(ArrayList<Token> tokenAnnotations, AbstractNode<Info,?> node) throws AbstractNodeCasException { int serial = node.getInfo().getNodeInfo().getSerial(); Token token = tokenAnnotations.get(serial - 1); String tokenText = token.getCoveredText(); String nodeText = node.getInfo().getNodeInfo().getWord(); if (!tokenText.equals(nodeText)) { throw new AbstractNodeCasException( "For node (serial=" + serial + ") with text \"" + nodeText + "\" got token with text \"" + tokenText + "\""); } return token; }
BasicNode node = buildNode(jcas, dependentNode.getInfo().getNodeInfo().getSerial(), id, dependent, depType, governor); extraNodes.add(node); node.setAntecedent(dependentNode);
int serial = node.getInfo().getNodeInfo().getSerial()-1; // this node's id in the original sentence AdditionalNodeInformation info = node.getInfo().getAdditionalNodeInformation(); for (ExtendedNode child : AbstractNodeUtils.treeToList(node)){ ExtendedNode toAdd =AbstractNodeUtils.getDeepAntecedentOf(child); int curId = node.getInfo().getNodeInfo().getSerial()-1; subtree.add(toAdd);
antecedent = mapIdToNode.get(antecedentId); if (antecedent==null)throw new ParserRunException("Antecedent not found for node: "+counterString+".\nParser output was:\n"+listStringToString(parserOutput)+rawTextForExceptionString); serial = antecedent.getInfo().getNodeInfo().getSerial(); pos = InfoGetFields.getPartOfSpeech(antecedent.getInfo());
int id = current_tree.getInfo().getNodeInfo().getSerial(); String word_lemma = current_tree.getInfo().getNodeInfo().getWordLemma(); PartOfSpeech word_pos = current_tree.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech();
int id = current_tree.getInfo().getNodeInfo().getSerial(); String word_lemma = current_tree.getInfo().getNodeInfo().getWordLemma(); PartOfSpeech word_pos = current_tree.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech();
/** * for tracing. */ private static String outNode(BasicNode node) { String result = String.format("id=%s:ser=%d:%s:%s", node.getInfo().getId(), node.getInfo().getNodeInfo().getSerial(), node.getInfo().getNodeInfo().getWord(), node.getInfo().getEdgeInfo().getDependencyRelation()!=null?node.getInfo().getEdgeInfo().getDependencyRelation().getStringRepresentation():"null"); if (node.getAntecedent() != null) { result += String.format("(^%s)", outNode(node.getAntecedent())); } return result; }
subtree.add(tokens.get(e.getInfo().getNodeInfo().getSerial()-1));
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())); }
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); } } } } } }
/** * 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);
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); } } } }