Search in sources :

Example 1 with NamedEntitiesLayer

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

the class TcfWriter method writeNamedEntity.

private void writeNamedEntity(JCas aJCas, TextCorpus aTextCorpus, Map<Integer, eu.clarin.weblicht.wlfxb.tc.api.Token> aTokensBeginPositionMap) {
    if (!JCasUtil.exists(aJCas, NamedEntity.class)) {
        // Do nothing if there are no named entities in the CAS
        getLogger().debug("Layer [" + TextCorpusLayerTag.NAMED_ENTITIES.getXmlName() + "]: empty");
        return;
    }
    String tagSetName = "BART";
    for (TagsetDescription tagSet : select(aJCas, TagsetDescription.class)) {
        if (tagSet.getLayer().equals(NamedEntity.class.getName())) {
            tagSetName = tagSet.getName();
            break;
        }
    }
    NamedEntitiesLayer namedEntitiesLayer = aTextCorpus.createNamedEntitiesLayer(tagSetName);
    getLogger().debug("Layer [" + TextCorpusLayerTag.NAMED_ENTITIES.getXmlName() + "]: created");
    for (NamedEntity namedEntity : select(aJCas, NamedEntity.class)) {
        List<Token> tokensInCas = selectCovered(aJCas, Token.class, namedEntity.getBegin(), namedEntity.getEnd());
        List<eu.clarin.weblicht.wlfxb.tc.api.Token> tokensInTcf = new ArrayList<>();
        for (Token token : tokensInCas) {
            tokensInTcf.add(aTokensBeginPositionMap.get(token.getBegin()));
        }
        namedEntitiesLayer.addEntity(namedEntity.getValue(), tokensInTcf);
    }
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) NamedEntitiesLayer(eu.clarin.weblicht.wlfxb.tc.api.NamedEntitiesLayer) ArrayList(java.util.ArrayList) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) TagsetDescription(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.TagsetDescription)

Aggregations

TagsetDescription (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.TagsetDescription)1 NamedEntity (de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 NamedEntitiesLayer (eu.clarin.weblicht.wlfxb.tc.api.NamedEntitiesLayer)1 ArrayList (java.util.ArrayList)1