use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class LinksReachableThroughChainsCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
boolean ok = true;
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!WebAnnoConst.CHAIN_TYPE.equals(layer.getType())) {
continue;
}
Type chainType;
Type linkType;
try {
chainType = getType(aCas, layer.getName() + "Chain");
linkType = getType(aCas, layer.getName() + "Link");
} catch (IllegalArgumentException e) {
// check
continue;
}
List<FeatureStructure> chains = new ArrayList<>(selectFS(aCas, chainType));
List<AnnotationFS> links = new ArrayList<>(select(aCas, linkType));
for (FeatureStructure chain : chains) {
AnnotationFS link = FSUtil.getFeature(chain, "first", AnnotationFS.class);
while (link != null) {
links.remove(link);
link = FSUtil.getFeature(link, "next", AnnotationFS.class);
}
}
if (!links.isEmpty()) {
ok = false;
aMessages.add(new LogMessage(this, LogLevel.ERROR, "CoreferenceLinks not reachable through chains: %d", links.size()));
for (AnnotationFS link : links) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unreachable CoreferenceLink [%s]", link));
}
}
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class RelationOffsetsCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
boolean ok = true;
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!WebAnnoConst.RELATION_TYPE.equals(layer.getType())) {
continue;
}
Type type;
try {
type = getType(aCas, layer.getName());
} catch (IllegalArgumentException e) {
// can skip checking the layer because there will be no annotations anyway.
continue;
}
for (AnnotationFS rel : select(aCas, type)) {
AnnotationFS target = getFeature(rel, WebAnnoConst.FEAT_REL_TARGET, AnnotationFS.class);
if ((rel.getBegin() != target.getBegin()) || (rel.getEnd() != target.getEnd())) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Relation offsets [%d,%d] to not match target offsets [%d,%d]", rel.getBegin(), rel.getEnd(), target.getBegin(), target.getEnd()));
ok = false;
}
}
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class BratRenderer method render.
/**
* wrap JSON responses to BRAT visualizer
*
* @param aResponse
* the response.
* @param aState
* the annotator model.
* @param aJCas
* the JCas.
* @param aAnnotationService
* the annotation service.s
*/
public static void render(GetDocumentResponse aResponse, AnnotatorState aState, VDocument aVDoc, JCas aJCas, AnnotationSchemaService aAnnotationService, ColoringStrategy aColoringStrategy) {
aResponse.setRtlMode(ScriptDirection.RTL.equals(aState.getScriptDirection()));
aResponse.setFontZoom(aState.getPreferences().getFontZoom());
// Render invisible baseline annotations (sentence, tokens)
renderTokenAndSentence(aJCas, aResponse, aState);
// Render visible (custom) layers
Map<String[], Queue<String>> colorQueues = new HashMap<>();
for (AnnotationLayer layer : aVDoc.getAnnotationLayers()) {
ColoringStrategy coloringStrategy = aColoringStrategy != null ? aColoringStrategy : ColoringStrategy.getStrategy(aAnnotationService, layer, aState.getPreferences(), colorQueues);
TypeAdapter typeAdapter = aAnnotationService.getAdapter(layer);
for (VSpan vspan : aVDoc.spans(layer.getId())) {
List<Offsets> offsets = toOffsets(vspan.getRanges());
String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures());
String bratHoverText = TypeUtil.getUiHoverText(typeAdapter, vspan.getHoverFeatures());
String color;
if (vspan.getColorHint() == null) {
color = getColor(vspan, coloringStrategy, bratLabelText);
} else {
color = vspan.getColorHint();
}
aResponse.addEntity(new Entity(vspan.getVid(), vspan.getType(), offsets, bratLabelText, color, bratHoverText));
}
for (VArc varc : aVDoc.arcs(layer.getId())) {
String bratLabelText;
if (varc.getLabelHint() == null) {
bratLabelText = TypeUtil.getUiLabelText(typeAdapter, varc.getFeatures());
} else {
bratLabelText = varc.getLabelHint();
}
String color;
if (varc.getColorHint() == null) {
color = getColor(varc, coloringStrategy, bratLabelText);
} else {
color = varc.getColorHint();
}
aResponse.addRelation(new Relation(varc.getVid(), varc.getType(), getArgument(varc.getSource(), varc.getTarget()), bratLabelText, color));
}
}
List<Sentence> sentences = new ArrayList<>(select(aJCas, Sentence.class));
for (VComment vcomment : aVDoc.comments()) {
String type;
switch(vcomment.getCommentType()) {
case ERROR:
type = AnnotationComment.ANNOTATION_ERROR;
break;
case INFO:
type = AnnotationComment.ANNOTATOR_NOTES;
break;
case YIELD:
type = "Yield";
break;
default:
type = AnnotationComment.ANNOTATOR_NOTES;
break;
}
AnnotationFS fs;
if (!vcomment.getVid().isSynthetic() && ((fs = selectByAddr(aJCas, vcomment.getVid().getId())) instanceof Sentence)) {
int index = sentences.indexOf(fs) + 1;
aResponse.addComment(new SentenceComment(index, type, vcomment.getComment()));
} else {
aResponse.addComment(new AnnotationComment(vcomment.getVid(), type, vcomment.getComment()));
}
}
// Render markers
for (VMarker vmarker : aVDoc.getMarkers()) {
if (vmarker instanceof VAnnotationMarker) {
VAnnotationMarker marker = (VAnnotationMarker) vmarker;
aResponse.addMarker(new AnnotationMarker(vmarker.getType(), marker.getVid()));
} else if (vmarker instanceof VSentenceMarker) {
VSentenceMarker marker = (VSentenceMarker) vmarker;
aResponse.addMarker(new SentenceMarker(vmarker.getType(), marker.getIndex()));
} else if (vmarker instanceof VTextMarker) {
VTextMarker marker = (VTextMarker) vmarker;
aResponse.addMarker(new TextMarker(marker.getType(), marker.getBegin(), marker.getEnd()));
} else {
LOG.warn("Unknown how to render marker: [" + vmarker + "]");
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class BratRenderer method buildEntityTypes.
/**
* Generates brat type definitions from the WebAnno layer definitions.
*
* @param aAnnotationLayers
* the layers
* @param aAnnotationService
* the annotation service
* @return the brat type definitions
*/
public static Set<EntityType> buildEntityTypes(List<AnnotationLayer> aAnnotationLayers, AnnotationSchemaService aAnnotationService) {
// Sort layers
List<AnnotationLayer> layers = new ArrayList<>(aAnnotationLayers);
layers.sort(Comparator.comparing(AnnotationLayer::getName));
// Now build the actual configuration
Set<EntityType> entityTypes = new LinkedHashSet<>();
for (AnnotationLayer layer : layers) {
EntityType entityType = configureEntityType(layer);
List<RelationType> arcs = new ArrayList<>();
// For link features, we also need to configure the arcs, even though there is no arc
// layer here.
boolean hasLinkFeatures = false;
for (AnnotationFeature f : aAnnotationService.listAnnotationFeature(layer)) {
if (!LinkMode.NONE.equals(f.getLinkMode())) {
hasLinkFeatures = true;
break;
}
}
if (hasLinkFeatures) {
String bratTypeName = getBratTypeName(layer);
arcs.add(new RelationType(layer.getName(), layer.getUiName(), bratTypeName, bratTypeName, null, "triangle,5", "3,3"));
}
// Styles for the remaining relation and chain layers
for (AnnotationLayer attachingLayer : getAttachingLayers(layer, layers, aAnnotationService)) {
arcs.add(configureRelationType(layer, attachingLayer));
}
entityType.setArcs(arcs);
entityTypes.add(entityType);
}
return entityTypes;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class ImportUtil method exportLayerDetails.
public static de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exportLayerDetails(Map<AnnotationLayer, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) {
de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer();
exLayer.setAllowStacking(aLayer.isAllowStacking());
exLayer.setBuiltIn(aLayer.isBuiltIn());
exLayer.setReadonly(aLayer.isReadonly());
exLayer.setCrossSentence(aLayer.isCrossSentence());
exLayer.setDescription(aLayer.getDescription());
exLayer.setEnabled(aLayer.isEnabled());
exLayer.setLockToTokenOffset(aLayer.isLockToTokenOffset());
exLayer.setMultipleTokens(aLayer.isMultipleTokens());
exLayer.setLinkedListBehavior(aLayer.isLinkedListBehavior());
exLayer.setName(aLayer.getName());
exLayer.setProjectName(aLayer.getProject().getName());
exLayer.setType(aLayer.getType());
exLayer.setUiName(aLayer.getUiName());
if (aLayerToExLayer != null) {
aLayerToExLayer.put(aLayer, exLayer);
}
List<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> exFeatures = new ArrayList<>();
for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) {
de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exFeature = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature();
exFeature.setDescription(feature.getDescription());
exFeature.setEnabled(feature.isEnabled());
exFeature.setRemember(feature.isRemember());
exFeature.setRequired(feature.isRequired());
exFeature.setHideUnconstraintFeature(feature.isHideUnconstraintFeature());
exFeature.setName(feature.getName());
exFeature.setProjectName(feature.getProject().getName());
exFeature.setType(feature.getType());
exFeature.setUiName(feature.getUiName());
exFeature.setVisible(feature.isVisible());
exFeature.setMultiValueMode(feature.getMultiValueMode());
exFeature.setLinkMode(feature.getLinkMode());
exFeature.setLinkTypeName(feature.getLinkTypeName());
exFeature.setLinkTypeRoleFeatureName(feature.getLinkTypeRoleFeatureName());
exFeature.setLinkTypeTargetFeatureName(feature.getLinkTypeTargetFeatureName());
if (feature.getTagset() != null) {
TagSet tagSet = feature.getTagset();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
exTagSet.setCreateTag(tagSet.isCreateTag());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : aAnnotationService.listTags(tagSet)) {
ExportedTag exTag = new ExportedTag();
exTag.setDescription(tag.getDescription());
exTag.setName(tag.getName());
exportedTags.add(exTag);
}
exTagSet.setTags(exportedTags);
exFeature.setTagSet(exTagSet);
}
exFeatures.add(exFeature);
if (aFeatureToExFeature != null) {
aFeatureToExFeature.put(feature, exFeature);
}
}
exLayer.setFeatures(exFeatures);
return exLayer;
}
Aggregations