use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class SpanHTMLOutputter method outputAnnotation.
private void outputAnnotation(SNode span, String matchedQName, SortedMap<Long, List<OutputItem>> outputStartTags, SortedMap<Long, List<OutputItem>> outputEndTags, int priority) {
long left;
long right;
RelannisNodeFeature feat = (RelannisNodeFeature) span.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
left = feat.getLeftToken();
right = feat.getRightToken();
SAnnotation matchedAnnotation;
if (type == Type.META_NAME) {
// constant property is used to store metadata names, see VisParser.java
matchedAnnotation = span.getAnnotation("meta::" + constant);
} else {
matchedAnnotation = span.getAnnotation(matchedQName);
}
String value;
// output to an inner text node
switch(type) {
case CONSTANT:
value = constant;
break;
case HTML_TEMPLATE:
String original = constant;
String innerValue = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
String innerAnno = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
value = original.replaceAll("%%value%%", innerValue);
value = value.replaceAll("%%anno%%", innerAnno);
break;
case VALUE:
value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
break;
case ESCAPED_VALUE:
value = htmlEscaper.escape(matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT());
break;
case ANNO_NAME:
value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
break;
case META_NAME:
value = matchedAnnotation.getValue() == null ? "NULL" : matchedAnnotation.getValue().toString();
matchedQName = "meta::" + metaname;
break;
default:
value = "";
break;
}
outputAny(left, right, matchedQName, value, outputStartTags, outputEndTags, priority);
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class SaltAnnotateExtractor method createMissingSpanningRelations.
/**
* Use the left/right token index of the spans to create spanning relations
* when this did not happen yet.
*
* @param graph
* @param nodeByRankID
* @param numberOfRelations
*/
private void createMissingSpanningRelations(SDocumentGraph graph, FastInverseMap<Long, SNode> nodeByRankID, TreeMap<Long, SToken> tokenByIndex, Map<String, ComponentEntry> componentForSpan, AtomicInteger numberOfRelations) {
// add the missing spanning relations for each continuous span of the graph
for (SSpan span : graph.getSpans()) {
long pre = 1;
RelannisNodeFeature featSpan = RelannisNodeFeature.extract(span);
ComponentEntry spanComponent = componentForSpan.get(span.getId());
if (spanComponent != null && featSpan != null && featSpan.getLeftToken() >= 0 && featSpan.getRightToken() >= 0) {
for (long i = featSpan.getLeftToken(); i <= featSpan.getRightToken(); i++) {
SToken tok = tokenByIndex.get(i);
if (tok != null) {
boolean missing = true;
List<SRelation<SNode, SNode>> existingRelations = graph.getRelations(span.getId(), tok.getId());
if (existingRelations != null) {
for (Relation e : existingRelations) {
if (e instanceof SSpanningRelation) {
missing = false;
break;
}
}
}
if (missing) {
String type = "c";
SLayer layer = findOrAddSLayer(spanComponent.getNamespace(), graph);
createNewRelation(graph, span, tok, null, type, spanComponent.getId(), layer, pre++, nodeByRankID, numberOfRelations);
}
}
// end if token exists
}
// end for each covered token index
}
}
// end for each span
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class SingleResultPanel method getIds.
private MinMax getIds(SDocumentGraph graph) {
List<SToken> sTokens = graph.getTokens();
MinMax minMax = new MinMax();
minMax.min = Long.MAX_VALUE;
minMax.max = Long.MIN_VALUE;
if (segmentationName == null) {
minMax.segName = "tokens";
if (sTokens != null) {
for (SToken t : sTokens) {
SFeature feature = t.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE);
if (feature != null && feature.getValue() instanceof RelannisNodeFeature) {
RelannisNodeFeature f = (RelannisNodeFeature) feature.getValue();
if (minMax.min > f.getTokenIndex()) {
minMax.min = f.getTokenIndex();
}
if (minMax.max < f.getTokenIndex()) {
minMax.max = f.getTokenIndex();
}
}
}
}
} else {
minMax.segName = segmentationName;
List<SNode> nodes = CommonHelper.getSortedSegmentationNodes(segmentationName, graph);
for (SNode n : nodes) {
RelannisNodeFeature f = RelannisNodeFeature.extract(n);
if (minMax.min > f.getSegIndex()) {
minMax.min = f.getSegIndex();
}
if (minMax.max < f.getSegIndex()) {
minMax.max = f.getSegIndex();
}
}
}
minMax.min++;
minMax.max++;
return minMax;
}
Aggregations