public TwitterFollowPanel(String id, IModel<TwitterFollowModel> model) {
   super(id, model);
   ExternalLink twitterFollowLink = new ExternalLink("url", model.getObject().getUrl());
   twitterFollowLink.add(
       new AttributeModifier("data-show-count", model.getObject().getShowCount().toString()));
   add(twitterFollowLink);
   Label twitterNameLabel = new Label("twitterNameLabel", model.getObject().getUsername());
   twitterFollowLink.add(twitterNameLabel);
 }
  public GlossResultsSeparatedPanel(String id, IModel<List<SegmentedWord>> model) {
    super(id, model);

    Form<List<SegmentedWord>> form = new Form<>("form", model);
    add(form);

    Border textBorder =
        new HeaderPanel(
            "text",
            hid ->
                new HeaderButtonTitlePanel(
                    hid,
                    Model.of("Text"),
                    bid ->
                        new EditButton(bid, new ResourceModel("label.edit")).setSize(Size.Small)));
    form.add(textBorder);

    textBorder.add(
        new ListView<>(
            "text",
            model,
            item -> {
              ExternalLink link =
                  new ExternalLink(
                      "word",
                      Model.of("#def_link_" + item.getIndex()),
                      new LambdaModel<>(
                          item.getModel(), new OptionalFunction<>(SegmentedWord.FUNCTION_TEXT)));
              link.add(
                  new EnabledModelBehavior(
                      new SupplierModel<>(() -> item.getModelObject().hasDefinition())));
              link.setMarkupId("word_link_" + item.getIndex());
              item.add(link);
            }));

    Border defBorder = new HeaderPanel("defs", Model.of("Definitions"));
    form.add(defBorder);

    defBorder.add(
        new ListView<>(
            "defs",
            model,
            item ->
                item.add(
                        new WordPartsListPanel(
                            "def",
                            item.getModel(),
                            new SupplierModel<>(() -> "#word_link_" + item.getIndex())))
                    .setMarkupId("def_link_" + item.getIndex())
                    .add(
                        new VisibleModelBehavior(
                            new SupplierModel<>(() -> item.getModelObject().hasDefinition())))));
  }
示例#3
0
 public LinkPanel(
     String wicketId, String linkCssClass, String label, String href, boolean newWindow) {
   super(wicketId);
   this.labelModel = new Model<String>(label);
   ExternalLink link = new ExternalLink("link", href);
   if (newWindow) {
     link.add(new SimpleAttributeModifier("target", "_blank"));
   }
   if (linkCssClass != null) {
     link.add(new SimpleAttributeModifier("class", linkCssClass));
   }
   link.add(new Label("icon").setVisible(false));
   link.add(new Label("label", labelModel));
   add(link);
 }
  public AbstractHtmlNotificationPanel(String id, IModel<T> model) {
    super(id, model);

    WebMarkupContainer root = new TransparentWebMarkupContainer("root");
    root.add(new StyleAttributeAppender(STYLE_ROOT));
    add(root);

    WebMarkupContainer mainContainer = new TransparentWebMarkupContainer("mainContainer");
    mainContainer.add(new StyleAttributeAppender(STYLE_MAIN_CONTAINER));
    root.add(mainContainer);

    mainContainer.add(new CustomWebMarkupContainer("mainTitle", STYLE_MAIN_TITLE));

    WebMarkupContainer footer = new CustomWebMarkupContainer("footer", STYLE_FOOTER);
    mainContainer.add(footer);

    ExternalLink aboutLink =
        new ExternalLink("aboutLink", notificationUrlBuilderService.getAboutUrl());
    aboutLink.add(new StyleAttributeAppender(STYLE_LINK_FOOTER));
    footer.add(aboutLink);
  }
示例#5
0
    public CrowdProjectDetailForm(String id) {
      super(id, new CompoundPropertyModel<SelectionModel>(new SelectionModel()));

      add(new TextField<String>("name").setRequired(true));

      add(new TextField<String>("apiKey"));

      useSentenceTextField =
          new NumberTextField<Integer>(
              "useSents",
              new LoadableDetachableModel<Integer>() {

                private static final long serialVersionUID = 1L;

                @Override
                protected Integer load() {
                  return selectedCrowdJob == null ? -1 : selectedCrowdJob.getUseSents();
                }
              });
      useSentenceTextField.setType(Integer.class);
      add(useSentenceTextField);

      useGoldSentenceTextField =
          new NumberTextField<Integer>(
              "useGoldSents",
              new LoadableDetachableModel<Integer>() {

                private static final long serialVersionUID = 1L;

                @Override
                protected Integer load() {
                  return selectedCrowdJob == null ? -1 : selectedCrowdJob.getUseGoldSents();
                }
              });
      useGoldSentenceTextField.setType(Integer.class);
      add(useGoldSentenceTextField);

      ExternalLink link1;
      ExternalLink link2;

      IModel<String> link1_model =
          new LoadableDetachableModel<String>() {
            private static final long serialVersionUID = -2140663269255140643L;

            @Override
            protected String load() {
              if (selectedCrowdJob != null) {
                return selectedCrowdJob.getLink1();
              } else {
                return "";
              }
            }
          };

      IModel<String> link2_model =
          new LoadableDetachableModel<String>() {
            private static final long serialVersionUID = -2140663269255140643L;

            @Override
            protected String load() {
              if (selectedCrowdJob != null) {
                return selectedCrowdJob.getLink2();
              } else {
                return "";
              }
            }
          };

      add(link1 = new ExternalLink("link1", link1_model));
      add(link2 = new ExternalLink("link2", link2_model));

      link1.add(
          new Label(
              "label1",
              new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                  return selectedCrowdJob.getLink1();
                }
              }));

      link2.add(
          new Label(
              "label2",
              new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                  return selectedCrowdJob.getLink2();
                }
              }));

      add(
          new Label(
              "status",
              new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                  return selectedCrowdJob.getStatus();
                }
              }));

      add(
          new Label(
              "availSentences",
              new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                  return String.valueOf(getSourceDocumentsSentCount());
                }
              }));

      add(
          new Label(
              "availGoldSentences",
              new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                  return String.valueOf(getGoldDocumentsSentCount());
                }
              }));

      // TODO: more comments
      add(new ListMultipleChoice<SourceDocument>("documents") {
            private static final long serialVersionUID = 1L;

            {
              setChoices(
                  new LoadableDetachableModel<List<SourceDocument>>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected List<SourceDocument> load() {

                      if (selectedCrowdJob != null) {
                        documents = new ArrayList<SourceDocument>(selectedCrowdJob.getDocuments());
                        Collections.sort(
                            documents,
                            new Comparator<SourceDocument>() {
                              @Override
                              public int compare(SourceDocument doc1, SourceDocument doc2) {
                                return (doc1.getProject().getName() + doc1.getName())
                                    .compareTo(doc2.getProject().getName() + doc2.getName());
                              }
                            });
                      }
                      return documents;
                    }
                  });
              setChoiceRenderer(
                  new ChoiceRenderer<SourceDocument>() {
                    private static final long serialVersionUID = 4332411944787665963L;

                    @Override
                    public Object getDisplayValue(SourceDocument aObject) {
                      return aObject.getName();
                    }
                  });
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          })
          .setOutputMarkupId(true);

      add(new ListMultipleChoice<SourceDocument>("goldDocuments") {
            private static final long serialVersionUID = 1L;

            {
              setChoices(
                  new LoadableDetachableModel<List<SourceDocument>>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected List<SourceDocument> load() {

                      if (selectedCrowdJob != null) {
                        goldDocuments =
                            new ArrayList<SourceDocument>(selectedCrowdJob.getGoldDocuments());
                        Collections.sort(
                            goldDocuments,
                            new Comparator<SourceDocument>() {
                              @Override
                              public int compare(SourceDocument doc1, SourceDocument doc2) {
                                return (doc1.getProject().getName() + doc1.getName())
                                    .compareTo(doc2.getProject().getName() + doc2.getName());
                              }
                            });
                      }

                      return goldDocuments;
                    }
                  });
              setChoiceRenderer(
                  new ChoiceRenderer<SourceDocument>() {
                    private static final long serialVersionUID = 4332411944787665963L;

                    @Override
                    public Object getDisplayValue(SourceDocument aObject) {
                      return aObject.getName();
                    }
                  });
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          })
          .setOutputMarkupId(true);

      // save the crowd task
      add(
          new Button("save", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              String name = crowdJobDetailForm.getModelObject().name;
              // rename task
              if (selectedCrowdJob != null && !repository.existsCrowdJob(name)) {
                selectedCrowdJob.setName(name);
                selectedCrowdJob.setProject(selectedProject);
                selectedCrowdJob.setApiKey(crowdJobDetailForm.getModelObject().apiKey);
                try {
                  repository.createCrowdJob(selectedCrowdJob);
                } catch (IOException e) {
                  error("Problem Processing Log file");
                }
                createCrowdJob = false;
                updateTable();

              }
              // save new task
              else if (!repository.existsCrowdJob(name)) {
                CrowdJob crowdJob = new CrowdJob();
                crowdJob.setName(name);
                selectedCrowdJob.setProject(selectedProject);
                try {
                  repository.createCrowdJob(crowdJob);
                } catch (IOException e) {
                  error("Problem Processing Log file");
                }
                selectedCrowdJob = crowdJob;
                createCrowdJob = false;
                updateTable();
              } else {
                selectedCrowdJob.setApiKey(crowdJobDetailForm.getModelObject().apiKey);
                try {
                  repository.createCrowdJob(selectedCrowdJob);
                } catch (IOException e) {
                  error("Problem Processing Log file");
                }
                error("Task [" + name + " ] already created!");
              }
            }
          });

      // remove the crowd project
      add(
          new Button("remove", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              repository.removeCrowdJob(selectedCrowdJob);
              updateTable();
              crowdJobDetailForm.setVisible(false);
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });

      // add documents to the crowd source project
      add(
          new Button("addDocuments", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              crowdDocumentListForm.setVisible(true);
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });

      // add documents to the crowd source project
      add(
          new Button("addGoldDocuments", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              goldDocumentListForm.setVisible(true);
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });

      // remove document from the crowd job
      add(
          new Button("removeDocument", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              List<SourceDocument> sourceDocuments =
                  new ArrayList<SourceDocument>(selectedCrowdJob.getDocuments());
              sourceDocuments.removeAll(CrowdProjectDetailForm.this.getModelObject().documents);
              selectedCrowdJob.setDocuments(new HashSet<SourceDocument>(sourceDocuments));
              try {
                repository.createCrowdJob(selectedCrowdJob);
              } catch (IOException e) {
                error("Problem Processing Log file");
              }
              documents.removeAll(CrowdProjectDetailForm.this.getModelObject().documents);
              crowdDocumentListForm.setModelObject(new SelectionModel());
              updateTable();
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });

      // remove gold documents from the crowd job
      add(
          new Button("removeGoldDocument", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              List<SourceDocument> goldSourceDocuments =
                  new ArrayList<SourceDocument>(selectedCrowdJob.getGoldDocuments());
              goldSourceDocuments.removeAll(
                  CrowdProjectDetailForm.this.getModelObject().goldDocuments);
              selectedCrowdJob.setGoldDocuments(new HashSet<SourceDocument>(goldSourceDocuments));
              try {
                repository.createCrowdJob(selectedCrowdJob);
              } catch (IOException e) {
                error("Problem Processing Log file");
              }
              goldDocuments.removeAll(CrowdProjectDetailForm.this.getModelObject().goldDocuments);
              goldDocumentListForm.setModelObject(new SelectionModel());
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });

      // send document to crowd flower and get back status and link
      add(
          new Button("uploadT1", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {

              if (namedEntityTaskManager == null) {
                namedEntityTaskManager = new NamedEntityTaskManager();
              }

              namedEntityTaskManager.setAPIKey(selectedCrowdJob.getApiKey());
              User user = userRepository.get(CROWD_USER);

              List<JCas> jCases = getSourceDocumentsJCases(user);
              // Get the JCASes for each gold document
              List<JCas> goldJCases = getGoldDocumentsJCases(user);
              /*     int useSent = useSentenceTextField.getModelObject() ==0?-1:useSentenceTextField.getModelObject();
              int useGoldSent = useGoldSentenceTextField.getModelObject() ==0?*/

              try {
                String template =
                    FileUtils.readFileToString(repository.getTemplate(CROWD_NERTASK1_TEMPLATE));
                selectedCrowdJob.setUseSents(useSentenceTextField.getModelObject());
                selectedCrowdJob.setUseGoldSents(useGoldSentenceTextField.getModelObject());

                String task1ID =
                    namedEntityTaskManager.uploadNewNERTask1(
                        template,
                        jCases,
                        goldJCases,
                        useSentenceTextField.getModelObject() == 0
                            ? -1
                            : useSentenceTextField.getModelObject(),
                        useGoldSentenceTextField.getModelObject());
                selectedCrowdJob.setTask1Id(task1ID);
                selectedCrowdJob.setStatus(namedEntityTaskManager.getStatusString(task1ID, ""));

                repository.createCrowdJob(selectedCrowdJob);

                int omittedSentences = namedEntityTaskManager.getOmittedSentences();
                if (omittedSentences == 0) {
                  info("Crowdflower task " + task1ID + " uploaded succesfully.");
                } else {
                  warn(
                      "Crowdflower task "
                          + task1ID
                          + " uploaded succesfully, but "
                          + omittedSentences
                          + " sentences were omitted due to processing errors (see log).");
                }
              } catch (FileNotFoundException e) {
                error("Could not find the template file for NER task 1: " + e.getMessage());
              } catch (JsonProcessingException e) {
                error("Template for NER task 1 is mal formated: " + e.getMessage());
              } catch (IOException e) {
                error(
                    "There was a problem reading the NER task 1 template file: " + e.getMessage());
              } catch (Exception e) {
                error(
                    "Something went wrong uploading your document(s) to crowdflower.com: "
                        + e.getMessage());
              }
            }
          });

      // send document to crowd flower and get back status and link
      add(
          new Button("uploadT2", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              if (namedEntityTaskManager == null) {
                namedEntityTaskManager = new NamedEntityTaskManager();
              }

              namedEntityTaskManager.setAPIKey(selectedCrowdJob.getApiKey());
              User user = userRepository.get(CROWD_USER);

              List<JCas> jCases = getSourceDocumentsJCases(user);

              // Get the JCASes for each gold document
              List<JCas> goldJCases = getGoldDocumentsJCases(user);
              try {

                String task1ID = selectedCrowdJob.getTask1Id();

                if (task1ID == null) {
                  error("Task1 not yet completed");
                  return;
                }

                String template =
                    FileUtils.readFileToString(repository.getTemplate(CROWD_NERTASK2_TEMPLATE));
                String task2ID =
                    namedEntityTaskManager.uploadNewNERTask2(template, task1ID, jCases, goldJCases);
                selectedCrowdJob.setTask2Id(task2ID);
                repository.createCrowdJob(selectedCrowdJob);

                int omittedSentences = namedEntityTaskManager.getOmittedSentences();
                if (omittedSentences == 0) {
                  info("Crowdflower task " + task2ID + " uploaded succesfully.");
                } else {
                  warn(
                      "Crowdflower task "
                          + task2ID
                          + " uploaded succesfully, but "
                          + omittedSentences
                          + " sentences were omitted due to processing errors (see log).");
                }

              } catch (FileNotFoundException e) {
                error("Could not find the template file for NER task 1: " + e.getMessage());
              } catch (JsonProcessingException e) {
                error("Template for NER task 1 is mal formated: " + e.getMessage());
              } catch (IOException e) {
                error(
                    "There was a problem reading the NER task 1 template file: " + e.getMessage());
              } catch (Exception e) {
                error(
                    "Something went wrong uploading your document(s) to crowdflower.com: "
                        + e.getMessage());
              }
            }

            @Override
            public boolean isVisible() {
              return true;
            }
          });

      add(
          new Button("retrieveT2", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              try {
                if (namedEntityTaskManager == null) {
                  namedEntityTaskManager = new NamedEntityTaskManager();
                }

                namedEntityTaskManager.setAPIKey(selectedCrowdJob.getApiKey());
                User user = userRepository.get(CROWD_USER);

                List<SourceDocument> sourceDocuments =
                    new ArrayList<SourceDocument>(selectedCrowdJob.getDocuments());
                List<JCas> jCases = getSourceDocumentsJCases(user);

                String task2ID = selectedCrowdJob.getTask2Id();

                if (task2ID == null) {
                  error("Task2 not yet completed");
                  return;
                }

                // clear previous annotation / imports for the crowd user
                int i = 0;
                for (JCas cas : jCases) {
                  BratAnnotatorUtility.clearJcasAnnotations(
                      cas, sourceDocuments.get(i), user, repository);
                  i++;
                }

                // import job results from crowdflwoer
                namedEntityTaskManager.setCrowdJobAnnotationsInDocs(task2ID, jCases);

                // save all changed document annotations on disk
                i = 0;
                for (JCas cas : jCases) {
                  SourceDocument document = sourceDocuments.get(i);
                  repository.writeAnnotationCas(cas, document, user);
                  i++;
                }
                int omittedEntities = namedEntityTaskManager.getOmittedEntities();

                if (omittedEntities == 0) {
                  info("Crowdflower job annotations imported succesfully for this task.");
                } else {
                  warn(
                      "Warning: Crowdflower job annotations imported succesfully for this task, but "
                          + omittedEntities
                          + " annotations were omitted due to processing errors (see log).");
                }
              } catch (JsonProcessingException e) {
                error("Json processing problem: " + e.getMessage());
              } catch (IOException e) {
                error("Input/Output exception: " + e.getMessage());
              } catch (Exception e) {
                error(
                    "Something went wrong importing your document(s) from crowdflower.com: "
                        + e.getMessage());
              }
            }

            @Override
            public boolean isVisible() {
              return true;
            }
          });

      // update the status of this source document from crowd
      add(
          new Button("update", new ResourceModel("label")) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
              if (namedEntityTaskManager == null) {
                namedEntityTaskManager = new NamedEntityTaskManager();
              }
              namedEntityTaskManager.setAPIKey(selectedCrowdJob.getApiKey());

              String id1 = selectedCrowdJob.getTask1Id();
              if (id1 == null) {
                id1 = "";
              }
              String id2 = selectedCrowdJob.getTask2Id();
              if (id2 == null) {
                id2 = "";
              }

              String status = namedEntityTaskManager.getStatusString(id1, id2);
              selectedCrowdJob.setStatus(status);
              try {
                repository.createCrowdJob(selectedCrowdJob);
              } catch (IOException e) {
                error("Problem Processing Log file");
              }
            }

            @Override
            public boolean isVisible() {
              return !createCrowdJob;
            }
          });
    }