Search in sources :

Example 11 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class TimelineReconstructor method getMatchedNodes.

private void getMatchedNodes() {
    SFeature matchids = graph.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDIDS);
    if (matchids != null) {
        String[] ids = matchids.getValue_STEXT().split(",");
        this.matchIDs.addAll(Arrays.asList(ids));
    }
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Example 12 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class TimelineReconstructor method convertSpanToToken.

private void convertSpanToToken(SStructuredNode span, String orderName) {
    final Set<String> validSpanAnnos = new HashSet<>(order2spanAnnos.get(orderName));
    if (!nodesToDelete.contains(span)) {
        nodesToDelete.add(span);
        if (textsByName.get(orderName) == null) {
            STextualDS newText = graph.createTextualDS("");
            newText.setName(orderName);
            textsByName.put(orderName, newText);
            textDataByName.put(orderName, new StringBuilder());
        }
        STextualDS textDS = textsByName.get(orderName);
        StringBuilder textData = textDataByName.get(orderName);
        TreeSet<Integer> coveredIdx = new TreeSet<>(spans2TimelinePos.get(span));
        if (!coveredIdx.isEmpty()) {
            SAnnotation textValueAnno = getTextValueAnno(orderName, span);
            if (textValueAnno != null) {
                String textValue = textValueAnno.getValue_STEXT();
                int startTextIdx = textData.length();
                textData.append(textValue);
                int endTextIdx = textData.length();
                SToken newToken = graph.createToken(textDS, startTextIdx, endTextIdx);
                // keep track of changed ids for matches
                if (this.matchIDs.contains(span.getId()))
                    this.oldID2newID.put(span.getId(), newToken.getId());
                // move all features to the new token
                if (span.getFeatures() != null) {
                    for (SFeature feat : span.getFeatures()) {
                        if (!"salt".equals(feat.getNamespace())) {
                            newToken.addFeature(feat);
                        }
                    }
                }
                // move all annotations to the new token
                if (span.getAnnotations() != null) {
                    for (SAnnotation annot : span.getAnnotations()) {
                        if (!"salt".equals(annot.getNamespace()) && !orderName.equals(annot.getName())) {
                            newToken.addAnnotation(annot);
                        }
                    }
                }
                STimelineRelation timeRel = SaltFactory.createSTimelineRelation();
                timeRel.setSource(newToken);
                timeRel.setTarget(graph.getTimeline());
                timeRel.setStart(coveredIdx.first());
                timeRel.setEnd(coveredIdx.last());
                graph.addRelation(timeRel);
                moveRelations(span, newToken, validSpanAnnos, orderName);
            }
        }
    }
}
Also used : SAnnotation(org.corpus_tools.salt.core.SAnnotation) SToken(org.corpus_tools.salt.common.SToken) TreeSet(java.util.TreeSet) STextualDS(org.corpus_tools.salt.common.STextualDS) STimelineRelation(org.corpus_tools.salt.common.STimelineRelation) HashSet(java.util.HashSet) SFeature(org.corpus_tools.salt.core.SFeature)

Example 13 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class RelannisNodeFeature method extract.

public static RelannisNodeFeature extract(SNode node) {
    RelannisNodeFeature featNode = null;
    SFeature sfeatNode = node.getFeature(ANNIS_NS + "::" + FEAT_RELANNIS_NODE);
    if (sfeatNode != null) {
        featNode = (RelannisNodeFeature) sfeatNode.getValue();
    }
    return featNode;
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Example 14 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class EventExtractor method addAnnotationsForNode.

private static void addAnnotationsForNode(SNode node, SDocumentGraph graph, long startTokenIndex, long endTokenIndex, PDFController pdfController, PDFPageHelper pageNumberHelper, AtomicInteger eventCounter, LinkedHashMap<String, ArrayList<Row>> rowsByAnnotation, boolean addMatch, Set<String> mediaLayer, boolean replaceValueWithMediaIcon) {
    List<String> matchedAnnos = new ArrayList<>();
    SFeature featMatchedAnnos = graph.getFeature(ANNIS_NS, FEAT_MATCHEDANNOS);
    if (featMatchedAnnos != null) {
        matchedAnnos = Splitter.on(',').trimResults().splitToList(featMatchedAnnos.getValue_STEXT());
    }
    // check if the span is a matched node
    SFeature featMatched = node.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
    Long matchRaw = featMatched == null ? null : featMatched.getValue_SNUMERIC();
    String matchedQualifiedAnnoName = "";
    if (matchRaw != null && matchRaw <= matchedAnnos.size()) {
        matchedQualifiedAnnoName = matchedAnnos.get((int) ((long) matchRaw) - 1);
    }
    // calculate the left and right values of a span
    // TODO: howto get these numbers with Salt?
    RelannisNodeFeature feat = (RelannisNodeFeature) node.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
    long leftLong = feat.getLeftToken();
    long rightLong = feat.getRightToken();
    leftLong = clip(leftLong, startTokenIndex, endTokenIndex);
    rightLong = clip(rightLong, startTokenIndex, endTokenIndex);
    int left = (int) (leftLong - startTokenIndex);
    int right = (int) (rightLong - startTokenIndex);
    for (SAnnotation anno : node.getAnnotations()) {
        ArrayList<Row> rows = rowsByAnnotation.get(anno.getQName());
        if (rows == null) {
            // try again with only the name
            rows = rowsByAnnotation.get(anno.getName());
        }
        if (rows != null) {
            // only do something if the annotation was defined before
            // 1. give each annotation of each span an own row
            Row r = new Row();
            String id = "event_" + eventCounter.incrementAndGet();
            GridEvent event = new GridEvent(id, left, right, anno.getValue_STEXT());
            event.setTooltip(Helper.getQualifiedName(anno));
            if (addMatch && matchRaw != null) {
                long match = matchRaw;
                if (matchedQualifiedAnnoName.isEmpty()) {
                    // always set the match when there is no matched annotation at all
                    event.setMatch(match);
                } else // check if the annotation also matches
                if (matchedQualifiedAnnoName.equals(anno.getQName())) {
                    event.setMatch(match);
                }
            }
            if (node instanceof SSpan) {
                // calculate overlapped SToken
                List<? extends SRelation<? extends SNode, ? extends SNode>> outEdges = graph.getOutRelations(node.getId());
                if (outEdges != null) {
                    for (SRelation<? extends SNode, ? extends SNode> e : outEdges) {
                        if (e instanceof SSpanningRelation) {
                            SSpanningRelation spanRel = (SSpanningRelation) e;
                            SToken tok = spanRel.getTarget();
                            event.getCoveredIDs().add(tok.getId());
                            // get the STextualDS of this token and add it to the event
                            String textID = getTextID(tok, graph);
                            if (textID != null) {
                                event.setTextID(textID);
                            }
                        }
                    }
                }
            // end if span has out edges
            } else if (node instanceof SToken) {
                event.getCoveredIDs().add(node.getId());
                // get the STextualDS of this token and add it to the event
                String textID = getTextID((SToken) node, graph);
                if (textID != null) {
                    event.setTextID(textID);
                }
            }
            // try to get time annotations
            if (mediaLayer == null || mediaLayer.contains(anno.getQName())) {
                double[] startEndTime = TimeHelper.getOverlappedTime(node);
                if (startEndTime.length == 1) {
                    if (replaceValueWithMediaIcon) {
                        event.setValue(" ");
                        event.setTooltip("play excerpt " + event.getStartTime());
                    }
                    event.setStartTime(startEndTime[0]);
                } else if (startEndTime.length == 2) {
                    event.setStartTime(startEndTime[0]);
                    event.setEndTime(startEndTime[1]);
                    if (replaceValueWithMediaIcon) {
                        event.setValue(" ");
                        event.setTooltip("play excerpt " + event.getStartTime() + "-" + event.getEndTime());
                    }
                }
            }
            r.addEvent(event);
            rows.add(r);
            if (pdfController != null && pdfController.sizeOfRegisterdPDFViewer() > 0) {
                String page = pageNumberHelper.getPageFromAnnotation(node);
                if (page != null) {
                    event.setPage(page);
                }
            }
        }
    }
// end for each annotation of span
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) GridEvent(annis.gui.widgets.grid.GridEvent) SSpan(org.corpus_tools.salt.common.SSpan) SAnnotation(org.corpus_tools.salt.core.SAnnotation) ArrayList(java.util.ArrayList) SToken(org.corpus_tools.salt.common.SToken) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) Row(annis.gui.widgets.grid.Row) SFeature(org.corpus_tools.salt.core.SFeature)

Example 15 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class GridComponent method tokenMatch.

/**
 * Checks if a token is a marked match
 *
 * @param tok the checked token.
 * @return Returns null, if token is not marked.
 */
private Long tokenMatch(SNode tok) {
    // check if the span is a matched node
    SFeature featMatched = tok.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
    Long matchRaw = featMatched == null ? null : featMatched.getValue_SNUMERIC();
    return matchRaw;
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Aggregations

SFeature (org.corpus_tools.salt.core.SFeature)24 SNode (org.corpus_tools.salt.core.SNode)12 RelannisNodeFeature (annis.model.RelannisNodeFeature)8 SToken (org.corpus_tools.salt.common.SToken)8 HashMap (java.util.HashMap)6 SRelation (org.corpus_tools.salt.core.SRelation)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 SAnnotation (org.corpus_tools.salt.core.SAnnotation)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 TreeMap (java.util.TreeMap)3 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)3 SOrderRelation (org.corpus_tools.salt.common.SOrderRelation)3 STextualDS (org.corpus_tools.salt.common.STextualDS)3 AnnotationGraph (annis.model.AnnotationGraph)2 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)2 LinkedHashSet (java.util.LinkedHashSet)2 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)2