use of de.tudarmstadt.ukp.clarin.webanno.support.logging.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.support.logging.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.support.logging.LogMessage in project webanno by webanno.
the class RelationOffsetsRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
List<AnnotationFS> fixedRels = new ArrayList<>();
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())) {
fixedRels.add(rel);
setFeature(rel, CAS.FEATURE_BASE_NAME_BEGIN, target.getBegin());
setFeature(rel, CAS.FEATURE_BASE_NAME_END, target.getEnd());
}
}
// Delete those relations that pointed to deleted spans
if (!fixedRels.isEmpty()) {
aMessages.add(new LogMessage(this, LogLevel.INFO, "Fixed the offsets of [%d] relations in layer [" + layer.getName() + "].", fixedRels.size()));
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class RemoveZeroSizeTokensAndSentencesRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
for (AnnotationFS s : selectSentences(aCas)) {
if (s.getBegin() >= s.getEnd()) {
aCas.removeFsFromIndexes(s);
aMessages.add(new LogMessage(this, INFO, "Removed sentence with illegal span: %s", s));
}
}
for (AnnotationFS t : WebAnnoCasUtil.selectTokens(aCas)) {
if (t.getBegin() >= t.getEnd()) {
AnnotationFS lemma = FSUtil.getFeature(t, "lemma", AnnotationFS.class);
if (lemma != null) {
aCas.removeFsFromIndexes(lemma);
aMessages.add(new LogMessage(this, INFO, "Removed lemma attached to token with illegal span: %s", t));
}
AnnotationFS pos = FSUtil.getFeature(t, "pos", AnnotationFS.class);
if (pos != null) {
aCas.removeFsFromIndexes(pos);
aMessages.add(new LogMessage(this, INFO, "Removed POS attached to token with illegal span: %s", t));
}
AnnotationFS stem = FSUtil.getFeature(t, "stem", AnnotationFS.class);
if (stem != null) {
aCas.removeFsFromIndexes(stem);
aMessages.add(new LogMessage(this, INFO, "Removed stem attached to token with illegal span: %s", t));
}
aCas.removeFsFromIndexes(t);
aMessages.add(new LogMessage(this, INFO, "Removed token with illegal span: %s", t));
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class AllAnnotationsIndexedCheckTest method testFail.
@Test
public void testFail() throws Exception {
TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory().createTypeSystemDescription();
String refTypeName = "RefType";
TypeDescription refTypeDesc = tsd.addType(refTypeName, null, CAS.TYPE_NAME_ANNOTATION);
refTypeDesc.addFeature("ref", null, CAS.TYPE_NAME_ANNOTATION);
CAS cas = CasCreationUtils.createCas(tsd, null, null);
Type refType = cas.getTypeSystem().getType(refTypeName);
// A regular index annotation
AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
cas.addFsToIndexes(anno1);
// A non-index annotation but reachable through an indexe one (below)
AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
// An indexed annotation that references the non-indexed annotation above
AnnotationFS anno3 = cas.createAnnotation(refType, 0, 1);
anno3.setFeatureValue(refType.getFeatureByBaseName("ref"), anno2);
cas.addFsToIndexes(anno3);
List<LogMessage> messages = new ArrayList<>();
CasDoctor cd = new CasDoctor(AllFeatureStructuresIndexedCheck.class);
// A project is not required for this check
boolean result = cd.analyze(null, cas, messages);
messages.forEach(System.out::println);
assertFalse(result);
}
Aggregations