use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class SpanHTMLOutputter method outputToken.
private void outputToken(SToken tok, SortedMap<Long, List<OutputItem>> outputStartTags, SortedMap<Long, List<OutputItem>> outputEndTags, int priority) {
RelannisNodeFeature feat = (RelannisNodeFeature) tok.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
long index = feat.getTokenIndex();
String value;
switch(type) {
case CONSTANT:
value = constant;
break;
case VALUE:
value = CommonHelper.getSpannedText(tok);
break;
case ESCAPED_VALUE:
value = htmlEscaper.escape(CommonHelper.getSpannedText(tok));
break;
case ANNO_NAME:
value = "tok";
break;
default:
value = "";
break;
}
outputAny(index, index, "tok", value, outputStartTags, outputEndTags, priority);
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class VakyarthaDependencyTree method printHTMLOutput.
public void printHTMLOutput(VisualizerInput input, Writer writer, Map<SNode, Integer> selectedNodes) {
SDocumentGraph sDocumentGraph = input.getSResult().getDocumentGraph();
for (SNode n : sDocumentGraph.getNodes()) {
if (selectNode(n)) {
RelannisNodeFeature feat = (RelannisNodeFeature) n.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
int tokenIdx = feat != null ? (int) feat.getTokenIndex() : -1;
selectedNodes.put(n, tokenIdx);
}
}
Map<SNode, Integer> node2Int = new HashMap<SNode, Integer>();
int count = 0;
for (SNode tok : selectedNodes.keySet()) {
node2Int.put(tok, count++);
}
try {
println("<html>", writer);
println("<head>", writer);
LinkedList<String> fontsText = new LinkedList<String>();
LinkedList<String> fontsDep = new LinkedList<String>();
if (input.getFont() != null) {
fontsText.add(input.getFont().getName());
fontsDep.add(input.getFont().getName());
println("<link href=\"" + input.getFont().getUrl() + "\" rel=\"stylesheet\" type=\"text/css\" >", writer);
}
fontsText.add("sans-serif");
fontsDep.add("serif");
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/jquery.js") + "\"></script>", writer);
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/raphael-min.js") + "\"></script>", writer);
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/vakyarthaDependency.js") + "\"></script>", writer);
// output the data for the javascript
println("<script type=\"text/javascript\">", writer);
println("fcolors={};", writer);
println("shownfeatures=[\"t\"];", writer);
println("tokens=new Object();", writer);
count = 0;
for (SNode node : selectedNodes.keySet()) {
JSONObject vakyarthaObject = new JSONObject();
String completeAnnotation = getAnnotation(node);
String annotationValue = completeAnnotation.replaceFirst(".*=", "");
String text = getText(node, input);
// decide, if the visualization is token based.
if (mappings.containsKey(MAPPING_NODE_KEY)) {
vakyarthaObject.put("t", annotationValue);
} else {
vakyarthaObject.put("t", text);
}
vakyarthaObject.put("annotation", annotationValue);
vakyarthaObject.put("text", text);
vakyarthaObject.put("tooltip", completeAnnotation);
JSONObject govs = new JSONObject();
List<SRelation<SNode, SNode>> sEdges = node.getGraph().getInRelations(node.getId());
for (SRelation<? extends SNode, ? extends SNode> e : sEdges) {
if (e instanceof SPointingRelation) {
SPointingRelation sRelation = (SPointingRelation) e;
boolean includeEdge = true;
// check layer
if (input.getNamespace() != null) {
// must be included in the layer in order to be included
includeEdge = false;
if (sRelation.getLayers() != null) {
for (SLayer layer : sRelation.getLayers()) {
if (input.getNamespace().equals(layer.getName())) {
includeEdge = true;
break;
}
}
}
}
if (includeEdge) {
SNode source = (SNode) sRelation.getSource();
String label = "";
for (SAnnotation anno : sRelation.getAnnotations()) {
label = anno.getValue_STEXT();
break;
}
if (sRelation.getSource() != null && node2Int.containsKey(source)) {
govs.put(String.valueOf(node2Int.get(source)), label);
}
}
}
// end if pointing relation
}
vakyarthaObject.put("govs", govs);
JSONObject attris = new JSONObject();
JSONObject tAttris = new JSONObject();
String tokenColor = "black";
if (input.getMarkedAndCovered().containsKey(node)) {
tokenColor = MatchedNodeColors.getHTMLColorByMatch(input.getMarkedAndCovered().get(node));
}
tAttris.put("fill", tokenColor);
tAttris.put("font", "11px " + StringUtils.join(fontsText, ","));
attris.put("t", tAttris);
JSONObject depAttris = new JSONObject();
depAttris.put("fill", "#999");
depAttris.put("font-style", "italic");
depAttris.put("font", "12px " + StringUtils.join(fontsDep, ","));
attris.put("deptext", depAttris);
vakyarthaObject.put("attris", attris);
writer.append("tokens[").append("" + count++).append("]=");
writer.append(vakyarthaObject.toString().replaceAll("\n", " "));
writer.append(";\n");
}
println("</script>", writer);
println("</head>", writer);
println("<body id=\"holder\">", writer);
// the div to render the javascript to
// println(
// "<div id=\"holder\"> </div>",
// writer);
println("</body>", writer);
println("</html>", writer);
} catch (JSONException ex) {
log.error(null, ex);
} catch (IOException ex) {
log.error(null, ex);
}
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class Helper method calculateColorsForMarkedExact.
public static Map<String, String> calculateColorsForMarkedExact(SDocument result) {
Map<String, String> markedExactMap = new HashMap<>();
if (result != null) {
SDocumentGraph g = result.getDocumentGraph();
if (g != null) {
for (SNode n : result.getDocumentGraph().getNodes()) {
SFeature featMatched = n.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
Long matchNum = featMatched == null ? null : featMatched.getValue_SNUMERIC();
if (matchNum != null) {
int color = Math.max(0, Math.min((int) matchNum.longValue() - 1, MatchedNodeColors.values().length - 1));
RelannisNodeFeature feat = RelannisNodeFeature.extract(n);
if (feat != null) {
markedExactMap.put("" + feat.getInternalID(), MatchedNodeColors.values()[color].name());
}
}
}
}
// end if g not null
}
// end if result not null
return markedExactMap;
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class Helper method calulcateColorsForMarkedAndCovered.
public static void calulcateColorsForMarkedAndCovered(SDocument result, Map<String, Long> markedAndCovered, Map<String, String> markedCoveredMap) {
if (markedAndCovered != null) {
for (Map.Entry<String, Long> markedEntry : markedAndCovered.entrySet()) {
int color = Math.max(0, Math.min((int) markedEntry.getValue().longValue() - 1, MatchedNodeColors.values().length - 1));
SNode n = result.getDocumentGraph().getNode(markedEntry.getKey());
RelannisNodeFeature feat = RelannisNodeFeature.extract(n);
if (feat != null) {
markedCoveredMap.put("" + feat.getInternalID(), MatchedNodeColors.values()[color].name());
}
}
// end for each entry in markedAndCoverd
}
// end if markedAndCovered not null
}
use of annis.model.RelannisNodeFeature in project ANNIS by korpling.
the class SaltAnnotateExtractor method createSinglePrimaryText.
private void createSinglePrimaryText(SDocumentGraph graph, long textID, TreeMap<Long, String> tokenTexts, TreeMap<Long, SToken> tokenByIndex) {
STextualDS textDataSource = SaltFactory.createSTextualDS();
textDataSource.setName("sText" + textID);
graph.addNode(textDataSource);
StringBuilder sbText = new StringBuilder();
Iterator<Map.Entry<Long, String>> itToken = tokenTexts.entrySet().iterator();
long index = 0;
while (itToken.hasNext()) {
Map.Entry<Long, String> e = itToken.next();
SToken tok = tokenByIndex.get(e.getKey());
SFeature rawFeature = tok.getFeature(SaltUtil.createQName(ANNIS_NS, FEAT_RELANNIS_NODE));
if (rawFeature != null) {
RelannisNodeFeature feat = (RelannisNodeFeature) rawFeature.getValue();
if (feat.getTextRef() == textID) {
STextualRelation textRel = SaltFactory.createSTextualRelation();
textRel.setSource(tok);
textRel.setTarget(textDataSource);
textRel.setStart(sbText.length());
textRel.setEnd(sbText.length() + e.getValue().length());
textRel.setName("sTextRel" + textID + "_" + (index++));
textRel.setTarget(textDataSource);
graph.addRelation(textRel);
sbText.append(e.getValue());
if (itToken.hasNext()) {
sbText.append(" ");
}
}
}
}
textDataSource.setText(sbText.toString());
}
Aggregations