@Override public String toString() { return "olia:" + name(); } }
@Override public boolean equals(Object obj) { return super.equals(obj) && obj instanceof PhraseTag && (category == null && ((PhraseTag)obj).category == null) || (category != null && category.equals(((PhraseTag)obj).category)); }
if(pos.isMapped()){ for(LexicalCategory cat : pos.getCategories()){ result.add(new TripleImpl(textAnnotation, RDF_TYPE, cat.getUri()));
@Override public PhraseTag parse(ObjectNode jValue, AnalysedText at) { JsonNode tag = jValue.path("tag"); if(!tag.isTextual()){ throw new IllegalStateException("Unable to parse PhraseTag. The value of the " +"'tag' field MUST have a textual value (json: "+jValue+")"); } JsonNode jCat = jValue.path("lc"); LexicalCategory lc = null; if(jCat.isTextual()){ try { lc = LexicalCategory.valueOf(jCat.getTextValue()); } catch (IllegalArgumentException e) { log.warn("Unable to parse category for PhraseTag from '" +jCat.getTextValue()+"' (will create with tag only)!",e); } } else if(jCat.isInt()){ lc = LexicalCategory.values()[jCat.getIntValue()]; } else if(!jCat.isMissingNode()){ log.warn("Unable to parse category for PhraseTag from "+jCat +"(will create with tag only)"); } return new PhraseTag(tag.getTextValue(),lc); }
@Override public ObjectNode serialize(ObjectMapper mapper, PhraseTag value) { ObjectNode jTag = mapper.createObjectNode(); jTag.put("tag",value.getTag()); if(value.getCategory() != null){ jTag.put("lc", value.getCategory().ordinal()); } return jTag; }
/** * 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(); }
/** * 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); } } /**
@Override public PhraseTag parse(ObjectNode jValue, AnalysedText at) { JsonNode tag = jValue.path("tag"); if(!tag.isTextual()){ throw new IllegalStateException("Unable to parse PhraseTag. The value of the " +"'tag' field MUST have a textual value (json: "+jValue+")"); } JsonNode jCat = jValue.path("lc"); LexicalCategory lc = null; if(jCat.isTextual()){ try { lc = LexicalCategory.valueOf(jCat.getTextValue()); } catch (IllegalArgumentException e) { log.warn("Unable to parse category for PhraseTag from '" +jCat.getTextValue()+"' (will create with tag only)!",e); } } else if(jCat.isInt()){ lc = LexicalCategory.values()[jCat.getIntValue()]; } else if(!jCat.isMissingNode()){ log.warn("Unable to parse category for PhraseTag from "+jCat +"(will create with tag only)"); } return new PhraseTag(tag.getTextValue(),lc); }
@Override public ObjectNode serialize(ObjectMapper mapper, PhraseTag value) { ObjectNode jTag = mapper.createObjectNode(); jTag.put("tag",value.getTag()); if(value.getCategory() != null){ jTag.put("lc", value.getCategory().ordinal()); } return jTag; }
@Override public String toString() { return "olia:" + name(); } }
/** * 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()))); } }
@Override public boolean equals(Object obj) { return super.equals(obj) && obj instanceof PhraseTag && (category == null && ((PhraseTag)obj).category == null) || (category != null && category.equals(((PhraseTag)obj).category)); }
@Override public String toString() { return phraseType.name(); }
/** * 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()))); } }
@Override public String toString() { return String.format("Phrase %s (%s)", tag, category == null ? "none" : category.name()); }
@Override public String toString() { return String.format("Phrase %s (%s)", tag, category == null ? "none" : category.name()); }
LexicalCategory() { this.uri = new IRI(OLIA_NAMESPACE + name()); }
LexicalCategory() { this.uri = new IRI(OLIA_NAMESPACE + name()); }