use of org.corpus_tools.salt.common.STextualDS in project ANNIS by korpling.
the class GridComponent method computeTokenRow.
private Row computeTokenRow(List<SNode> tokens, SDocumentGraph graph, LinkedHashMap<String, ArrayList<Row>> rowsByAnnotation, long startIndex, AtomicInteger tokenOffsetForText) {
/* we will only add tokens of one texts which is mentioned by any
included annotation. */
Set<String> validTextIDs = new HashSet<>();
if (enforcedText == null) {
Iterator<ArrayList<Row>> itAllRows = rowsByAnnotation.values().iterator();
while (itAllRows.hasNext()) {
ArrayList<Row> rowsForAnnotation = itAllRows.next();
for (Row r : rowsForAnnotation) {
validTextIDs.addAll(r.getTextIDs());
}
}
/**
* we want to show all token if no valid text was found and we have only one
* text and the first one if there are more than one text.
*/
List<STextualDS> allTexts = graph.getTextualDSs();
if (validTextIDs.isEmpty() && allTexts != null && (allTexts.size() == 1 || allTexts.size() == 2)) {
validTextIDs.add(allTexts.get(0).getId());
}
} else {
validTextIDs.add(enforcedText.getId());
}
Row tokenRow = new Row();
for (SNode t : tokens) {
// get the Salt ID of the STextualDS of this token
STextualDS tokenText = CommonHelper.getTextualDSForNode(t, graph);
// only add token if text ID matches the valid one
if (tokenText != null && validTextIDs.contains(tokenText.getId())) {
RelannisNodeFeature feat = (RelannisNodeFeature) t.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_RELANNIS_NODE).getValue();
long idxLeft = feat.getLeftToken() - startIndex;
long idxRight = feat.getRightToken() - startIndex;
if (tokenOffsetForText.get() < 0) {
// set the token offset by assuming the first idx must be zero
tokenOffsetForText.set(Math.abs((int) idxLeft));
}
String text = extractTextForToken(t, segmentationName);
GridEvent event = new GridEvent(t.getId(), (int) idxLeft, (int) idxRight, text);
event.setTextID(tokenText.getId());
// check if the token is a matched node
Long match = isCoveredTokenMarked() ? markCoveredTokens(input.getMarkedAndCovered(), t) : tokenMatch(t);
event.setMatch(match);
tokenRow.addEvent(event);
}
}
return tokenRow;
}
use of org.corpus_tools.salt.common.STextualDS in project ANNIS by korpling.
the class KWICVisualizer method createComponent.
@Override
public KWICInterface createComponent(VisualizerInput visInput, VisualizationToggle visToggle) {
MediaController mediaController = VaadinSession.getCurrent().getAttribute(MediaController.class);
PDFController pdfController = VaadinSession.getCurrent().getAttribute(PDFController.class);
List<STextualDS> texts = visInput.getDocument().getDocumentGraph().getTextualDSs();
// having the KWIC nested in a panel can slow down rendering
if (texts.size() == 1) {
// directly return the single non-nested KWIC panel
return new KWICComponent(visInput, mediaController, pdfController, texts.get(0));
} else {
// return a more complicated implementation which can handle several texts
return new KWICMultipleTextComponent(visInput, mediaController, pdfController);
}
}
use of org.corpus_tools.salt.common.STextualDS in project ANNIS by korpling.
the class TimelineReconstructor method createTokenFromSOrder.
private void createTokenFromSOrder() {
nodesToDelete.add(graph.getTextualDSs().get(0));
Map<String, SSpan> rootNodes = new HashMap<>();
// also add nodes that are are marked as start by ANNIS even if they don't have an outgoing order rel
for (SSpan n : graph.getSpans()) {
SFeature feat = n.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_FIRST_NODE_SEGMENTATION_CHAIN);
if (feat != null && feat.getValue_STEXT() != null) {
rootNodes.put(feat.getValue_STEXT(), n);
} else {
// check if there is no incoming SOrderRelation but an outgoing
boolean isRoot = true;
for (SRelation<?, ?> inRel : n.getInRelations()) {
if (inRel instanceof SOrderRelation) {
isRoot = false;
break;
}
}
if (isRoot) {
for (SRelation<?, ?> outRel : n.getOutRelations()) {
if (outRel instanceof SOrderRelation) {
rootNodes.put(((SOrderRelation) outRel).getType(), n);
break;
}
}
}
}
}
// convert all root nodes to spans
for (Map.Entry<String, SSpan> rootEntry : rootNodes.entrySet()) {
SNode root = rootEntry.getValue();
String orderName = rootEntry.getKey();
convertSpanToToken((SSpan) root, orderName);
}
// traverse through all SOrderRelations in order
graph.traverse(new LinkedList<SNode>(rootNodes.values()), GRAPH_TRAVERSE_TYPE.TOP_DOWN_DEPTH_FIRST, "TimeReconstructSOrderRelations", new GraphTraverseHandler() {
@Override
public void nodeReached(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
if (relation instanceof SOrderRelation && currNode instanceof SSpan) {
String orderName = ((SOrderRelation) relation).getType();
if (fromNode != null) {
// add a space to the text
StringBuilder t = textDataByName.get(orderName);
if (t != null) {
t.append(" ");
}
}
convertSpanToToken((SSpan) currNode, orderName);
}
}
@Override
public void nodeLeft(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
}
@Override
public boolean checkConstraint(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation relation, SNode currNode, long order) {
if (relation == null || relation instanceof SOrderRelation) {
return true;
} else {
return false;
}
}
});
// update the text of the TextualDSs
for (Map.Entry<String, StringBuilder> textDataEntry : textDataByName.entrySet()) {
STextualDS textDS = textsByName.get(textDataEntry.getKey());
if (textDS != null) {
textDS.setText(textDataEntry.getValue().toString());
}
}
}
Aggregations