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; }
private static <T extends Info, S extends AbstractNode<T,S>> boolean isNamedEntity(S node) { boolean ret = false; try { if (node.getInfo().getNodeInfo().getNamedEntityAnnotation() != null) ret = true; } catch(NullPointerException e) {} return ret; }
public Map<Integer,Double> forSubstitutionMultiWord(Map<Integer,Double> originalFeatureVector, SubstituteNodeSpecificationMultiWord spec) throws TeEngineMlException { Map<Integer,Double> featureVector = new LinkedHashMap<Integer, Double>(); featureVector.putAll(originalFeatureVector); spec.addDescription("Multi-Word"); Set<String> addedHypothesisWord = new LinkedHashSet<String>(); for (String hypothesisWord : spec.getHypothesisWords()) { if (!StringUtil.setContainsIgnoreCase(spec.getTextWords(), hypothesisWord)) { addedHypothesisWord.add(hypothesisWord); } } return updateFeatureVectorForSubstitutionMultiWord(featureVector,spec,spec.getNewNodeInfo().getNamedEntityAnnotation()!=null,addedHypothesisWord); }
if (!rhsLemma.equalsIgnoreCase(lhsLemma)) try{if (rhsNode.getInfo().getNodeInfo().getNamedEntityAnnotation()!=null) namedEntity=true;} catch(NullPointerException e){}
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); } } } } } }
/** * 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);