Search in sources :

Example 1 with DependencyParse

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

the class TcfReader method convertDependencies.

private void convertDependencies(JCas aJCas, TextCorpus aCorpusData, Map<String, Token> aTokens) {
    if (aCorpusData.getDependencyParsingLayer() == null) {
        // No layer to read from.
        return;
    }
    for (int i = 0; i < aCorpusData.getDependencyParsingLayer().size(); i++) {
        DependencyParse dependencyParse = aCorpusData.getDependencyParsingLayer().getParse(i);
        for (eu.clarin.weblicht.wlfxb.tc.api.Dependency dependency : dependencyParse.getDependencies()) {
            eu.clarin.weblicht.wlfxb.tc.api.Token[] governorTokens = aCorpusData.getDependencyParsingLayer().getGovernorTokens(dependency);
            eu.clarin.weblicht.wlfxb.tc.api.Token[] dependentTokens = aCorpusData.getDependencyParsingLayer().getDependentTokens(dependency);
            POS dependentPos = aTokens.get(dependentTokens[0].getID()).getPos();
            // as a default POS --
            if (dependentPos == null) {
                getUimaContext().getLogger().log(Level.INFO, "There is no pos for this token, added is -- as a pos");
                dependentPos = new POS(aJCas);
                dependentPos.setBegin(aTokens.get(dependentTokens[0].getID()).getBegin());
                dependentPos.setEnd(aTokens.get(dependentTokens[0].getID()).getEnd());
                dependentPos.setPosValue("--");
                dependentPos.addToIndexes();
                aTokens.get(dependentTokens[0].getID()).setPos(dependentPos);
            }
            if (governorTokens != null) {
                POS governerPos = aTokens.get(governorTokens[0].getID()).getPos();
                if (governerPos == null) {
                    if (dependency.getFunction().equals("ROOT")) {
                    // do nothing
                    } else {
                        getUimaContext().getLogger().log(Level.INFO, "There is no pos for this token, added is -- as a pos");
                        governerPos = new POS(aJCas);
                        governerPos.setBegin(aTokens.get(governorTokens[0].getID()).getBegin());
                        governerPos.setEnd(aTokens.get(governorTokens[0].getID()).getEnd());
                        governerPos.setPosValue("--");
                        governerPos.addToIndexes();
                        aTokens.get(governorTokens[0].getID()).setPos(governerPos);
                    }
                }
            } else {
                governorTokens = dependentTokens;
            }
            Dependency outDependency = new Dependency(aJCas);
            outDependency.setDependencyType(dependency.getFunction());
            outDependency.setGovernor(aTokens.get(governorTokens[0].getID()));
            outDependency.setDependent(dependency.getFunction().equals("ROOT") ? aTokens.get(governorTokens[0].getID()) : aTokens.get(dependentTokens[0].getID()));
            outDependency.setBegin(outDependency.getDependent().getBegin());
            outDependency.setEnd(outDependency.getDependent().getEnd());
            outDependency.addToIndexes();
        }
    }
}
Also used : DependencyParse(eu.clarin.weblicht.wlfxb.tc.api.DependencyParse) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)

Aggregations

POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)1 DependencyParse (eu.clarin.weblicht.wlfxb.tc.api.DependencyParse)1