Пример #1
0
  private void setCurationSegmentBeginEnd()
      throws UIMAException, ClassNotFoundException, IOException {
    JCas jCas = repository.readAnnotationCas(bModel.getDocument(), bModel.getUser());

    final int sentenceAddress =
        getAddr(
            selectSentenceAt(jCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset()));

    final Sentence sentence = selectByAddr(jCas, Sentence.class, sentenceAddress);
    List<Sentence> followingSentences =
        selectFollowing(jCas, Sentence.class, sentence, bModel.getPreferences().getWindowSize());
    // Check also, when getting the last sentence address in the display window, if this is the
    // last sentence or the ONLY sentence in the document
    Sentence lastSentenceAddressInDisplayWindow =
        followingSentences.size() == 0
            ? sentence
            : followingSentences.get(followingSentences.size() - 1);
    curationSegment.setBegin(sentence.getBegin());
    curationSegment.setEnd(lastSentenceAddressInDisplayWindow.getEnd());
  }
Пример #2
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()
            + "]");
  }