@Override public boolean evaluate(Object span) { return types.contains(((Span)span).getType()); } });
@Override public boolean evaluate(Object span) { return types.contains(((Span)span).getType()); } });
@Override public boolean evaluate(Object span) { return types.contains(((Span)span).getType()); } });
@Override public boolean evaluate(Object span) { return types.contains(((Span)span).getType()); } });
@Override public boolean equals(Object obj) { return obj instanceof SpanImpl && getType() == ((Span)obj).getType() && Arrays.equals(this.span, ((SpanImpl)obj).span); }
@Override public boolean equals(Object obj) { return obj instanceof SpanImpl && getType() == ((Span)obj).getType() && Arrays.equals(this.span, ((SpanImpl)obj).span); }
private void logChunks(AnalysedText at){ Iterator<Span> it = at.getEnclosed(EnumSet.of(SpanTypeEnum.Sentence, SpanTypeEnum.Chunk)); while(it.hasNext()){ Span span = it.next(); if(span.getType() == SpanTypeEnum.Chunk){ log.trace(" > {} {}",span,span.getSpan()); } else { log.trace(" > {}",span); } for(Value<PhraseTag> value : span.getAnnotations(PHRASE_ANNOTATION)){ log.trace(" - {}",value); } } }
while(tokenIt.hasNext()){ Span span = tokenIt.next(); switch (span.getType()) { case Token: Token word = (Token)span;
private ObjectNode writeSpan(Span span) throws IOException { log.trace("wirte {}",span); ObjectNode jSpan = mapper.createObjectNode(); jSpan.put("type", span.getType().name()); jSpan.put("start", span.getStart()); jSpan.put("end", span.getEnd()); for(String key : span.getKeys()){ List<Value<?>> values = span.getValues(key); if(values.size() == 1){ jSpan.put(key, writeValue(values.get(0))); } else { ArrayNode jValues = jSpan.putArray(key); for(Value<?> value : values){ jValues.add(writeValue(value)); } jSpan.put(key, jValues); } } log.trace(" ... {}",jSpan); return jSpan; }
private ObjectNode writeSpan(Span span) throws IOException { log.trace("wirte {}",span); ObjectNode jSpan = mapper.createObjectNode(); jSpan.put("type", span.getType().name()); jSpan.put("start", span.getStart()); jSpan.put("end", span.getEnd()); for(String key : span.getKeys()){ List<Value<?>> values = span.getValues(key); if(values.size() == 1){ jSpan.put(key, writeValue(values.get(0))); } else { ArrayNode jValues = jSpan.putArray(key); for(Value<?> value : values){ jValues.add(writeValue(value)); } jSpan.put(key, jValues); } } log.trace(" ... {}",jSpan); return jSpan; }
@Override public int compareTo(Span o) { if(context != null && o.getContext() != null && !context.equals(o.getContext())){ log.warn("Comparing Spans with different Context. This is not an " + "intended usage of this class as start|end|type parameters " + "do not have a natural oder over different texts."); log.info("This will sort Spans based on start|end|type parameters "+ "regardless that the might be over different texts!"); //TODO consider throwing an IllegalStateExcetion! } //Compare Integers ASC (used here three times) // (x < y) ? -1 : ((x == y) ? 0 : 1); int start = (span[0] < o.getStart()) ? -1 : ((span[0] == o.getStart()) ? 0 : 1); if(start == 0){ //sort end in DESC order int end = (span[1] < o.getEnd()) ? 1 : ((span[1] == o.getEnd()) ? 0 : -1); //if start AND end is the same compare based on the span type //Natural order of span types is defined by the Enum.ordinal() int o1 = getType().ordinal(); int o2 = o.getType().ordinal(); return end != 0 ? end : (o1 < o2) ? -1 : ((o1 == o2) ? 0 : 1); } else { return start; } }
@Override public int compareTo(Span o) { if(context != null && o.getContext() != null && !context.equals(o.getContext())){ log.warn("Comparing Spans with different Context. This is not an " + "intended usage of this class as start|end|type parameters " + "do not have a natural oder over different texts."); log.info("This will sort Spans based on start|end|type parameters "+ "regardless that the might be over different texts!"); //TODO consider throwing an IllegalStateExcetion! } //Compare Integers ASC (used here three times) // (x < y) ? -1 : ((x == y) ? 0 : 1); int start = (span[0] < o.getStart()) ? -1 : ((span[0] == o.getStart()) ? 0 : 1); if(start == 0){ //sort end in DESC order int end = (span[1] < o.getEnd()) ? 1 : ((span[1] == o.getEnd()) ? 0 : -1); //if start AND end is the same compare based on the span type //Natural order of span types is defined by the Enum.ordinal() int o1 = getType().ordinal(); int o2 = o.getType().ordinal(); return end != 0 ? end : (o1 < o2) ? -1 : ((o1 == o2) ? 0 : 1); } else { return start; } }
@Override public ObjectNode serialize(ObjectMapper mapper, CorefFeature coref) { ObjectNode jCoref = mapper.createObjectNode(); jCoref.put(IS_REPRESENTATIVE_TAG, coref.isRepresentative()); Set<Span> mentions = coref.getMentions(); ArrayNode jMentions = mapper.createArrayNode(); for(Span mention : mentions) { ObjectNode jMention = mapper.createObjectNode(); jMention.put(MENTION_TYPE_TAG, mention.getType().toString()); jMention.put(MENTION_START_TAG, mention.getStart()); jMention.put(MENTION_END_TAG, mention.getEnd()); jMentions.add(jMention); } jCoref.put(MENTIONS_TAG, jMentions); return jCoref; }
@Override public ObjectNode serialize(ObjectMapper mapper, CorefFeature coref) { ObjectNode jCoref = mapper.createObjectNode(); jCoref.put(IS_REPRESENTATIVE_TAG, coref.isRepresentative()); Set<Span> mentions = coref.getMentions(); ArrayNode jMentions = mapper.createArrayNode(); for(Span mention : mentions) { ObjectNode jMention = mapper.createObjectNode(); jMention.put(MENTION_TYPE_TAG, mention.getType().toString()); jMention.put(MENTION_START_TAG, mention.getStart()); jMention.put(MENTION_END_TAG, mention.getEnd()); jMentions.add(jMention); } jCoref.put(MENTIONS_TAG, jMentions); return jCoref; }
span.getType() == SpanTypeEnum.Text ? -1 : span.getEnd()); if(!contextOnlyUriScheme || span.getType() == SpanTypeEnum.Text){ graph.add(new TripleImpl(segment, RDF_TYPE, Nif20.RFC5147String.getUri())); lf.createTypedLiteral(span.getEnd()))); String content = text.getSpan(); if(span.getType() != SpanTypeEnum.Text){ graph.add(new TripleImpl(segment, RDF_TYPE, Nif20.String.getUri())); switch (span.getType()) { case Token: graph.add(new TripleImpl(segment, RDF_TYPE, Nif20.Word.getUri()));
switch (span.getType()) { case Sentence: if(sentence != null && writePrevNext){
@Override public ObjectNode serialize(ObjectMapper mapper, DependencyRelation relation) { ObjectNode jDependencyRelation = mapper.createObjectNode(); GrammaticalRelationTag gramRelTag = relation.getGrammaticalRelationTag(); jDependencyRelation.put(RELATION_TYPE_TAG, gramRelTag.getTag()); jDependencyRelation.put(RELATION_STANBOL_TYPE_TAG, gramRelTag.getGrammaticalRelation().ordinal()); jDependencyRelation.put(RELATION_IS_DEPENDENT_TAG, (relation.isDependent())); Span partner = relation.getPartner(); if (partner != null) { jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, partner.getType().toString()); jDependencyRelation.put(RELATION_PARTNER_START_TAG, partner.getStart()); jDependencyRelation.put(RELATION_PARTNER_END_TAG, partner.getEnd()); } else { jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, ROOT_TAG); jDependencyRelation.put(RELATION_PARTNER_START_TAG, 0); jDependencyRelation.put(RELATION_PARTNER_END_TAG, 0); } return jDependencyRelation; }
@Override public ObjectNode serialize(ObjectMapper mapper, DependencyRelation relation) { ObjectNode jDependencyRelation = mapper.createObjectNode(); GrammaticalRelationTag gramRelTag = relation.getGrammaticalRelationTag(); jDependencyRelation.put(RELATION_TYPE_TAG, gramRelTag.getTag()); jDependencyRelation.put(RELATION_STANBOL_TYPE_TAG, gramRelTag.getGrammaticalRelation().ordinal()); jDependencyRelation.put(RELATION_IS_DEPENDENT_TAG, (relation.isDependent())); Span partner = relation.getPartner(); if (partner != null) { jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, partner.getType().toString()); jDependencyRelation.put(RELATION_PARTNER_START_TAG, partner.getStart()); jDependencyRelation.put(RELATION_PARTNER_END_TAG, partner.getEnd()); } else { jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, ROOT_TAG); jDependencyRelation.put(RELATION_PARTNER_START_TAG, 0); jDependencyRelation.put(RELATION_PARTNER_END_TAG, 0); } return jDependencyRelation; }
graph.add(new TripleImpl(segment, StringOntology.endIndex.getUri(), lf.createTypedLiteral(span.getEnd()))); switch (span.getType()) { case Token: graph.add(new TripleImpl(segment, RDF_TYPE, SsoOntology.Word.getUri()));
graph.add(new TripleImpl(segment, StringOntology.endIndex.getUri(), lf.createTypedLiteral(span.getEnd()))); switch (span.getType()) { case Token: graph.add(new TripleImpl(segment, RDF_TYPE, SsoOntology.Word.getUri()));