Exemplo n.º 1
0
 private String extractAnnotation(
     Set<Annotation> annotations, String namespace, String featureName) {
   for (Annotation a : annotations) {
     if (a.getNamespace().equals(namespace) && a.getName().equals(featureName)) {
       return a.getValue();
     }
   }
   return "--";
 }
Exemplo n.º 2
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");
    }
  }