/** * 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(); }
while( j < posSequences.length && !done){ String p = posSequences[j].getOutcomes().get(i); done = j > 0 && p.equals(actPos[0].getTag()); if(!done){ actPos[j] = getPosTag(posModel,adhocTags,p,language);
+ "does not provide POS tags for each token!"); } else { posList.add(posValue.value().getTag());
@Override public ObjectNode serialize(ObjectMapper mapper, PosTag value){ ObjectNode jPosTag = mapper.createObjectNode(); jPosTag.put("tag", value.getTag()); if(value.getPos().size() == 1){ jPosTag.put("pos",value.getPos().iterator().next().ordinal());
@Override public ObjectNode serialize(ObjectMapper mapper, PosTag value){ ObjectNode jPosTag = mapper.createObjectNode(); jPosTag.put("tag", value.getTag()); if(value.getPos().size() == 1){ jPosTag.put("pos",value.getPos().iterator().next().ordinal());
if((!disjoint(tpc.getLinkedLexicalCategories(), posTag.getCategories())) || (!disjoint(tpc.getLinkedPos(), posTag.getPosHierarchy())) || tpc.getLinkedPosTags().contains(posTag.getTag())){ if(posAnnotation.probability() == Value.UNKNOWN_PROBABILITY || posAnnotation.probability() >= tpc.getMinPosAnnotationProbability()){ if((!Collections.disjoint(tpc.getMatchedLexicalCategories(), posTag.getCategories())) || (!Collections.disjoint(tpc.getMatchedPos(), posTag.getPosHierarchy())) || tpc.getMatchedPosTags().contains(posTag.getTag())){ if(posAnnotation.probability() == Value.UNKNOWN_PROBABILITY || posAnnotation.probability() >= tpc.getMinPosAnnotationProbability()){
if((!disjoint(tpc.getLinkedLexicalCategories(), posTag.getCategories())) || (!disjoint(tpc.getLinkedPos(), posTag.getPosHierarchy())) || tpc.getLinkedPosTags().contains(posTag.getTag())){ if(posAnnotation.probability() == Value.UNKNOWN_PROBABILITY || posAnnotation.probability() >= tpc.getMinPosAnnotationProbability()){ if((!Collections.disjoint(tpc.getMatchedLexicalCategories(), posTag.getCategories())) || (!Collections.disjoint(tpc.getMatchedPos(), posTag.getPosHierarchy())) || tpc.getMatchedPosTags().contains(posTag.getTag())){ if(posAnnotation.probability() == Value.UNKNOWN_PROBABILITY || posAnnotation.probability() >= tpc.getMinPosAnnotationProbability()){
/** * 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()))); } }