use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class FeatureAttachedSpanAnnotationsTrulyAttachedCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
boolean ok = true;
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
Type layerType;
Type attachType;
try {
layerType = getType(aCas, layer.getName());
attachType = getType(aCas, layer.getAttachType().getName());
} catch (IllegalArgumentException e) {
// check
continue;
}
for (AnnotationFS anno : select(aCas, layerType)) {
for (AnnotationFS attach : selectCovered(attachType, anno)) {
AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
if (candidate != anno) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Annotation should be attached to [" + layer.getAttachFeature().getName() + "] but is not.\nAnnotation: [" + anno + "]\nAttach annotation:[" + attach + "]"));
ok = false;
}
}
}
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class ReattachFeatureAttachedSpanAnnotationsAndDeleteExtrasRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
int count = 0;
// attach -> e.g. Token
for (AnnotationFS anno : select(aCas, getType(aCas, layer.getName()))) {
for (AnnotationFS attach : selectCovered(getType(aCas, layer.getAttachType().getName()), anno)) {
AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
if (candidate == null) {
setFeature(attach, layer.getAttachFeature().getName(), anno);
count++;
} else if (candidate != anno) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot attach annotation because attach feature alread non-null"));
}
}
}
if (count > 0) {
aMessages.add(new LogMessage(this, LogLevel.INFO, "Reattached [%d] unattached spans layer [" + layer.getName() + "].", count));
}
// Go over the layer that is being attached to (e.g. Lemma) and ensure that if there
// only exactly one annotation for each annotation in the layer that has the attach
// feature (e.g. Token) - or short: ensure that there are not multiple Lemmas for a
// single Token because such a thing is not valid in WebAnno. Layers that have an
// attach feature cannot have stacking enabled!
//
// attach -> e.g. Token
// candidates -> e.g. Lemma
List<AnnotationFS> toDelete = new ArrayList<>();
for (AnnotationFS attach : select(aCas, getType(aCas, layer.getAttachType().getName()))) {
List<AnnotationFS> candidates = selectCovered(getType(aCas, layer.getName()), attach);
if (!candidates.isEmpty()) {
// One of the candidates should already be attached
AnnotationFS attachedCandidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
for (AnnotationFS candidate : candidates) {
if (candidate != attachedCandidate) {
toDelete.add(candidate);
}
}
}
}
// Delete those the extra candidates that are not properly attached
if (!toDelete.isEmpty()) {
toDelete.forEach(aCas::removeFsFromIndexes);
aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] unattached stacked candidates [" + layer.getName() + "].", toDelete.size()));
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class ReattachFeatureAttachedSpanAnnotationsRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
int count = 0;
// attach -> e.g. Token
for (AnnotationFS anno : select(aCas, getType(aCas, layer.getName()))) {
for (AnnotationFS attach : selectCovered(getType(aCas, layer.getAttachType().getName()), anno)) {
AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
if (candidate == null) {
setFeature(attach, layer.getAttachFeature().getName(), anno);
count++;
} else if (candidate != anno) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot attach annotation because attach feature alread non-null"));
}
}
}
if (count > 0) {
aMessages.add(new LogMessage(this, LogLevel.INFO, "Reattached [%d] unattached spans on layer [" + layer.getName() + "].", count));
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationSchemaServiceImpl method getProjectTypes.
@Override
public TypeSystemDescription getProjectTypes(Project aProject) {
// Create a new type system from scratch
TypeSystemDescription tsd = new TypeSystemDescription_impl();
for (AnnotationLayer type : listAnnotationLayer(aProject)) {
if (type.getType().equals(SPAN_TYPE) && !type.isBuiltIn()) {
TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
generateFeatures(tsd, td, type);
} else if (type.getType().equals(RELATION_TYPE) && !type.isBuiltIn()) {
TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
AnnotationLayer attachType = type.getAttachType();
td.addFeature(WebAnnoConst.FEAT_REL_TARGET, "", attachType.getName());
td.addFeature(WebAnnoConst.FEAT_REL_SOURCE, "", attachType.getName());
generateFeatures(tsd, td, type);
} else if (type.getType().equals(CHAIN_TYPE) && !type.isBuiltIn()) {
TypeDescription tdChains = tsd.addType(type.getName() + "Chain", "", CAS.TYPE_NAME_ANNOTATION_BASE);
tdChains.addFeature("first", "", type.getName() + "Link");
// Custom features on chain layers are currently not supported
// generateFeatures(tsd, tdChains, type);
TypeDescription tdLink = tsd.addType(type.getName() + "Link", "", CAS.TYPE_NAME_ANNOTATION);
tdLink.addFeature("next", "", type.getName() + "Link");
tdLink.addFeature("referenceType", "", CAS.TYPE_NAME_STRING);
tdLink.addFeature("referenceRelation", "", CAS.TYPE_NAME_STRING);
}
}
return tsd;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationSchemaServiceImpl method getLayer.
@Override
@Transactional(noRollbackFor = NoResultException.class)
public AnnotationLayer getLayer(Project aProject, FeatureStructure aFS) {
String layerName = aFS.getType().getName();
AnnotationLayer layer;
try {
layer = getLayer(layerName, aProject);
} catch (NoResultException e) {
if (layerName.endsWith("Chain")) {
layerName = layerName.substring(0, layerName.length() - 5);
}
if (layerName.endsWith("Link")) {
layerName = layerName.substring(0, layerName.length() - 4);
}
layer = getLayer(layerName, aProject);
}
return layer;
}
Aggregations