Search in sources :

Example 1 with Reference

use of eu.clarin.weblicht.wlfxb.tc.api.Reference in project webanno by webanno.

the class TcfReader method storeReferencesAndTargetsInMap.

private void storeReferencesAndTargetsInMap(Map<Integer, CoreferenceLink> aReferencesMap, eu.clarin.weblicht.wlfxb.tc.api.ReferencedEntity entity, TextCorpus aCorpusData, Map<String, Token> aTokens, JCas aJcas) {
    for (Reference reference : entity.getReferences()) {
        StringBuilder sbTokens = new StringBuilder();
        for (eu.clarin.weblicht.wlfxb.tc.api.Token token : aCorpusData.getReferencesLayer().getTokens(reference)) {
            sbTokens.append(token.getID()).append(" ");
        }
        String[] referenceTokens = sbTokens.toString().split(" ");
        int begin = getOffsets(referenceTokens, aTokens)[0];
        int end = getOffsets(referenceTokens, aTokens)[1];
        CoreferenceLink link = new CoreferenceLink(aJcas);
        link.setBegin(begin);
        link.setEnd(end);
        String referencesType = reference.getType() == null ? "nam" : reference.getType();
        link.setReferenceType(referencesType);
        if (reference.getRelation() != null) {
            link.setReferenceRelation(reference.getRelation());
        }
        link.addToIndexes();
        aReferencesMap.put(aJcas.getCasImpl().ll_getFSRef(link), link);
    }
}
Also used : Reference(eu.clarin.weblicht.wlfxb.tc.api.Reference) CoreferenceLink(de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceLink)

Example 2 with Reference

use of eu.clarin.weblicht.wlfxb.tc.api.Reference 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);
    }
}
Also used : CoreferenceChain(de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceChain) Reference(eu.clarin.weblicht.wlfxb.tc.api.Reference) ArrayList(java.util.ArrayList) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) TagsetDescription(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.TagsetDescription) CoreferenceLink(de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceLink) ReferencesLayer(eu.clarin.weblicht.wlfxb.tc.api.ReferencesLayer)

Aggregations

CoreferenceLink (de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceLink)2 Reference (eu.clarin.weblicht.wlfxb.tc.api.Reference)2 CoreferenceChain (de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceChain)1 TagsetDescription (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.TagsetDescription)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 ReferencesLayer (eu.clarin.weblicht.wlfxb.tc.api.ReferencesLayer)1 ArrayList (java.util.ArrayList)1