use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage 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.diag.CasDoctor.LogMessage in project webanno by webanno.
the class NoZeroSizeTokensAndSentencesCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
try {
boolean ok = true;
for (Token t : select(aCas.getJCas(), Token.class)) {
if (t.getBegin() >= t.getEnd()) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Token with illegal span: %s", t));
ok = false;
}
}
for (Sentence s : select(aCas.getJCas(), Sentence.class)) {
if (s.getBegin() >= s.getEnd()) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Sentence with illegal span: %s", s));
ok = false;
}
}
return ok;
} catch (CASException e) {
log.error("Unabled to access JCas", e);
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unabled to access JCas", e.getMessage()));
return false;
}
}
use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage 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.diag.CasDoctor.LogMessage 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.diag.CasDoctor.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method createMessagesView.
private ListView<LogMessage> createMessagesView(IModel<LogMessageSet> aModel) {
return new ListView<LogMessage>("messages", PropertyModel.of(aModel, "messages")) {
private static final long serialVersionUID = 8957632000765128508L;
@Override
protected void populateItem(ListItem<LogMessage> aItem) {
IModel<LogMessage> msg = aItem.getModel();
aItem.add(new Label("level", PropertyModel.of(msg, "level")));
aItem.add(new Label("source", PropertyModel.of(msg, "source.simpleName")));
aItem.add(new Label("message", PropertyModel.of(msg, "message")));
}
};
}
Aggregations