use of org.apache.stanbol.enhancer.nlp.pos.Pos in project stanbol by apache.
the class Nif20Helper method writePos.
/**
* 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);
}
}
use of org.apache.stanbol.enhancer.nlp.pos.Pos in project stanbol by apache.
the class PosTagSupport method serialize.
@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());
} else if (!value.getPos().isEmpty()) {
ArrayNode jPos = mapper.createArrayNode();
for (Pos pos : value.getPos()) {
jPos.add(pos.ordinal());
}
jPosTag.put("pos", jPos);
}
if (!value.getCategories().isEmpty()) {
//we need only the categories not covered by Pos elements
EnumSet<LexicalCategory> categories = EnumSet.noneOf(LexicalCategory.class);
categories.addAll(value.getCategories());
for (Pos pos : value.getPos()) {
categories.removeAll(pos.categories());
}
if (categories.size() == 1) {
jPosTag.put("lc", categories.iterator().next().ordinal());
} else if (!categories.isEmpty()) {
ArrayNode jCategory = mapper.createArrayNode();
for (LexicalCategory lc : categories) {
jCategory.add(lc.ordinal());
}
jPosTag.put("lc", jCategory);
}
}
return jPosTag;
}
use of org.apache.stanbol.enhancer.nlp.pos.Pos in project stanbol by apache.
the class PosTagSupport method parse.
@Override
public PosTag parse(ObjectNode jValue, AnalysedText at) {
PosTagInfo tagInfo = new PosTagInfo();
JsonNode tag = jValue.path("tag");
if (!tag.isTextual()) {
throw new IllegalStateException("Unable to parse PosTag. The value of the " + "'tag' field MUST have a textual value (json: " + jValue + ")");
}
tagInfo.tag = tag.getTextValue();
if (jValue.has("lc")) {
tagInfo.categories = JsonUtils.parseEnum(jValue, "lc", LexicalCategory.class);
} else {
tagInfo.categories = EnumSet.noneOf(LexicalCategory.class);
}
if (jValue.has("pos")) {
tagInfo.pos = JsonUtils.parseEnum(jValue, "pos", Pos.class);
} else {
tagInfo.pos = EnumSet.noneOf(Pos.class);
}
PosTag posTag = posTagCache.get(tagInfo);
if (posTag == null) {
posTag = new PosTag(tagInfo.tag, tagInfo.categories, tagInfo.pos);
posTagCache.put(tagInfo, posTag);
}
return posTag;
}
use of org.apache.stanbol.enhancer.nlp.pos.Pos in project stanbol by apache.
the class NIFHelper method writePos.
/**
* 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())));
}
}
Aggregations