Search in sources :

Example 1 with MatchedNodeColors

use of annis.libgui.MatchedNodeColors in project ANNIS by korpling.

the class ProielRegularDependencyTree method writeNode.

private void writeNode(AnnisNode n) {
    String color = "#000000";
    String shape = "point";
    String colorAsString = input.getMarkableExactMap().get(Long.toString(n.getId()));
    if (colorAsString != null) {
        MatchedNodeColors matchedColor = MatchedNodeColors.valueOf(colorAsString);
        color = matchedColor.getHTMLColor();
        shape = "circle";
    }
    w("  " + n.getId() + "[shape=\"" + shape + "\", label=\"\" ");
    // background color
    w("style=filled, ");
    w("fillcolor=\"");
    w(color);
    w("\" color=\"");
    w(color);
    w("\" ];\n");
}
Also used : MatchedNodeColors(annis.libgui.MatchedNodeColors)

Example 2 with MatchedNodeColors

use of annis.libgui.MatchedNodeColors in project ANNIS by korpling.

the class DotGraphVisualizer method writeNode.

private void writeNode(AnnisNode node) {
    w("\t");
    w(node.getId());
    // attributes
    w(" [ ");
    // output label
    w("label=\"");
    appendLabel(node);
    appendNodeAnnotations(node);
    w("\", ");
    // background color
    w("style=filled, ");
    w("fillcolor=\"");
    String colorAsString = input.getMarkableExactMap().get(Long.toString(node.getId()));
    if (colorAsString != null) {
        MatchedNodeColors color = MatchedNodeColors.valueOf(colorAsString);
        w(color.getHTMLColor());
    } else {
        w("#ffffff");
    }
    w("\" ");
    // "footer"
    w("];\n");
}
Also used : MatchedNodeColors(annis.libgui.MatchedNodeColors)

Example 3 with MatchedNodeColors

use of annis.libgui.MatchedNodeColors in project ANNIS by korpling.

the class ProielDependecyTree method writeNode.

private void writeNode(AnnisNode n, String word) {
    String shape = "box";
    String id = "" + n.getId();
    String fillcolor = "#ffffff";
    String fontcolor = "black";
    String style = "filled";
    String label = "";
    // get pos annotation
    String posAnno = "";
    for (Annotation anno : n.getNodeAnnotations()) {
        if ("tiger".equals(anno.getNamespace()) && "pos".equals(anno.getName()) && anno.getValue() != null) {
            posAnno = anno.getValue();
        }
    }
    if (isEmptyNode(word)) {
        if (isRootNode(n)) {
            shape = "circle";
        } else {
            if (posAnno.length() > 0) {
                // decide which pos to use
                switch(posAnno.charAt(0)) {
                    case 'V':
                        shape = "circle";
                        label = posAnno;
                        break;
                    case 'C':
                        shape = "diamond";
                        label = posAnno;
                        break;
                    case 'P':
                        shape = "hexagon";
                        label = posAnno;
                        break;
                    default:
                        shape = "circle";
                        label = posAnno;
                        break;
                }
            }
        }
    } else {
        // is coordinator?
        if ("C-".equals(posAnno)) {
            shape = "diamond";
        }
        label = word;
    }
    // check coloring
    String matchColorAsString = input.getMarkableExactMap().get(Long.toString(n.getId()));
    if (matchColorAsString == null) {
        // check if there mighte be a matching token that is directly belonging to
        // this "fake" token node
        AnnisNode token = getCorrespondingRealToken(n);
        if (token != null) {
            matchColorAsString = input.getMarkableExactMap().get(Long.toString(token.getId()));
        }
    }
    if (matchColorAsString != null) {
        MatchedNodeColors matchColor = MatchedNodeColors.valueOf(matchColorAsString);
        fillcolor = matchColor.getHTMLColor();
    }
    // write out the node
    w(id);
    w(" [");
    wAtt("fontcolor", fontcolor);
    wAtt("shape", shape);
    wAtt("fillcolor", fillcolor);
    wAtt("style", style);
    wAtt("label", label);
    w("];\n");
}
Also used : AnnisNode(annis.model.AnnisNode) MatchedNodeColors(annis.libgui.MatchedNodeColors) Annotation(annis.model.Annotation)

Example 4 with MatchedNodeColors

use of annis.libgui.MatchedNodeColors in project ANNIS by korpling.

the class ProielRegularDependencyTree method writeToken.

private void writeToken(AnnisNode n) {
    w("  " + n.getId() + "[label=\"" + n.getSpannedText() + "\" ");
    // background color
    w("style=filled, ");
    w("fillcolor=\"");
    String colorAsString = input.getMarkableExactMap().get(Long.toString(n.getId()));
    if (colorAsString != null) {
        MatchedNodeColors color = MatchedNodeColors.valueOf(colorAsString);
        w(color.getHTMLColor());
    } else {
        w("#ffffff");
    }
    w("\" ];\n");
}
Also used : MatchedNodeColors(annis.libgui.MatchedNodeColors)

Example 5 with MatchedNodeColors

use of annis.libgui.MatchedNodeColors in project ANNIS by korpling.

the class CorefVisualizer method outputSingleText.

private List<Node> outputSingleText(List<SToken> token, VisualizerInput input) throws IOException {
    List<Node> result = new LinkedList<Node>();
    List<Long> prevpositions, listpositions;
    List<Long> finalpositions = null;
    int maxlinkcount = 0;
    String lastId, currentId = null;
    for (SToken tok : token) {
        prevpositions = finalpositions;
        if (prevpositions != null && prevpositions.size() < 1) {
            prevpositions = null;
        }
        lastId = currentId;
        currentId = tok.getId();
        listpositions = componentOfToken.get(currentId);
        List<Boolean> checklist = null;
        if (prevpositions == null && listpositions != null) {
            finalpositions = listpositions;
        } else if (listpositions == null) {
            finalpositions = new LinkedList<Long>();
        } else {
            checklist = new LinkedList<Boolean>();
            for (int i = 0; prevpositions != null && i < prevpositions.size(); i++) {
                if (listpositions.contains(prevpositions.get(i))) {
                    checklist.add(true);
                } else {
                    checklist.add(false);
                }
            }
            List<Long> remains = new LinkedList<Long>();
            for (int i = 0; i < listpositions.size(); i++) {
                if (prevpositions != null && !prevpositions.contains(listpositions.get(i))) {
                    remains.add(listpositions.get(i));
                }
            }
            int minsize = checklist.size() + remains.size();
            int number = 0;
            finalpositions = new LinkedList<Long>();
            for (int i = 0; i < minsize; i++) {
                if (prevpositions != null && checklist.size() > i && checklist.get(i).booleanValue()) {
                    finalpositions.add(prevpositions.get(i));
                } else {
                    if (remains.size() > number) {
                        Long ll = remains.get(number);
                        finalpositions.add(ll);
                        number++;
                        minsize--;
                    } else {
                        finalpositions.add(Long.MIN_VALUE);
                    }
                }
            }
        }
        String onclick = "";
        String style = "";
        if (input.getMarkedAndCovered().containsKey(tok)) {
            MatchedNodeColors[] vals = MatchedNodeColors.values();
            long match = Math.min(input.getMarkedAndCovered().get(tok) - 1, vals.length - 1);
            style += ("color: " + vals[(int) match].getHTMLColor() + ";");
        }
        boolean underline = false;
        if (!finalpositions.isEmpty()) {
            style += "cursor:pointer;";
            underline = true;
            onclick = "togglePRAuto(this);";
        }
        Table tableSingleTok = new Table();
        result.add(tableSingleTok);
        tableSingleTok.setCSSClass("token");
        int currentlinkcount = 0;
        if (underline) {
            boolean firstone = true;
            int index = -1;
            String tooltip;
            if (!finalpositions.isEmpty()) {
                for (Long currentPositionComponent : finalpositions) {
                    index++;
                    String left = "", right = "";
                    // == pir
                    TComponent currentWriteComponent = null;
                    String currentType = "";
                    if (!currentPositionComponent.equals(Long.MIN_VALUE) && komponent.size() > currentPositionComponent) {
                        currentWriteComponent = komponent.get((int) (long) currentPositionComponent);
                        List<String> pi = currentWriteComponent.tokenList;
                        List<String> preparedPi = new LinkedList<String>();
                        for (String s : pi) {
                            preparedPi.add(prepareID(s));
                        }
                        currentType = currentWriteComponent.type;
                        left = StringUtils.join(preparedPi, ",");
                        right = "" + currentPositionComponent + 1;
                    }
                    String annotations = getAnnotations(tok.getId(), currentPositionComponent);
                    if (firstone) {
                        firstone = false;
                        if (currentWriteComponent == null) {
                            String left2 = "", right2 = "";
                            long pr = 0;
                            // == pir
                            TComponent currentWriteComponent2;
                            String currentType2 = "";
                            String annotations2 = "";
                            for (Long currentPositionComponent2 : finalpositions) {
                                if (!currentPositionComponent2.equals(Long.MIN_VALUE) && komponent.size() > currentPositionComponent2) {
                                    currentWriteComponent2 = komponent.get((int) (long) currentPositionComponent2);
                                    List<String> pi2 = currentWriteComponent2.tokenList;
                                    // prepare each single ID
                                    List<String> preparedPi2 = new LinkedList<String>();
                                    for (String s : pi2) {
                                        preparedPi2.add(prepareID(s));
                                    }
                                    currentType2 = currentWriteComponent2.type;
                                    left2 = StringUtils.join(preparedPi2, ",");
                                    right2 = "" + currentPositionComponent2 + 1;
                                    annotations2 = getAnnotations(tok.getId(), currentPositionComponent2);
                                    pr = currentPositionComponent2;
                                    break;
                                }
                            }
                            tooltip = "&lt;b&gt;Component&lt;/b&gt;: " + (pr + 1) + ", &lt;b&gt;Type&lt;/b&gt;: " + currentType2 + annotations2;
                            Tr trTok = new Tr();
                            tableSingleTok.appendChild(trTok);
                            Td tdTok = new Td();
                            trTok.appendChild(tdTok);
                            tdTok.setId("tok_" + prepareID(tok.getId()));
                            tdTok.setTitle(tooltip);
                            tdTok.setStyle(style);
                            tdTok.setAttribute("onclick", onclick);
                            tdTok.setAttribute("annis:pr_left", left2);
                            tdTok.setAttribute("annis:pr_right", right2);
                            Text textTok = new Text("&nbsp;" + CommonHelper.getSpannedText(tok) + "&nbsp;");
                            tdTok.appendChild(textTok);
                        } else {
                            // easier
                            tooltip = "&lt;b&gt;Component&lt;/b&gt;: " + (currentPositionComponent + 1) + ", &lt;b&gt;Type&lt;/b&gt; " + currentType + annotations;
                            Tr trTok = new Tr();
                            tableSingleTok.appendChild(trTok);
                            Td tdTok = new Td();
                            trTok.appendChild(tdTok);
                            tdTok.setId("tok_" + prepareID(tok.getId()));
                            tdTok.setTitle(tooltip);
                            tdTok.setStyle(style);
                            tdTok.setAttribute("onclick", onclick);
                            tdTok.setAttribute("annis:pr_left", left);
                            tdTok.setAttribute("annis:pr_right", right);
                            Text textTok = new Text("&nbsp;" + CommonHelper.getSpannedText(tok) + "&nbsp;");
                            tdTok.appendChild(textTok);
                        }
                    }
                    currentlinkcount++;
                    // while we've got underlines
                    if (currentPositionComponent.equals(Long.MIN_VALUE)) {
                        Tr trBlank = new Tr();
                        tableSingleTok.appendChild(trBlank);
                        Td tdBlank = new Td();
                        trBlank.appendChild(tdBlank);
                        trBlank.setCSSClass("line");
                    } else {
                        int color;
                        if (colorlist.containsKey((int) (long) currentPositionComponent)) {
                            color = colorlist.get((int) (long) currentPositionComponent);
                        } else {
                            color = getNewColor((int) (long) currentPositionComponent);
                            colorlist.put((int) (long) currentPositionComponent, color);
                        }
                        if (color > 16777215) {
                            color = 16777215;
                        }
                        String addition = ";border-style: solid; border-width: 0px 0px 0px 2px; border-color: white ";
                        if (lastId != null && currentId != null && checklist != null && checklist.size() > index && checklist.get(index).booleanValue() == true) {
                            if (connectionOf(lastId, currentId, currentPositionComponent)) {
                                addition = "";
                            }
                        }
                        tooltip = "&lt;b&gt;Component&lt;/b&gt;: " + (currentPositionComponent + 1) + ", &lt;b&gt;Type&lt;/b&gt;: " + currentType + annotations;
                        Tr trLineContainer = new Tr();
                        tableSingleTok.appendChild(trLineContainer);
                        Td tdLineContainer = new Td();
                        trLineContainer.appendChild(tdLineContainer);
                        Table tableLineContainer = new Table();
                        tdLineContainer.appendChild(tableLineContainer);
                        trLineContainer.setCSSClass("line");
                        tableLineContainer.setCSSClass("linecontainer");
                        Tr trLine = new Tr();
                        tableLineContainer.appendChild(trLine);
                        Td tdLine = new Td();
                        trLine.appendChild(tdLine);
                        tdLine.setCSSClass("clickableline");
                        tdLine.setStyle("background-color: #" + Integer.toHexString(color) + "; " + style + addition);
                        tdLine.setAttribute("onclick", onclick);
                        tdLine.setAttribute("annis:pr_left", left);
                        tdLine.setAttribute("annis:pr_right", right);
                        tdLine.setTitle(tooltip);
                        Tr trSpace = new Tr();
                        tableLineContainer.appendChild(trSpace);
                        Td tdSpace = new Td();
                        trSpace.appendChild(tdSpace);
                        tdSpace.setCSSClass("space");
                    }
                }
            }
            if (currentlinkcount > maxlinkcount) {
                maxlinkcount = currentlinkcount;
            } else {
                if (currentlinkcount < maxlinkcount) {
                    addEmptyLines(tableSingleTok, maxlinkcount - currentlinkcount);
                }
            }
        } else {
            // print a token without lines
            Tr trTok = new Tr();
            tableSingleTok.appendChild(trTok);
            Td tdTok = new Td();
            trTok.appendChild(tdTok);
            tdTok.setId("tok_" + prepareID(tok.getId()));
            tdTok.setStyle(style);
            Text textTok = new Text("&nbsp;" + CommonHelper.getSpannedText(tok) + "&nbsp;");
            tdTok.appendChild(textTok);
            if (maxlinkcount > 0) {
                addEmptyLines(tableSingleTok, maxlinkcount);
            }
        }
    }
    return result;
}
Also used : Table(com.hp.gagawa.java.elements.Table) SNode(org.corpus_tools.salt.core.SNode) SStructuredNode(org.corpus_tools.salt.common.SStructuredNode) Node(com.hp.gagawa.java.Node) Text(com.hp.gagawa.java.elements.Text) LinkedList(java.util.LinkedList) SToken(org.corpus_tools.salt.common.SToken) Td(com.hp.gagawa.java.elements.Td) MatchedNodeColors(annis.libgui.MatchedNodeColors) LinkedList(java.util.LinkedList) List(java.util.List) Tr(com.hp.gagawa.java.elements.Tr)

Aggregations

MatchedNodeColors (annis.libgui.MatchedNodeColors)5 AnnisNode (annis.model.AnnisNode)1 Annotation (annis.model.Annotation)1 Node (com.hp.gagawa.java.Node)1 Table (com.hp.gagawa.java.elements.Table)1 Td (com.hp.gagawa.java.elements.Td)1 Text (com.hp.gagawa.java.elements.Text)1 Tr (com.hp.gagawa.java.elements.Tr)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 SStructuredNode (org.corpus_tools.salt.common.SStructuredNode)1 SToken (org.corpus_tools.salt.common.SToken)1 SNode (org.corpus_tools.salt.core.SNode)1