private void updateCurationView(final CurationContainer curationContainer, final SourceListView curationViewItem, AjaxRequestTarget aTarget, JCas jCas) { Sentence currentSent = WebAnnoCasUtil.getCurrentSentence(jCas, curationViewItem.getBegin(), curationViewItem.getEnd()); state.setFirstVisibleUnit(WebAnnoCasUtil.findWindowStartCenteringOnSelection(jCas, currentSent, curationViewItem.getBegin(), state.getProject(), state.getDocument(), state.getPreferences().getWindowSize())); curationContainer.setBratAnnotatorModel(state); onChange(aTarget); }
private void createNewRelationAnnotation(RelationAdapter aAdapter, JCas aJCas) throws AnnotationException { LOG.trace("createNewRelationAnnotation()"); AnnotatorState state = getModelObject(); Selection selection = state.getSelection(); AnnotationFS originFs = selectByAddr(aJCas, selection.getOrigin()); AnnotationFS targetFs = selectByAddr(aJCas, selection.getTarget()); // Creating a relation AnnotationFS arc = aAdapter.add(state.getDocument(), state.getUser().getUsername(), originFs, targetFs, aJCas, state.getWindowBeginOffset(), state.getWindowEndOffset()); selection.selectArc(new VID(arc), originFs, targetFs); }
state.getAnnotationLayers(), annotationService); if (state.getMode().equals(Mode.CURATION)) { diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd()); diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getBegin(), aCurationSegment.getEnd()); addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, d, false, false); addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, i, true, false); all.removeAll(i); addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, all, false, true); return annoStates;
public static void savePreference(UserPreferencesService aPrefService, AnnotatorState aState, String aUsername) throws IOException { aPrefService.savePreferences(aState.getProject(), aUsername, aState.getMode(), aState.getPreferences()); } }
void updateRememberLayer() { AnnotatorState state = getModelObject(); if (state.getPreferences().isRememberLayer()) { if (state.getDefaultAnnotationLayer() == null) { state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer()); } } else if (!state.getSelection().isArc()) { state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer()); } // if no layer is selected in Settings if (state.getSelectedAnnotationLayer() != null) { selectedAnnotationLayer.setDefaultModelObject( state.getSelectedAnnotationLayer().getUiName()); } }
@Override protected List<SourceDocument> getListOfDocs() { AnnotatorState state = getModelObject(); return new ArrayList<>(documentService .listAnnotatableDocuments(state.getProject(), state.getUser()).keySet()); }
state.setUser(user); if (!SourceDocumentState.CURATION_FINISHED.equals(state.getDocument().getState())) { documentService.transitionSourceDocumentState(state.getDocument(), ANNOTATION_IN_PROGRESS_TO_CURATION_IN_PROGRESS); .listAnnotationDocuments(state.getDocument())) { if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) { finishedAnnotationDocuments.add(annotationDocument); randomAnnotationDocument, state.getMode()); JCas mergeJCas = cb.getMergeCas(state, state.getDocument(), jCases, randomAnnotationDocument, true); state.reset(); state.getPreferences() .setCurationWindowSize(WebAnnoCasUtil.getSentenceCount(mergeJCas)); .getCurationCasTimestamp(state.getDocument())); state.moveToUnit(mergeJCas, aFocus); gotoPageTextField.setModelObject(getModelObject().getFirstVisibleUnitIndex()); if (currentprojectId != state.getProject().getId()) { state.clearRememberedFeatures(); currentprojectId = state.getProject().getId(); curationPanel.getEditor().reset(aTarget);
state.setUser(userRepository.getCurrentUser()); state.setDocument(state.getDocument(), getListOfDocs()); .createOrGetAnnotationDocument(state.getDocument(), state.getUser()); if (correctionDocumentService.existsCorrectionCas(state.getDocument())) { correctionCas = correctionDocumentService.readCorrectionCas(state.getDocument()); correctionCas = documentService.createOrReadInitialCas(state.getDocument()); if (documentService.existsCas(state.getDocument(), state.getUser().getUsername())) { editorCas = documentService.readAnnotationCas(annotationDocument); editorCas = documentService.createOrReadInitialCas(state.getDocument()); state.getDocument()); annotationDocument.getDocument(), state.getUser(), false); correctionDocumentService.writeCorrectionCas(correctionCas, state.getDocument()); state.reset(); .getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername())); state.setConstraints(constraintsService.loadConstraints(state.getProject())); state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(editorCas)); if (currentprojectId != state.getProject().getId()) {
state.setUser(userRepository.getCurrentUser()); .createOrGetAnnotationDocument(state.getDocument(), state.getUser()); state.reset(); .getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername())); state.setConstraints(constraintsService.loadConstraints(state.getProject())); if (currentprojectId != state.getProject().getId()) { state.clearRememberedFeatures(); currentprojectId = state.getProject().getId(); state.moveToUnit(editorCas, aFocus); gotoPageTextField.setModelObject(getModelObject().getFirstVisibleUnitIndex()); if (SourceDocumentState.NEW.equals(state.getDocument().getState())) { documentService.transitionSourceDocumentState(state.getDocument(), NEW_TO_ANNOTATION_IN_PROGRESS); new DocumentOpenedEvent(this, editorCas, getModelObject().getDocument(), getModelObject().getUser().getUsername())); LOG.debug("Configured BratAnnotatorModel for user [" + state.getUser().getUsername() + "] f:[" + state.getFirstVisibleUnitIndex() + "] l:[" + state.getLastVisibleUnitIndex() + "] s:[" + state.getFocusUnitIndex() + "]");
private void setCurationSegmentBeginEnd(JCas aEditorCas) throws UIMAException, ClassNotFoundException, IOException { AnnotatorState state = getModelObject(); curationSegment.setBegin(state.getWindowBeginOffset()); curationSegment.setEnd(state.getWindowEndOffset()); }
boolean isAnnotationFinished() { AnnotatorState state = getModelObject(); if (state.getMode().equals(Mode.CURATION)) { return state.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED); } else { return documentService.isAnnotationFinished(state.getDocument(), state.getUser()); } }
private void createNewChainLinkAnnotation(ChainAdapter aAdapter, JCas aJCas) { LOG.trace("createNewChainLinkAnnotation()"); AnnotatorState state = getModelObject(); Selection selection = state.getSelection(); AnnotationFS originFs = selectByAddr(aJCas, selection.getOrigin()); AnnotationFS targetFs = selectByAddr(aJCas, selection.getTarget()); // Creating a new chain link int addr = aAdapter.addArc(state.getDocument(), state.getUser().getUsername(), aJCas, originFs, targetFs); selection.selectArc(new VID(addr), originFs, targetFs); }
private void createSpan(String spanType, AnnotatorState aBModel, JCas aMergeJCas, AnnotationDocument aAnnotationDocument, int aAddress) throws IOException, UIMAException, ClassNotFoundException, AnnotationException { JCas clickedJCas = getJCas(aBModel, aAnnotationDocument); AnnotationFS fsClicked = selectByAddr(clickedJCas, aAddress); if (isCorefType(fsClicked)) { throw new AnnotationException("Coreference Annotation not supported in curation"); } long layerId = TypeUtil.getLayerId(spanType); AnnotationLayer layer = annotationService.getLayer(layerId); MergeCas.addSpanAnnotation(aBModel, annotationService, layer, aMergeJCas, fsClicked, layer.isAllowStacking()); writeEditorCas(aBModel, aMergeJCas); // update timestamp int sentenceNumber = getSentenceNumber(clickedJCas, fsClicked.getBegin()); aBModel.setFocusUnitIndex(sentenceNumber); aBModel.getDocument().setSentenceAccessed(sentenceNumber); if (aBModel.getPreferences().isScrollPage()) { Sentence sentence = selectSentenceAt(aMergeJCas, aBModel.getFirstVisibleUnitBegin(), aBModel.getFirstVisibleUnitEnd()); sentence = findWindowStartCenteringOnSelection(aMergeJCas, sentence, fsClicked.getBegin(), aBModel.getProject(), aBModel.getDocument(), aBModel.getPreferences().getWindowSize()); aBModel.setFirstVisibleUnit(sentence); } }
private void reactToAnnotationsBeingCreatedOrDeleted(IPartialPageRequestHandler aTarget, AnnotationLayer aLayer) { try { AnnotatorState state = getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); // // Make sure we know about the current suggestions and their visibility state // refreshSuggestions(); // Update visibility in case the annotation where the feature was set overlaps with // any suggestions that need to be hidden now. PredictionTask.calculateVisibility(learningRecordService, annotationService, getAnnotationPage().getEditorCas(), state.getUser().getUsername(), aLayer, alState.getSuggestions(), state.getWindowBeginOffset(), state.getWindowEndOffset()); // Update the suggestion in the AL sidebar, but do not jump or touch the right // sidebar such that the user can happily continue to edit the annotation moveToNextRecommendation(aTarget, true); } catch (IOException e) { LOG.info("Error reading CAS: {}", e.getMessage()); error("Error reading CAS " + e.getMessage()); aTarget.addChildren(getPage(), IFeedback.class); } }
/** * @deprecated The UI class {@link AnnotatorState} should not be passed here. Use * {@link #delete(SourceDocument, String, JCas, VID)} instead. */ @Deprecated default void setFeatureValue(AnnotatorState aState, JCas aJCas, int aAddress, AnnotationFeature aFeature, Object aValue) { setFeatureValue(aState.getDocument(), aState.getUser().getUsername(), aJCas, aAddress, aFeature, aValue); }
@OnEvent public void onRenderAnnotations(RenderAnnotationsEvent aEvent) { AnnotatorState state = aEvent.getState(); if (selectedResult != null) { if ( // Check if match is in current document selectedResult.getDocumentId() == state.getDocument().getId() && // Check if match is in currently visible part of the document state.getWindowBeginOffset() <= selectedResult.getOffsetStart() && selectedResult.getOffsetEnd() <= state.getWindowEndOffset() ) { aEvent.getVDocument() .add(new VTextMarker(VMarker.MATCH_FOCUS, selectedResult.getOffsetStart() - state.getWindowBeginOffset(), selectedResult.getOffsetEnd() - state.getWindowBeginOffset())); } } }
private String render(JCas aJcas, AnnotatorState aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException { List<AnnotationLayer> layersToRender = new ArrayList<>(); for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) { boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName()); boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE); if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) { layersToRender.add(layer); } } VDocument vdoc = new VDocument(); preRenderer.render(vdoc, aBratAnnotatorModel.getWindowBeginOffset(), aBratAnnotatorModel.getWindowEndOffset(), aJcas, layersToRender); GetDocumentResponse response = new GetDocumentResponse(); BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy); return JSONUtil.toInterpretableJsonString(response); }
state.getPreferences().setWindowSize(10); state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(jCas)); state.setProject(project); preRenderer.render(vdoc, state.getWindowBeginOffset(), state.getWindowEndOffset(), jCas, schemaService.listAnnotationLayer(project));
public static void renderTokenAndSentence(JCas aJcas, GetDocumentResponse aResponse, AnnotatorState aState) int windowBegin = aState.getWindowBeginOffset(); int windowEnd = aState.getWindowEndOffset(); aResponse.setSentenceNumberOffset(aState.getFirstVisibleUnitIndex());
@Override protected void onConfigure() { super.onConfigure(); AnnotatorState state = CurationPage.this.getModelObject(); setEnabled(state.getProject() != null && state.getDocument() != null && !documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)); } });