/**
  * Loads the available example queries for a specific corpus.
  *
  * @param corpusNames Specifies the corpora example queries are fetched for. If it is null or
  *     empty all available example queries are fetched.
  */
 private void loadExamplesFromRemote(String[] corpusNames) {
   WebResource service = Helper.getAnnisWebResource();
   try {
     if (corpusNames == null || corpusNames.length == 0) {
       examples =
           service
               .path("query")
               .path("corpora")
               .path("example-queries")
               .get(new GenericType<List<ExampleQuery>>() {});
     } else {
       String concatedCorpusNames = StringUtils.join(corpusNames, ",");
       examples =
           service
               .path("query")
               .path("corpora")
               .path("example-queries")
               .queryParam("corpora", concatedCorpusNames)
               .get(new GenericType<List<ExampleQuery>>() {});
     }
   } catch (UniformInterfaceException ex) {
     // ignore
   } catch (Exception ex) {
     log.error("problems with getting example queries from remote for {}", corpusNames, ex);
   }
 }
Example #2
0
 @Override
 public void buttonClick(ClickEvent event) {
   ShareQueryReferenceWindow w =
       new ShareQueryReferenceWindow(
           ui.getQueryController().getSearchQuery(), !Helper.isKickstarter(getSession()));
   getUI().addWindow(w);
   w.center();
 }
Example #3
0
  private static void addAnnotationsForNode(
      SNode node,
      SDocumentGraph graph,
      long startTokenIndex,
      long endTokenIndex,
      PDFController pdfController,
      PDFPageHelper pageNumberHelper,
      AtomicInteger eventCounter,
      LinkedHashMap<String, ArrayList<Row>> rowsByAnnotation,
      boolean addMatch,
      Set<String> mediaLayer,
      boolean replaceValueWithMediaIcon) {

    List<String> matchedAnnos = new ArrayList<>();
    SFeature featMatchedAnnos = graph.getFeature(ANNIS_NS, FEAT_MATCHEDANNOS);
    if (featMatchedAnnos != null) {
      matchedAnnos = Splitter.on(',').trimResults().splitToList(featMatchedAnnos.getValue_STEXT());
    }
    // check if the span is a matched node
    SFeature featMatched = node.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
    Long matchRaw = featMatched == null ? null : featMatched.getValue_SNUMERIC();

    String matchedQualifiedAnnoName = "";
    if (matchRaw != null && matchRaw <= matchedAnnos.size()) {
      matchedQualifiedAnnoName = matchedAnnos.get((int) ((long) matchRaw) - 1);
    }

    // calculate the left and right values of a span
    // TODO: howto get these numbers with Salt?
    RelannisNodeFeature feat =
        (RelannisNodeFeature) node.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();

    long leftLong = feat.getLeftToken();
    long rightLong = feat.getRightToken();

    leftLong = clip(leftLong, startTokenIndex, endTokenIndex);
    rightLong = clip(rightLong, startTokenIndex, endTokenIndex);

    int left = (int) (leftLong - startTokenIndex);
    int right = (int) (rightLong - startTokenIndex);

    for (SAnnotation anno : node.getAnnotations()) {
      ArrayList<Row> rows = rowsByAnnotation.get(anno.getQName());
      if (rows == null) {
        // try again with only the name
        rows = rowsByAnnotation.get(anno.getName());
      }
      if (rows != null) {
        // only do something if the annotation was defined before

        // 1. give each annotation of each span an own row
        Row r = new Row();

        String id = "event_" + eventCounter.incrementAndGet();
        GridEvent event = new GridEvent(id, left, right, anno.getValue_STEXT());
        event.setTooltip(Helper.getQualifiedName(anno));

        if (addMatch && matchRaw != null) {
          long match = matchRaw;

          if (matchedQualifiedAnnoName.isEmpty()) {
            // always set the match when there is no matched annotation at all
            event.setMatch(match);
          }
          // check if the annotation also matches
          else if (matchedQualifiedAnnoName.equals(anno.getQName())) {
            event.setMatch(match);
          }
        }
        if (node instanceof SSpan) {
          // calculate overlapped SToken

          List<? extends SRelation<? extends SNode, ? extends SNode>> outEdges =
              graph.getOutRelations(node.getId());
          if (outEdges != null) {
            for (SRelation<? extends SNode, ? extends SNode> e : outEdges) {
              if (e instanceof SSpanningRelation) {
                SSpanningRelation spanRel = (SSpanningRelation) e;

                SToken tok = spanRel.getTarget();
                event.getCoveredIDs().add(tok.getId());

                // get the STextualDS of this token and add it to the event
                String textID = getTextID(tok, graph);
                if (textID != null) {
                  event.setTextID(textID);
                }
              }
            }
          } // end if span has out edges
        } else if (node instanceof SToken) {
          event.getCoveredIDs().add(node.getId());
          // get the STextualDS of this token and add it to the event
          String textID = getTextID((SToken) node, graph);
          if (textID != null) {
            event.setTextID(textID);
          }
        }

        // try to get time annotations
        if (mediaLayer == null || mediaLayer.contains(anno.getQName())) {

          double[] startEndTime = TimeHelper.getOverlappedTime(node);
          if (startEndTime.length == 1) {
            if (replaceValueWithMediaIcon) {
              event.setValue(" ");
              event.setTooltip("play excerpt " + event.getStartTime());
            }
            event.setStartTime(startEndTime[0]);
          } else if (startEndTime.length == 2) {
            event.setStartTime(startEndTime[0]);
            event.setEndTime(startEndTime[1]);
            if (replaceValueWithMediaIcon) {
              event.setValue(" ");
              event.setTooltip("play excerpt " + event.getStartTime() + "-" + event.getEndTime());
            }
          }
        }

        r.addEvent(event);
        rows.add(r);

        if (pdfController != null && pdfController.sizeOfRegisterdPDFViewer() > 0) {
          String page = pageNumberHelper.getPageFromAnnotation(node);
          if (page != null) {
            event.setPage(page);
          }
        }
      }
    } // end for each annotation of span
  }
Example #4
0
  public ExceptionDialog(Throwable ex, String caption) {
    this.cause = ex;
    Preconditions.checkNotNull(ex);

    layout = new VerticalLayout();
    setContent(layout);
    layout.setWidth("100%");
    layout.setHeight("-1");

    if (caption == null) {
      setCaption("Unexpected error");
    } else {
      setCaption(caption);
    }

    Label lblInfo =
        new Label("An unexpected error occured.<br />The error message was:", ContentMode.HTML);
    lblInfo.setHeight("-1px");
    lblInfo.setWidth("100%");
    layout.addComponent(lblInfo);
    lblInfo.addStyleName("exception-message-caption");

    String message = ex.getMessage();
    if (message == null || message.isEmpty()) {
      message = "<no message>";
    }
    Label lblMessage = new Label(message);
    lblMessage.addStyleName("exception-message-content");
    lblMessage.setHeight("-1px");
    lblMessage.setWidth("100%");
    layout.addComponent(lblMessage);

    actionsLayout = new HorizontalLayout();
    actionsLayout.addStyleName("exception-dlg-details");
    actionsLayout.setWidth("100%");
    actionsLayout.setHeight("-1px");
    layout.addComponent(actionsLayout);

    btDetails = new Button("Show Details", this);
    btDetails.setStyleName(BaseTheme.BUTTON_LINK);
    actionsLayout.addComponent(btDetails);

    btReportBug = new Button("Report Problem", this);
    btReportBug.setStyleName(BaseTheme.BUTTON_LINK);
    btReportBug.setVisible(false);
    btReportBug.setIcon(FontAwesome.ENVELOPE_O);
    UI ui = UI.getCurrent();
    if (ui instanceof SearchUI) {
      btReportBug.setVisible(((SearchUI) ui).canReportBugs());
    }
    actionsLayout.addComponent(btReportBug);
    actionsLayout.setComponentAlignment(btDetails, Alignment.TOP_LEFT);
    actionsLayout.setComponentAlignment(btReportBug, Alignment.TOP_RIGHT);

    lblStacktrace = new Label(Helper.convertExceptionToMessage(ex), ContentMode.PREFORMATTED);
    detailsPanel = new Panel(lblStacktrace);
    detailsPanel.setWidth("100%");
    detailsPanel.setHeight("300px");
    detailsPanel.setVisible(false);
    lblStacktrace.setSizeUndefined();
    lblStacktrace.setVisible(true);
    layout.addComponent(detailsPanel);

    btClose = new Button("OK", this);
    layout.addComponent(btClose);

    layout.setComponentAlignment(btClose, Alignment.BOTTOM_CENTER);
    layout.setExpandRatio(detailsPanel, 0.0f);
    layout.setExpandRatio(actionsLayout, 1.0f);
  }