use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class DanglingRelationsCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
boolean ok = true;
for (AnnotationFS fs : aCas.getAnnotationIndex()) {
Type t = fs.getType();
Feature sourceFeat = t.getFeatureByBaseName(FEAT_REL_SOURCE);
Feature targetFeat = t.getFeatureByBaseName(FEAT_REL_TARGET);
// Is this a relation?
if (!(sourceFeat != null && targetFeat != null)) {
continue;
}
RelationAdapter relationAdapter = (RelationAdapter) annotationService.findAdapter(aProject, fs);
Feature relationSourceAttachFeature = null;
Feature relationTargetAttachFeature = null;
if (relationAdapter.getAttachFeatureName() != null) {
relationSourceAttachFeature = sourceFeat.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
relationTargetAttachFeature = targetFeat.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
}
FeatureStructure source = fs.getFeatureValue(sourceFeat);
FeatureStructure target = fs.getFeatureValue(targetFeat);
// Here we get the annotations that the relation is pointing to in the UI
if (source != null && relationSourceAttachFeature != null) {
source = (AnnotationFS) source.getFeatureValue(relationSourceAttachFeature);
}
if (target != null && relationTargetAttachFeature != null) {
target = (AnnotationFS) target.getFeatureValue(relationTargetAttachFeature);
}
// Does it have null endpoints?
if (source == null || target == null) {
StringBuilder message = new StringBuilder();
message.append("Relation [" + relationAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot identify attached annotations.");
if (relationAdapter.getAttachFeatureName() != null) {
message.append("\nRelation [" + relationAdapter.getLayer().getName() + "] attached to feature [" + relationAdapter.getAttachFeatureName() + "].");
}
message.append("\nSource: " + source);
message.append("\nTarget: " + target);
aMessages.add(new LogMessage(this, INFO, "%s", message));
ok = false;
}
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.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;
int count = 0;
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
Type layerType;
Type attachType;
try {
layerType = getAnnotationType(aCas, layer.getName());
attachType = getAnnotationType(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 (!anno.equals(candidate)) {
if (count < 100) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Annotation should be attached to [" + layer.getAttachFeature().getName() + "] but is not.\nAnnotation: [" + anno + "]\nAttach annotation:[" + attach + "]"));
}
count++;
ok = false;
}
}
}
}
if (count >= 100) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "In total [%d] annotations were not properly attached", count));
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class NoZeroSizeTokensAndSentencesCheck method check.
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
boolean ok = true;
for (AnnotationFS t : selectTokens(aCas)) {
if (t.getBegin() >= t.getEnd()) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Token with illegal span: %s", t));
ok = false;
}
}
for (AnnotationFS s : selectSentences(aCas)) {
if (s.getBegin() >= s.getEnd()) {
aMessages.add(new LogMessage(this, LogLevel.ERROR, "Sentence with illegal span: %s", s));
ok = false;
}
}
return ok;
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.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")));
aItem.add(new Label("message", PropertyModel.of(msg, "message")));
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method actionRepair.
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setRepairClasses(formModel.repairs);
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
// Repair INITIAL CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
try {
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error repairing initial CAS for [{}]", sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair CORRECTION_USER CAS if necessary
if (PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CORRECTION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CORRECTION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (FileNotFoundException e) {
// If there is no CAS for the correction user, then correction has not started
// yet. This is not a problem, so we can ignore it. (REC: I wonder if this
// assumption is correct in curation mode...)
messageSet.messages.add(LogMessage.info(getClass(), "Correction seems to have not yet started."));
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CORRECTION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CORRECTION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair CURATION_USER CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CURATION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CURATION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (FileNotFoundException e) {
if (asList(CURATION_IN_PROGRESS, CURATION_FINISHED).contains(sd.getState())) {
messageSet.messages.add(LogMessage.error(getClass(), "Curation CAS missing."));
} else {
// If there is no CAS for the curation user, then curation has not started
// yet. This is not a problem, so we can ignore it.
messageSet.messages.add(LogMessage.info(getClass(), "Curation has not started."));
}
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CURATION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CURATION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair regular annotator CASes
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
try {
casStorageService.forceActionOnCas(sd, ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error repairing annotations of user [{}] for [{}]", ad.getUser(), sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
Aggregations