/** * 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; } }
public static <T extends Info, S extends AbstractNode<T,S>> Map<String,S> mapVarIdToNode(S tree) { Map<String,S> ret = new LinkedHashMap<String, S>(); for (S node : TreeIterator.iterableTree(tree)) { if (InfoGetFields.isVariable(node.getInfo())) { Integer varIdInteger = node.getInfo().getNodeInfo().getVariableId(); String varId = varIdInteger.toString(); ret.put(varId,node); } } return ret; }
@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; }
int id = current_tree.getInfo().getNodeInfo().getSerial(); String word_lemma = current_tree.getInfo().getNodeInfo().getWordLemma(); PartOfSpeech word_pos = current_tree.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech();
word = node.getInfo().getNodeInfo().getWordLemma(); pos = node.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech().getStringRepresentation(); sbPos.append(pos); sbWords.append(word);
/** * Return a String that represent that NP-parts array (it may filter some of the word if not needed) * @param nodes * @return * @throws InitException - if {@link ClassUtils} was not initialized. */ protected String getFinalStringRepresentation(List<NodeInfo> nodes, NodeInfo NPsourceNode) throws InitException{ NodeInfo[] sortedNodes = sortNodes(nodes); String stringRep = new String(); LinkedList<NodeInfo> filteredNodes = new LinkedList<NodeInfo>(); filteredNodes = filterNodesArray(sortedNodes,NPsourceNode); filteredNodes = filterFirstLastNodes(filteredNodes); if (filteredNodes.size() <= m_maxNPSize) //only save that NP if less then 7 words length { //Write array to string for (int i = 0; i < filteredNodes.size(); i++) { if (!(stringRep.isEmpty())) //if it's not the first word { stringRep = stringRep + " "; } stringRep = stringRep + filteredNodes.get(i).getWordLemma(); } } return stringRep; }
&&(!UtilClass.isANoun(nodes.getLast().getSyntacticInfo().getPartOfSpeech()))) PartOfSpeech firstpos = nodes.getFirst().getSyntacticInfo().getPartOfSpeech(); while ((nodes.size() > 0) && (!( (UtilClass.isANoun(firstpos)) firstpos = nodes.getFirst().getSyntacticInfo().getPartOfSpeech();
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); } } } } } }
@Override protected String getWordOf(BasicNode node) { String ret = null; try { ret = node.getInfo().getNodeInfo().getWord(); } catch(NullPointerException e) {} return ret; } }
public static boolean infoIsNamedEntity(Info info) { boolean ret = false; if (info!=null){if(info.getNodeInfo()!=null){if(info.getNodeInfo().getNamedEntityAnnotation()!=null) { ret = true; }}} return ret; }
try if (node.getInfo().getNodeInfo().getVariableId()!=null) lemma = "*"+node.getInfo().getNodeInfo().getVariableId().toString(); if (node.getInfo().getNodeInfo().isVariable()) var = node.getInfo().getNodeInfo().getVariableId().toString();
if (leftInfo.getNodeInfo().isVariable()) throw new EntailmentCompilationException("A \""+ AlignmentType.COPY_LEMMA.name() + "\" cannot come out of a variable node"); lemma = leftInfo.getNodeInfo().getWordLemma(); word = leftInfo.getNodeInfo().getWord(); // if the lemma is copied, the word is copied with it break; case COPY_TAG: syntacticInfo = leftInfo.getNodeInfo().getSyntacticInfo(); break; case COPY_REL:
int id = current_tree.getInfo().getNodeInfo().getSerial(); String word_lemma = current_tree.getInfo().getNodeInfo().getWordLemma(); PartOfSpeech word_pos = current_tree.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech();
word = node.getInfo().getNodeInfo().getWordLemma(); pos = node.getInfo().getNodeInfo().getSyntacticInfo().getPartOfSpeech().getStringRepresentation();
/** * Return a String that represent that NP-parts array (it may filter some of the word if not neeeded) * @param nodes * @return * @throws InitException */ protected String getFinalStringRepresentation(List<NodeInfo> nodes, NodeInfo NPsourceNode) throws InitException{ NodeInfo[] sortedNodes = sortNodes(nodes); String stringRep = new String(); LinkedList<NodeInfo> filteredNodes = new LinkedList<NodeInfo>(); filteredNodes = filterNodesArray(sortedNodes,NPsourceNode); filteredNodes = filterFirstLastNodes(filteredNodes); if (filteredNodes.size() <= m_maxNPSize) //only save that NP if less then 7 words length { //Write array to string for (int i = 0; i < filteredNodes.size(); i++) { if (!(stringRep.isEmpty())) //if it's not the first word { stringRep = stringRep + " "; } stringRep = stringRep + filteredNodes.get(i).getWordLemma(); } } return stringRep; }
&&(!UtilClass.isANoun(nodes.getLast().getSyntacticInfo().getPartOfSpeech()))) PartOfSpeech firstpos = nodes.getFirst().getSyntacticInfo().getPartOfSpeech(); while ((nodes.size() > 0) && (!( (UtilClass.isANoun(firstpos)) firstpos = nodes.getFirst().getSyntacticInfo().getPartOfSpeech();
/*** * 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; }