use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.
the class AnnotationPageBase method ensureRequiredFeatureValuesSet.
/**
* Checks if all required features on all annotations are set. If a required feature value is
* missing, then the method scrolls to that location and schedules a re-rendering. In such
* a case, an {@link IllegalStateException} is thrown.
*/
protected void ensureRequiredFeatureValuesSet(AjaxRequestTarget aTarget, JCas aJcas) {
AnnotatorState state = getModelObject();
CAS editorCas = aJcas.getCas();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(state.getProject())) {
TypeAdapter adapter = annotationService.getAdapter(layer);
List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
// If no feature is required, then we can skip the whole procedure
if (features.stream().allMatch((f) -> !f.isRequired())) {
continue;
}
// Check each feature structure of this layer
for (AnnotationFS fs : select(editorCas, adapter.getAnnotationType(editorCas))) {
for (AnnotationFeature f : features) {
if (WebAnnoCasUtil.isRequiredFeatureMissing(f, fs)) {
// Find the sentence that contains the annotation with the missing
// required feature value
Sentence s = WebAnnoCasUtil.getSentence(aJcas, fs.getBegin());
// Put this sentence into the focus
state.setFirstVisibleUnit(s);
actionRefreshDocument(aTarget);
// Inform the user
throw new IllegalStateException("Document cannot be marked as finished. Annotation with ID [" + WebAnnoCasUtil.getAddr(fs) + "] on layer [" + layer.getUiName() + "] is missing value for feature [" + f.getUiName() + "].");
}
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.
the class SuggestionViewPanel method mergeArc.
private void mergeArc(IRequestParameters aRequest, UserAnnotationSegment aCurationUserSegment, JCas aJcas) throws AnnotationException, IOException, UIMAException, ClassNotFoundException {
int addressOriginClicked = aRequest.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt();
int addressTargetClicked = aRequest.getParameterValue(PARAM_TARGET_SPAN_ID).toInt();
String arcType = removePrefix(aRequest.getParameterValue(PARAM_TYPE).toString());
String fsArcaddress = aRequest.getParameterValue(PARAM_ARC_ID).toString();
AnnotatorState bModel = aCurationUserSegment.getAnnotatorState();
SourceDocument sourceDocument = bModel.getDocument();
// for correction and automation, the lower panel is the clickedJcase, from the suggestions
JCas clickedJCas;
if (!aCurationUserSegment.getAnnotatorState().getMode().equals(Mode.CURATION)) {
clickedJCas = correctionDocumentService.readCorrectionCas(sourceDocument);
} else {
User user = userRepository.get(aCurationUserSegment.getUsername());
AnnotationDocument clickedAnnotationDocument = documentService.getAnnotationDocument(sourceDocument, user);
clickedJCas = getJCas(bModel, clickedAnnotationDocument);
}
long layerId = TypeUtil.getLayerId(arcType);
AnnotationLayer layer = annotationService.getLayer(layerId);
TypeAdapter adapter = annotationService.getAdapter(layer);
int address = Integer.parseInt(fsArcaddress.split("\\.")[0]);
AnnotationFS clickedFS = selectByAddr(clickedJCas, address);
if (isCorefType(clickedFS)) {
throw new AnnotationException(" Coreference Annotation not supported in curation");
}
MergeCas.addArcAnnotation(adapter, aJcas, addressOriginClicked, addressTargetClicked, fsArcaddress, clickedJCas, clickedFS);
writeEditorCas(bModel, aJcas);
int sentenceNumber = getSentenceNumber(clickedJCas, clickedFS.getBegin());
bModel.setFocusUnitIndex(sentenceNumber);
// Update timestamp
bModel.getDocument().setSentenceAccessed(sentenceNumber);
if (bModel.getPreferences().isScrollPage()) {
Sentence sentence = selectSentenceAt(aJcas, bModel.getFirstVisibleUnitBegin(), bModel.getFirstVisibleUnitEnd());
sentence = findWindowStartCenteringOnSelection(aJcas, sentence, clickedFS.getBegin(), bModel.getProject(), bModel.getDocument(), bModel.getPreferences().getWindowSize());
bModel.setFirstVisibleUnit(sentence);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.
the class SuggestionViewPanel method addSuggestionColor.
/**
* For each {@link ConfigurationSet}, where there are some differences in users annotation and
* the curation annotation.
*/
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
for (ConfigurationSet cs : aCfgSet) {
boolean use = false;
for (String u : cs.getCasGroupIds()) {
Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
if (colors == null) {
colors = new HashMap<>();
aSuggestionColors.put(u, colors);
}
for (Configuration c : cs.getConfigurations(u)) {
FeatureStructure fs = c.getFs(u, aCasMap);
AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
TypeAdapter typeAdapter = annotationService.getAdapter(layer);
VID vid;
// link FS
if (c.getPosition().getFeature() != null) {
int fi = 0;
for (AnnotationFeature f : typeAdapter.listFeatures()) {
if (f.getName().equals(c.getPosition().getFeature())) {
break;
}
fi++;
}
vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
} else {
vid = new VID(WebAnnoCasUtil.getAddr(fs));
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
continue;
}
// automation and correction projects
if (!aMode.equals(Mode.CURATION) && !aAgree) {
if (cs.getCasGroupIds().size() == 2) {
colors.put(vid, AnnotationState.DO_NOT_USE);
} else {
colors.put(vid, AnnotationState.DISAGREE);
}
continue;
}
// this set agree with the curation annotation
if (c.getCasGroupIds().contains(CURATION_USER)) {
use = true;
} else {
use = false;
}
// this curation view
if (u.equals(CURATION_USER)) {
continue;
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
} else if (use) {
colors.put(vid, AnnotationState.USE);
} else if (aI) {
colors.put(vid, AnnotationState.DISAGREE);
} else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
colors.put(vid, AnnotationState.DISAGREE);
} else {
colors.put(vid, AnnotationState.DO_NOT_USE);
}
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.
the class PreRenderer method render.
public void render(VDocument aResponse, AnnotatorState aState, JCas aJCas, List<AnnotationLayer> aLayers) {
// Render (custom) layers
for (AnnotationLayer layer : aLayers) {
List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
TypeAdapter adapter = annotationService.getAdapter(layer);
Renderer renderer = getRenderer(adapter);
renderer.render(aJCas, features, aResponse, aState);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.
the class AnnotationDetailEditorPanel method getAttachedLinks.
private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer) {
CAS cas = aFs.getCAS();
Set<AnnotationFS> attachedLinks = new HashSet<>();
TypeAdapter adapter = annotationService.getAdapter(aLayer);
if (adapter instanceof SpanAdapter) {
for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(aLayer)) {
if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
// Fetch slot hosts that could link to the current FS and check if any of
// them actually links to the current FS
Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class, link.targetAddr);
// our list of attached links.
if (isSame(linkTarget, aFs)) {
attachedLinks.add(linkFS);
}
}
}
}
}
}
return attachedLinks;
}
Aggregations