예제 #1
0
  @Override
  public void convertText(
      AnnisResultSet queryResult,
      List<String> keys,
      Map<String, String> args,
      Writer out,
      int offset)
      throws IOException {

    Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();

    List<String> metaKeys = new LinkedList<>();
    if (args.containsKey("metakeys")) {
      Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
      for (String s : it) {
        metaKeys.add(s);
      }
    }

    int counter = 0;
    for (AnnisResult annisResult : queryResult) {
      Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds();

      counter++;
      out.append((counter + offset) + ". ");
      List<AnnisNode> tok = annisResult.getGraph().getTokens();

      for (AnnisNode annisNode : tok) {
        Long tokID = annisNode.getId();
        if (matchedNodeIds.contains(tokID)) {
          out.append("[");
          out.append(annisNode.getSpannedText());
          out.append("]");
        } else {
          out.append(annisNode.getSpannedText());
        }

        for (Annotation annotation : annisNode.getNodeAnnotations()) {
          out.append("/" + annotation.getValue());
        }

        out.append(" ");
      }
      out.append("\n");

      if (!metaKeys.isEmpty()) {
        String[] path = annisResult.getPath();
        super.appendMetaData(
            out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
      }
      out.append("\n");
    }
  }
예제 #2
0
  @Override
  public void writeOutput(VisualizerInput input, OutputStream outstream) {
    this.input = input;
    AnnisResult result = input.getResult();
    List<AbstractImageGraphicsItem> layouts = new LinkedList<AbstractImageGraphicsItem>();

    double width = 0;
    double maxheight = 0;

    for (DirectedGraph<AnnisNode, Edge> g : graphtools.getSyntaxGraphs(input)) {
      if (g.getEdgeCount() > 0 && g.getVertexCount() > 0) {

        ConstituentLayouter<AbstractImageGraphicsItem> cl =
            new ConstituentLayouter<AbstractImageGraphicsItem>(g, backend, labeler, styler, input);

        AbstractImageGraphicsItem item =
            cl.createLayout(
                new LayoutOptions(
                    VerticalOrientation.TOP_ROOT,
                    AnnisGraphTools.detectLayoutDirection(result.getGraph())));

        Rectangle2D treeSize = item.getBounds();

        maxheight = Math.max(maxheight, treeSize.getHeight());
        width += treeSize.getWidth();
        layouts.add(item);
      }
    }

    BufferedImage image =
        new BufferedImage(
            (int) (width + (layouts.size() - 1) * TREE_DISTANCE + 2 * SIDE_MARGIN),
            (int) (maxheight + 2 * TOP_MARGIN),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D canvas = createCanvas(image);
    double xOffset = SIDE_MARGIN;
    for (AbstractImageGraphicsItem item : layouts) {
      AffineTransform t = canvas.getTransform();
      Rectangle2D bounds = item.getBounds();
      canvas.translate(xOffset, TOP_MARGIN + maxheight - bounds.getHeight());
      renderTree(item, canvas);
      xOffset += bounds.getWidth() + TREE_DISTANCE;
      canvas.setTransform(t);
    }
    try {
      ImageIO.write(image, "png", outstream);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }