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);
}
}
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);
});
}
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();
}
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"));
}
Aggregations