@Override public Set<LexicalCategory> getCategories(PosTag posTag) { return posTag.getCategories(); }
/** * If the current Token should be considered for counting distances to * negations and nouns * @param token * @param language * @return */ private boolean isCountable(Token token, String language){ Value<PosTag> posAnnotation = token.getAnnotation(NlpAnnotations.POS_ANNOTATION); if(posAnnotation != null && !Collections.disjoint(countableLexCats, posAnnotation.value().getCategories())){ return true; } else { return false; } }
/** * Checks if a posTag matches against this TokenTypeDefinition * @param posTag the posTag to check * @return <code>true</code> in case of a match. Otherwise <code>false</code> * @throws NullPointerException if the parsed posTag is <code>null</code> */ public boolean matches(PosTag posTag){ //check against incldues categories, posTags and tags boolean matches = (!Collections.disjoint(posTag.getCategories(), categories)) || (!Collections.disjoint(posTag.getPosHierarchy(), posTags)) || tags.contains(posTag.getTag()); //if there is a match we need still to check for excluded POS tags return matches ? Collections.disjoint(posTag.getPosHierarchy(),excludedPosTags) : false; }
/** * used for trace level logging of Tokens part of a chunk * @param token * @return */ private String logPosCategories(Token token){ List<Value<PosTag>> posTags = token.getAnnotations(POS_ANNOTATION); List<String> catNames = new ArrayList<String>(posTags.size()); for(Value<PosTag> tag : posTags){ Set<LexicalCategory> cats = tag.value().getCategories(); if(cats.size() > 1){ catNames.add(cats.toString()); } else if(!cats.isEmpty()){ catNames.add(cats.iterator().next().toString()); } else { catNames.add(tag.value().getTag()); } } return catNames.toString(); }
if(!value.getCategories().isEmpty()){ categories.addAll(value.getCategories()); for(Pos pos : value.getPos()){ categories.removeAll(pos.categories());
if(!value.getCategories().isEmpty()){ categories.addAll(value.getCategories()); for(Pos pos : value.getPos()){ categories.removeAll(pos.categories());
log.debug(" [{}] '{}' pos: {}, sentiment {}", new Object[]{ addToList ? sentimentTokens.size() : "-", word.getSpan(),pos.value().getCategories(), sentiment == null ? "none" : sentiment.getValue()});
for(LexicalCategory cat :posAnno.value().getCategories()){ if(!tokenLexCats.containsKey(cat)){ //do not override with lover prob tokenLexCats.put(cat, posAnno.probability()); Set<LexicalCategory> mfCats = EnumSet.noneOf(LexicalCategory.class); for(PosTag mfPos : mf.getPosList()){ mfCats.addAll(mfPos.getCategories());
if(tag.probability() == Value.UNKNOWN_PROBABILITY || tag.probability() >= MIN_POS_CONF || !Collections.disjoint(tag.value().getCategories(),PREF_LEX_CAT)){ posTag = tag.value(); break;
if((!disjoint(tpc.getLinkedLexicalCategories(), posTag.getCategories())) || (!disjoint(tpc.getLinkedPos(), posTag.getPosHierarchy())) || tpc.getLinkedPosTags().contains(posTag.getTag())){ PosTag posTag = posAnnotation.value(); if(posTag.isMapped()){ if((!Collections.disjoint(tpc.getMatchedLexicalCategories(), posTag.getCategories())) || (!Collections.disjoint(tpc.getMatchedPos(), posTag.getPosHierarchy())) || tpc.getMatchedPosTags().contains(posTag.getTag())){ for(Value<MorphoFeatures> morphoAnnotation : morphoAnnotations){ for(PosTag posTag : morphoAnnotation.value().getPosList()){ if(!disjoint(selectedPosTag.getCategories(),posTag.getCategories())){ mf = morphoAnnotation.value(); break selectMorphoFeature; //stop after finding the first one
if((!disjoint(tpc.getLinkedLexicalCategories(), posTag.getCategories())) || (!disjoint(tpc.getLinkedPos(), posTag.getPosHierarchy())) || tpc.getLinkedPosTags().contains(posTag.getTag())){ PosTag posTag = posAnnotation.value(); if(posTag.isMapped()){ if((!Collections.disjoint(tpc.getMatchedLexicalCategories(), posTag.getCategories())) || (!Collections.disjoint(tpc.getMatchedPos(), posTag.getPosHierarchy())) || tpc.getMatchedPosTags().contains(posTag.getTag())){ for(Value<MorphoFeatures> morphoAnnotation : morphoAnnotations){ for(PosTag posTag : morphoAnnotation.value().getPosList()){ if(!disjoint(selectedPosTag.getCategories(),posTag.getCategories())){ mf = morphoAnnotation.value(); break selectMorphoFeature; //stop after finding the first one
for(PosTag pos: getPosList()){ if(pos.isMapped()){ for(LexicalCategory cat : pos.getCategories()){ result.add(new TripleImpl(textAnnotation, RDF_TYPE, cat.getUri()));
/** * Writes the {@link NlpAnnotations#POS_ANNOTATION} as NIF 1.0 to the parsed * RDF graph by using the parsed segmentUri as subject * @param graph the graph * @param annotated the annotated element (e.g. a {@link Token}) * @param segmentUri the URI of the resource representing the parsed * annotated element in the graph */ public static void writePos(Graph graph, Annotated annotated, IRI segmentUri) { Value<PosTag> posTag = annotated.getAnnotation(NlpAnnotations.POS_ANNOTATION); if(posTag != null){ if(posTag.value().isMapped()){ for(Pos pos : posTag.value().getPos()){ graph.add(new TripleImpl(segmentUri, Nif20.oliaCategory.getUri(), pos.getUri())); } for(LexicalCategory cat : posTag.value().getCategories()){ graph.add(new TripleImpl(segmentUri, Nif20.oliaCategory.getUri(), cat.getUri())); } } graph.add(new TripleImpl(segmentUri, Nif20.posTag.getUri(), lf.createTypedLiteral(posTag.value().getTag()))); //set the oliaConf //remove existing conf values (e.g. for a single word phrase) setOliaConf(graph, segmentUri, posTag); } } /**
/** * Writes the {@link NlpAnnotations#POS_ANNOTATION} as NIF 1.0 to the parsed * RDF graph by using the parsed segmentUri as subject * @param graph the graph * @param annotated the annotated element (e.g. a {@link Token}) * @param segmentUri the URI of the resource representing the parsed * annotated element in the graph */ public static void writePos(Graph graph, Annotated annotated, IRI segmentUri) { Value<PosTag> posTag = annotated.getAnnotation(NlpAnnotations.POS_ANNOTATION); if(posTag != null){ if(posTag.value().isMapped()){ for(Pos pos : posTag.value().getPos()){ graph.add(new TripleImpl(segmentUri, SsoOntology.oliaLink.getUri(), pos.getUri())); } for(LexicalCategory cat : posTag.value().getCategories()){ graph.add(new TripleImpl(segmentUri, SsoOntology.oliaLink.getUri(), cat.getUri())); } } graph.add(new TripleImpl(segmentUri, SsoOntology.posTag.getUri(), lf.createTypedLiteral(posTag.value().getTag()))); graph.add(new TripleImpl(segmentUri, ENHANCER_CONFIDENCE, lf.createTypedLiteral(posTag.probability()))); } }
/** * Writes the {@link NlpAnnotations#POS_ANNOTATION} as NIF 1.0 to the parsed * RDF graph by using the parsed segmentUri as subject * @param graph the graph * @param annotated the annotated element (e.g. a {@link Token}) * @param segmentUri the URI of the resource representing the parsed * annotated element in the graph */ public static void writePos(Graph graph, Annotated annotated, IRI segmentUri) { Value<PosTag> posTag = annotated.getAnnotation(NlpAnnotations.POS_ANNOTATION); if(posTag != null){ if(posTag.value().isMapped()){ for(Pos pos : posTag.value().getPos()){ graph.add(new TripleImpl(segmentUri, SsoOntology.oliaLink.getUri(), pos.getUri())); } for(LexicalCategory cat : posTag.value().getCategories()){ graph.add(new TripleImpl(segmentUri, SsoOntology.oliaLink.getUri(), cat.getUri())); } } graph.add(new TripleImpl(segmentUri, SsoOntology.posTag.getUri(), lf.createTypedLiteral(posTag.value().getTag()))); graph.add(new TripleImpl(segmentUri, ENHANCER_CONFIDENCE, lf.createTypedLiteral(posTag.probability()))); } }