Search in sources :

Example 81 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class SuggestionViewPanel method init.

/**
 * Initializes the user annotation segments later to be filled with content.
 */
public void init(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException {
    AnnotatorState state = aCurationContainer.getAnnotatorState();
    SourceDocument sourceDocument = state.getDocument();
    Map<String, JCas> jCases = new HashMap<>();
    // This is the CAS that the user can actively edit
    JCas annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, jCases);
    // We store the CAS that the user will edit as the "CURATION USER"
    jCases.put(CURATION_USER, annotatorCas);
    // get differing feature structures
    Map<String, Map<VID, AnnotationState>> annoStates = calcColors(state, aCurationSegment, annotatorCas, jCases);
    List<String> usernamesSorted = new ArrayList<>(jCases.keySet());
    Collections.sort(usernamesSorted);
    final Mode mode = state.getMode();
    boolean isAutomationMode = mode.equals(Mode.AUTOMATION);
    boolean isCorrectionMode = mode.equals(Mode.CORRECTION);
    boolean isCurationMode = mode.equals(Mode.CURATION);
    List<UserAnnotationSegment> segments = new ArrayList<>();
    for (String username : usernamesSorted) {
        if ((!username.equals(CURATION_USER) && isCurationMode) || (username.equals(CURATION_USER) && (isAutomationMode || isCorrectionMode))) {
            JCas jCas = jCases.get(username);
            // Set up coloring strategy
            ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(username));
            // Create curation view for the current user
            UserAnnotationSegment seg = new UserAnnotationSegment();
            seg.setUsername(username);
            seg.setAnnotatorState(state);
            seg.setCollectionData(getCollectionInformation(annotationService, aCurationContainer));
            seg.setDocumentResponse(render(jCas, state, curationColoringStrategy));
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
            segments.add(seg);
        }
    }
    sentenceListView.setModelObject(segments);
    if (aTarget != null) {
        aTarget.add(this);
    }
}
Also used : HashMap(java.util.HashMap) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 82 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class SuggestionViewPanel method updatePanel.

/**
 * @param aTarget
 *            the AJAX target.
 * @param aCurationContainer
 *            the container.
 * @param aAnnotationSelectionByUsernameAndAddress
 *            selections by user.
 * @param aCurationSegment
 *            the segment.
 * @throws UIMAException
 *             hum?
 * @throws ClassNotFoundException
 *             hum?
 * @throws IOException
 *             hum?
 * @throws AnnotationException
 *             hum?
 */
public void updatePanel(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    AnnotatorState state = aCurationContainer.getAnnotatorState();
    SourceDocument sourceDocument = state.getDocument();
    Map<String, JCas> jCases = new HashMap<>();
    // This is the CAS that the user can actively edit
    JCas annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, jCases);
    // We store the CAS that the user will edit as the "CURATION USER"
    jCases.put(CURATION_USER, annotatorCas);
    // get differing feature structures
    Map<String, Map<VID, AnnotationState>> annoStates = calcColors(state, aCurationSegment, annotatorCas, jCases);
    sentenceListView.visitChildren(BratSuggestionVisualizer.class, (v, visit) -> {
        BratSuggestionVisualizer vis = (BratSuggestionVisualizer) v;
        UserAnnotationSegment seg = vis.getModelObject();
        JCas jCas = jCases.get(seg.getUsername());
        // Set up coloring strategy
        ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(seg.getUsername()));
        // Create curation view for the current user
        try {
            seg.setCollectionData(getCollectionInformation(annotationService, aCurationContainer));
            seg.setDocumentResponse(render(jCas, state, curationColoringStrategy));
            seg.setAnnotatorState(state);
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
        } catch (IOException e) {
            error("Unable to render: " + e.getMessage());
            LOG.error("Unable to render", e);
        }
        vis.requestRender(aTarget);
    });
}
Also used : BratSuggestionVisualizer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.BratSuggestionVisualizer) HashMap(java.util.HashMap) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 83 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class BratAnnotationEditor method actionArc.

private ArcAnnotationResponse actionArc(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException, AnnotationException {
    AnnotationFS originFs = selectByAddr(jCas, request.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt());
    AnnotationFS targetFs = selectByAddr(jCas, request.getParameterValue(PARAM_TARGET_SPAN_ID).toInt());
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    selection.selectArc(paramId, originFs, targetFs);
    if (selection.getAnnotation().isNotSet()) {
        // Create new annotation
        getActionHandler().actionCreateOrUpdate(aTarget, jCas);
    } else {
        getActionHandler().actionSelect(aTarget, jCas);
    }
    return new ArcAnnotationResponse();
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) ArcAnnotationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.ArcAnnotationResponse) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 84 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class CasToBratJsonTest method testGenerateBratJsonGetDocument.

/**
 * generate brat JSON data for the document
 */
@Test
public void testGenerateBratJsonGetDocument() throws Exception {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    String jsonFilePath = "target/test-output/output_cas_to_json_document.json";
    String file = "src/test/resources/tcf04-karin-wl.xml";
    CAS cas = JCasFactory.createJCas().getCas();
    CollectionReader reader = CollectionReaderFactory.createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
    reader.getNext(cas);
    JCas jCas = cas.getJCas();
    AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
    state.getPreferences().setWindowSize(10);
    state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(jCas));
    state.setProject(project);
    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, state, jCas, annotationSchemaService.listAnnotationLayer(project));
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer.render(response, state, vdoc, jCas, annotationSchemaService);
    JSONUtil.generatePrettyJson(jsonConverter, response, new File(jsonFilePath));
    assertThat(linesOf(new File("src/test/resources/output_cas_to_json_document_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) CollectionReader(org.apache.uima.collection.CollectionReader) GetDocumentResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse) CAS(org.apache.uima.cas.CAS) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) File(java.io.File) Test(org.junit.Test)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)84 JCas (org.apache.uima.jcas.JCas)37 IOException (java.io.IOException)26 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)23 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 UIMAException (org.apache.uima.UIMAException)20 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)16 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)16 ArrayList (java.util.ArrayList)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)14 List (java.util.List)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 Map (java.util.Map)9 NoResultException (javax.persistence.NoResultException)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8