diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c90c6ee36..dab401a22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ ANNIS is a frontend to the graphANNIS webservice, which has its [own changelog]( ## [Unreleased] +### Added + +- Visualizer `arch_dependency` allows to highlight roots with explicit edges by setting a label value that identifies such edges. + The value is set with mapping `root_label`. + ## [4.16.0] - 2026-10-09 ### Added diff --git a/src/main/java/org/corpus_tools/annis/gui/visualizers/iframe/dependency/VakyarthaDependencyTree.java b/src/main/java/org/corpus_tools/annis/gui/visualizers/iframe/dependency/VakyarthaDependencyTree.java index 9c68fe0871..5b7b492116 100644 --- a/src/main/java/org/corpus_tools/annis/gui/visualizers/iframe/dependency/VakyarthaDependencyTree.java +++ b/src/main/java/org/corpus_tools/annis/gui/visualizers/iframe/dependency/VakyarthaDependencyTree.java @@ -14,7 +14,6 @@ package org.corpus_tools.annis.gui.visualizers.iframe.dependency; -import com.google.common.collect.Range; import java.io.IOException; import java.io.Writer; import java.util.Comparator; @@ -24,6 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; + import org.apache.commons.lang3.StringUtils; import org.corpus_tools.annis.gui.Helper; import org.corpus_tools.annis.gui.MatchedNodeColors; @@ -44,6 +44,8 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import com.google.common.collect.Range; + /** * Provides a dependence visualization based on vakyartha visualization, which was developed by Kim * Gerdes. @@ -55,7 +57,12 @@ * * Mappings:
* If a annotation key is specified with node_key:key, all nodes which carry this annotation - * are searched for pointing relations and instead of the token span the annotation value is used. + * are searched for pointing relations and instead of the token span the annotation value is used.
+ * If root edges should be display, this can be achieved by setting root_label to the edge label + * value that identifies root edges. This, of course, requires these edges to exist.
+ * If the label for root edges is actually contained in a node annotation, the key for the node annotation + * needs to be provided additionally by setting root_label_node_key to the respective qualified + * annotation name. * * @author Thomas Krause {@literal } * @author Benjamin Weißenfels{@literal } @@ -77,6 +84,16 @@ public class VakyarthaDependencyTree extends WriterVisualizer { // NO_UCD (unuse * the token level. */ private final String MAPPING_NODE_KEY = "node_key"; + /** + * If this mapping is set to a string value, any edge holding an edge label with said value + * will be considered a root edge and displayed as such. + * */ + private final String MAPPING_ROOT_LABEL = "root_label"; + /** + * If this is set to an annotation qname, the root label will be looked for on target nodes + * rather than edges. This only works when root_label is set. + */ + private static final String MAPPING_ROOT_LABEL_NODE_KEY = "root_label_node_key"; private Map mappings; @@ -142,11 +159,10 @@ public void printHTMLOutput(VisualizerInput input, Writer writer, TreeSet } } - Map node2Int = new HashMap(); int count = 0; for (SNode tok : selectedNodes) { - node2Int.put(tok, count++); + node2Int.put(tok, count++); } @@ -180,6 +196,8 @@ public void printHTMLOutput(VisualizerInput input, Writer writer, TreeSet println("tokens=new Object();", writer); count = 0; + String nodeRootQname = mappings.get(MAPPING_ROOT_LABEL_NODE_KEY); + for (SNode node : selectedNodes) { JSONObject vakyarthaObject = new JSONObject(); @@ -199,6 +217,12 @@ public void printHTMLOutput(VisualizerInput input, Writer writer, TreeSet JSONObject govs = new JSONObject(); List> sEdges = node.getGraph().getInRelations(node.getId()); + + // if root edges are determined by node labels, this needs to be checked here + String node_label = nodeRootQname == null? null : node.getAnnotation(nodeRootQname).getValue_STEXT(); + if ((node_label != null) && (node_label.equals(mappings.get(MAPPING_ROOT_LABEL)))) { + govs.put("root", node_label); + } for (SRelation e : sEdges) { if (e instanceof SPointingRelation) { @@ -225,8 +249,11 @@ public void printHTMLOutput(VisualizerInput input, Writer writer, TreeSet String label = sRelation.getAnnotations().stream().findFirst() .map(SAnnotation::getValue_STEXT).orElse(""); - - if (sRelation.getSource() != null && node2Int.containsKey(source)) { + + if ((nodeRootQname == null) && (label.equals(mappings.get(MAPPING_ROOT_LABEL)))) { + govs.put("root", label); + } + else if (sRelation.getSource() != null && node2Int.containsKey(source)) { govs.put(String.valueOf(node2Int.get(source)), label); } }