use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID 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.model.VID in project webanno by webanno.
the class ChainRenderer method render.
@Override
public void render(JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aState) {
List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
// Find the features for the arc and span labels - it is possible that we do not find a
// feature for arc/span labels because they may have been disabled.
AnnotationFeature spanLabelFeature = null;
AnnotationFeature arcLabelFeature = null;
for (AnnotationFeature f : visibleFeatures) {
if (WebAnnoConst.COREFERENCE_TYPE_FEATURE.equals(f.getName())) {
spanLabelFeature = f;
}
if (WebAnnoConst.COREFERENCE_RELATION_FEATURE.equals(f.getName())) {
arcLabelFeature = f;
}
}
// At this point arc and span feature labels must have been found! If not, the later code
// will crash.
ChainAdapter typeAdapter = getTypeAdapter();
Type chainType = typeAdapter.getAnnotationType(aJcas.getCas());
Feature chainFirst = chainType.getFeatureByBaseName(typeAdapter.getChainFirstFeatureName());
int colorIndex = 0;
// Iterate over the chains
for (FeatureStructure chainFs : selectFS(aJcas.getCas(), chainType)) {
AnnotationFS linkFs = (AnnotationFS) chainFs.getFeatureValue(chainFirst);
AnnotationFS prevLinkFs = null;
// Iterate over the links of the chain
while (linkFs != null) {
Feature linkNext = linkFs.getType().getFeatureByBaseName(typeAdapter.getLinkNextFeatureName());
AnnotationFS nextLinkFs = (AnnotationFS) linkFs.getFeatureValue(linkNext);
// Is link after window? If yes, we can skip the rest of the chain
if (linkFs.getBegin() >= aState.getWindowEndOffset()) {
// Go to next chain
break;
}
// end within the window
if (!(linkFs.getBegin() >= aState.getWindowBeginOffset()) && (linkFs.getEnd() <= aState.getWindowEndOffset())) {
// prevLinkFs remains null until we enter the window
linkFs = nextLinkFs;
// Go to next link
continue;
}
String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
// Render span
{
String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, linkFs, (spanLabelFeature != null) ? asList(spanLabelFeature) : emptyList());
String bratHoverText = TypeUtil.getUiHoverText(typeAdapter, linkFs, (spanLabelFeature != null) ? asList(spanLabelFeature) : emptyList());
VRange offsets = new VRange(linkFs.getBegin() - aState.getWindowBeginOffset(), linkFs.getEnd() - aState.getWindowBeginOffset());
aResponse.add(new VSpan(typeAdapter.getLayer(), linkFs, bratTypeName, offsets, colorIndex, singletonMap("label", bratLabelText), singletonMap("label", bratHoverText)));
}
// and last link are within the window ;)
if (prevLinkFs != null) {
String bratLabelText = null;
if (typeAdapter.isLinkedListBehavior() && arcLabelFeature != null) {
// Render arc label
bratLabelText = TypeUtil.getUiLabelText(typeAdapter, prevLinkFs, asList(arcLabelFeature));
} else {
// Render only chain type
bratLabelText = TypeUtil.getUiLabelText(typeAdapter, prevLinkFs, emptyList());
}
aResponse.add(new VArc(typeAdapter.getLayer(), new VID(prevLinkFs, 1, VID.NONE, VID.NONE), bratTypeName, prevLinkFs, linkFs, colorIndex, singletonMap("label", bratLabelText)));
}
// Render errors if required features are missing
renderRequiredFeatureErrors(visibleFeatures, linkFs, aResponse);
// if (BratAjaxCasUtil.isSame(linkFs, nextLinkFs)) {
// log.error("Loop in CAS detected, aborting rendering of chains");
// break;
// }
prevLinkFs = linkFs;
linkFs = nextLinkFs;
}
// The color index is updated even for chains that have no visible links in the current
// window because we would like the chain color to be independent of visibility. In
// particular the color of a chain should not change when switching pages/scrolling.
colorIndex++;
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID in project webanno by webanno.
the class SpanRenderer method render.
@Override
public void render(JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
SpanAdapter typeAdapter = getTypeAdapter();
Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
List<Sentence> visibleSentences = selectCovered(aJcas, Sentence.class, windowBegin, windowEnd);
for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
Map<String, String> hoverFeatures = getHoverFeatures(typeAdapter, fs, aFeatures);
Sentence beginSent = null;
Sentence endSent = null;
// the visible window
for (Sentence sent : visibleSentences) {
if (beginSent == null) {
// offset of the current annotation.
if (sent.getBegin() <= fs.getBegin() && fs.getBegin() <= sent.getEnd()) {
beginSent = sent;
}
// second sentence.
if (fs.getBegin() == fs.getEnd()) {
endSent = sent;
}
}
if (endSent == null) {
if (sent.getBegin() <= fs.getEnd() && fs.getEnd() <= sent.getEnd()) {
endSent = sent;
}
}
if (beginSent != null && endSent != null) {
break;
}
}
if (beginSent == null || endSent == null) {
throw new IllegalStateException("Unable to determine sentences in which the annotation starts/ends: " + fs);
}
List<Sentence> sentences = selectCovered(aJcas, Sentence.class, beginSent.getBegin(), endSent.getEnd());
List<VRange> ranges = new ArrayList<>();
if (sentences.size() > 1) {
for (Sentence sentence : sentences) {
if (sentence.getBegin() <= fs.getBegin() && fs.getBegin() < sentence.getEnd()) {
ranges.add(new VRange(fs.getBegin() - windowBegin, sentence.getEnd() - windowBegin));
} else if (sentence.getBegin() <= fs.getEnd() && fs.getEnd() <= sentence.getEnd()) {
ranges.add(new VRange(sentence.getBegin() - windowBegin, fs.getEnd() - windowBegin));
} else {
ranges.add(new VRange(sentence.getBegin() - windowBegin, sentence.getEnd() - windowBegin));
}
}
aResponse.add(new VSpan(typeAdapter.getLayer(), fs, bratTypeName, ranges, features, hoverFeatures));
} else {
// FIXME It should be possible to remove this case and the if clause because
// the case that a FS is inside a single sentence is just a special case
aResponse.add(new VSpan(typeAdapter.getLayer(), fs, bratTypeName, new VRange(fs.getBegin() - windowBegin, fs.getEnd() - windowBegin), features, hoverFeatures));
}
// Render errors if required features are missing
renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
// Render slots
int fi = 0;
for (AnnotationFeature feat : typeAdapter.listFeatures()) {
if (MultiValueMode.ARRAY.equals(feat.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(feat.getLinkMode())) {
List<LinkWithRoleModel> links = typeAdapter.getFeatureValue(feat, fs);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
FeatureStructure targetFS = selectByAddr(fs.getCAS(), link.targetAddr);
aResponse.add(new VArc(typeAdapter.getLayer(), new VID(fs, fi, li), bratTypeName, fs, targetFS, link.role, features));
}
}
fi++;
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID in project webanno by webanno.
the class ArcAdapter method delete.
public void delete(AnnotatorState aState, JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, String aDepCoveredText, String aGovCoveredText, Object aValue) {
Feature dependentFeature = getAnnotationType(aJCas.getCas()).getFeatureByBaseName(getTargetFeatureName());
Feature governorFeature = getAnnotationType(aJCas.getCas()).getFeatureByBaseName(getSourceFeatureName());
AnnotationFS dependentFs = null;
AnnotationFS governorFs = null;
Type type = CasUtil.getType(aJCas.getCas(), getAnnotationTypeName());
Type spanType = getType(aJCas.getCas(), getAttachTypeName());
Feature arcSpanFeature = spanType.getFeatureByBaseName(getAttachFeatureName());
for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) {
if (getAttachFeatureName() != null) {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
} else {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature);
}
if (aDepCoveredText.equals(dependentFs.getCoveredText()) && aGovCoveredText.equals(governorFs.getCoveredText())) {
if (ObjectUtils.equals(getFeatureValue(aFeature, fs), aValue)) {
delete(aState, aJCas, new VID(getAddr(fs)));
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID in project webanno by webanno.
the class EntityTest method toJsonTest.
@Test
public void toJsonTest() throws IOException {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
String json = JSONUtil.toPrettyJsonString(jsonConverter, new Entity(new VID(1, 2), "type", new Offsets(1, 2), "label", "color", "somehoverspantext"));
assertEquals("[ \"1.2\", \"type\", [ [ 1, 2 ] ], \"label\", \"color\", \"somehoverspantext\" ]", json);
}
Aggregations