Ejemplo n.º 1
0
 private JCas createCorrectionCas(
     JCas mergeJCas,
     BratAnnotatorModel aBratAnnotatorModel,
     AnnotationDocument randomAnnotationDocument)
     throws UIMAException, ClassNotFoundException, IOException {
   User userLoggedIn =
       userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
   mergeJCas = repository.readAnnotationCas(aBratAnnotatorModel.getDocument(), userLoggedIn);
   repository.writeCorrectionCas(mergeJCas, randomAnnotationDocument.getDocument(), userLoggedIn);
   return mergeJCas;
 }
Ejemplo n.º 2
0
  public Map<String, JCas> listJcasesforCorrection(
      AnnotationDocument randomAnnotationDocument, SourceDocument aDocument, Mode aMode)
      throws UIMAException, ClassNotFoundException, IOException {
    Map<String, JCas> jCases = new HashMap<String, JCas>();
    User user =
        userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
    randomAnnotationDocument = repository.getAnnotationDocument(aDocument, user);

    // Upgrading should be an explicit action during the opening of a document at the end
    // of the open dialog - it must not happen during editing because the CAS addresses
    // are used as IDs in the UI
    // repository.upgradeCasAndSave(aDocument, aMode, user.getUsername());
    JCas jCas = repository.readAnnotationCas(randomAnnotationDocument);
    jCases.put(user.getUsername(), jCas);
    return jCases;
  }
Ejemplo n.º 3
0
  /**
   * For the first time a curation page is opened, create a MergeCas that contains only agreeing
   * annotations Using the CAS of the curator user.
   *
   * @param aProject the project
   * @param randomAnnotationDocument an annotation document.
   * @param jCases the JCases
   * @param aAnnotationLayers the layers.
   * @return the JCas.
   * @throws IOException if an I/O error occurs.
   */
  public JCas createCurationCas(
      Project aProject,
      AnnotationDocument randomAnnotationDocument,
      Map<String, JCas> jCases,
      List<AnnotationLayer> aAnnotationLayers)
      throws IOException {
    User userLoggedIn =
        userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());

    JCas mergeJCas = repository.readAnnotationCas(randomAnnotationDocument);
    jCases.put(CurationPanel.CURATION_USER, mergeJCas);

    List<Type> entryTypes = getEntryTypes(mergeJCas, aAnnotationLayers, annotationService);

    DiffResult diff =
        CasDiff2.doDiffSingle(
            annotationService,
            aProject,
            entryTypes,
            jCases,
            0,
            mergeJCas.getDocumentText().length());

    for (Entry<Position, ConfigurationSet> diffEntry :
        diff.getDifferingConfigurationSets().entrySet()) {
      // Remove FSes with differences from the merge CAS
      List<Configuration> cfgsForCurationUser =
          diffEntry.getValue().getConfigurations(CurationPanel.CURATION_USER);
      for (Configuration cfg : cfgsForCurationUser) {
        FeatureStructure fs = cfg.getFs(CurationPanel.CURATION_USER, jCases);
        mergeJCas.removeFsFromIndexes(fs);
      }
    }

    repository.writeCurationCas(mergeJCas, randomAnnotationDocument.getDocument(), userLoggedIn);
    return mergeJCas;
  }
Ejemplo n.º 4
0
  private void loadDocumentAction()
      throws UIMAException, ClassNotFoundException, IOException, BratAnnotationException {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    User logedInUser =
        userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());

    bModel.setUser(logedInUser);

    JCas jCas = null;
    try {
      AnnotationDocument logedInUserAnnotationDocument =
          repository.getAnnotationDocument(bModel.getDocument(), logedInUser);
      jCas = repository.readAnnotationCas(logedInUserAnnotationDocument);
    } catch (IOException e) {
      throw e;
    }
    // Get information to be populated to bratAnnotatorModel from the JCAS of the logged in user
    //
    catch (DataRetrievalFailureException e) {

      jCas = repository.readAnnotationCas(bModel.getDocument(), logedInUser);
      // This is the auto annotation, save it under CORRECTION_USER, Only if it is not created
      // by another annotater
      if (!repository.existsCorrectionCas(bModel.getDocument())) {
        repository.writeCorrectionCas(jCas, bModel.getDocument(), logedInUser);
      }
    } catch (NoResultException e) {
      jCas = repository.readAnnotationCas(bModel.getDocument(), logedInUser);
      // This is the auto annotation, save it under CORRECTION_USER, Only if it is not created
      // by another annotater
      if (!repository.existsCorrectionCas(bModel.getDocument())) {
        repository.writeCorrectionCas(jCas, bModel.getDocument(), logedInUser);
      }
    }

    // (Re)initialize brat model after potential creating / upgrading CAS
    bModel.initForDocument(jCas);

    // Load user preferences
    PreferencesUtil.setAnnotationPreference(
        username, repository, annotationService, bModel, Mode.AUTOMATION);

    // if project is changed, reset some project specific settings
    if (currentprojectId != bModel.getProject().getId()) {
      bModel.initForProject();
    }

    currentprojectId = bModel.getProject().getId();
    currentDocumentId = bModel.getDocument().getId();

    LOG.debug(
        "Configured BratAnnotatorModel for user ["
            + bModel.getUser()
            + "] f:["
            + bModel.getFirstSentenceAddress()
            + "] l:["
            + bModel.getLastSentenceAddress()
            + "] s:["
            + bModel.getSentenceAddress()
            + "]");
  }