use of eu.clarin.weblicht.wlfxb.tc.api.ReferencesLayer in project webanno by webanno.
the class TcfWriter method writeCoreference.
private void writeCoreference(JCas aJCas, TextCorpus aTextCorpus, Map<Integer, eu.clarin.weblicht.wlfxb.tc.api.Token> aTokensBeginPositionMap) {
if (!JCasUtil.exists(aJCas, CoreferenceChain.class)) {
// Do nothing if there are no coreference chains in the CAS
getLogger().debug("Layer [" + TextCorpusLayerTag.REFERENCES.getXmlName() + "]: empty");
return;
}
String tagSetName = "TueBaDz";
for (TagsetDescription tagSet : select(aJCas, TagsetDescription.class)) {
if (tagSet.getLayer().equals(CoreferenceLink.class.getName())) {
tagSetName = tagSet.getName();
break;
}
}
ReferencesLayer coreferencesLayer = aTextCorpus.createReferencesLayer(null, tagSetName, null);
getLogger().debug("Layer [" + TextCorpusLayerTag.REFERENCES.getXmlName() + "]: created");
for (CoreferenceChain chain : select(aJCas, CoreferenceChain.class)) {
CoreferenceLink prevLink = null;
Reference prevRef = null;
List<Reference> refs = new ArrayList<>();
for (CoreferenceLink link : chain.links()) {
// Get covered tokens
List<eu.clarin.weblicht.wlfxb.tc.api.Token> tokens = new ArrayList<>();
for (Token token : selectCovered(Token.class, link)) {
tokens.add(aTokensBeginPositionMap.get(token.getBegin()));
}
// Create current reference
Reference ref = coreferencesLayer.createReference(link.getReferenceType(), tokens, null);
// Special handling for expletive relations
if (REL_TYPE_EXPLETIVE.equals(link.getReferenceRelation())) {
coreferencesLayer.addRelation(ref, REL_TYPE_EXPLETIVE);
// chain, so we bail out here.
continue;
}
// Create relation between previous and current reference
if (prevLink != null) {
coreferencesLayer.addRelation(prevRef, prevLink.getReferenceRelation(), ref);
}
prevLink = link;
prevRef = ref;
refs.add(ref);
}
coreferencesLayer.addReferent(refs);
}
}
Aggregations