use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method actionRepair.
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
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)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.repair(project, initialCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(initialCas, documentService.getCasFile(sd, INITIAL_CAS_PSEUDO_USER));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.repair(project, userCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method actionCheck.
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setCheckClasses(CasDoctor.scanChecks());
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
try {
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "No initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.analyze(project, initialCas.getCas(), messageSet.messages);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error reading initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error reading initial CAS for [" + sd.getName() + "]", e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage 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.diag.CasDoctor.LogMessage 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.diag.CasDoctor.LogMessage in project webanno by webanno.
the class ReindexFeatureAttachedSpanAnnotationsRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
Map<FeatureStructure, FeatureStructure> nonIndexed = getNonIndexedFSesWithOwner(aCas);
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
int count = 0;
// anno -> e.g. Lemma
for (AnnotationFS attach : select(aCas, getType(aCas, layer.getAttachType().getName()))) {
AnnotationFS anno = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
if (anno != null && nonIndexed.containsKey(anno)) {
aCas.addFsToIndexes(anno);
count++;
}
}
if (count > 0) {
aMessages.add(new LogMessage(this, LogLevel.INFO, "Reindexed [%d] unindexed spans in layer [" + layer.getName() + "].", count));
}
}
}
Aggregations