Search in sources :

Example 1 with MorphemeSurface

use of zemberek.morphology._analyzer._SingleAnalysis.MorphemeSurface in project zemberek-nlp by ahmetaa.

the class _SingleAnalysis method fromSearchPath.

// Here we generate a _SingleAnalysis from a search path.
public static _SingleAnalysis fromSearchPath(SearchPath searchPath) {
    List<MorphemeSurface> morphemes = new ArrayList<>(searchPath.transitions.size());
    int derivationCount = 0;
    for (SurfaceTransition transition : searchPath.getTransitions()) {
        if (transition.isDerivative()) {
            derivationCount++;
        }
        Morpheme morpheme = transition.getMorpheme();
        // if empty, use the cache.
        if (transition.surface.isEmpty()) {
            MorphemeSurface suffixSurface = emptyMorphemeCache.get(morpheme);
            if (suffixSurface == null) {
                suffixSurface = new MorphemeSurface(morpheme, "");
                emptyMorphemeCache.put(morpheme, suffixSurface);
            }
            morphemes.add(suffixSurface);
            continue;
        }
        MorphemeSurface suffixSurface = new MorphemeSurface(morpheme, transition.surface);
        morphemes.add(suffixSurface);
    }
    int[] groupBoundaries = new int[derivationCount + 1];
    // we assume there is always an IG
    groupBoundaries[0] = 0;
    int morphemeCounter = 0, derivationCounter = 1;
    for (SurfaceTransition transition : searchPath.getTransitions()) {
        if (transition.isDerivative()) {
            groupBoundaries[derivationCounter] = morphemeCounter;
            derivationCounter++;
        }
        morphemeCounter++;
    }
    return new _SingleAnalysis(searchPath.getDictionaryItem(), morphemes, groupBoundaries);
}
Also used : Morpheme(zemberek.morphology._morphotactics.Morpheme) ArrayList(java.util.ArrayList)

Example 2 with MorphemeSurface

use of zemberek.morphology._analyzer._SingleAnalysis.MorphemeSurface in project zemberek-nlp by ahmetaa.

the class AnalyzerTestBase method lastMorphemeIs.

boolean lastMorphemeIs(_SingleAnalysis result, String morphemeName) {
    List<MorphemeSurface> morphemes = result.getMorphemesSurfaces();
    if (morphemes.size() == 0) {
        return false;
    }
    MorphemeSurface last = morphemes.get(morphemes.size() - 1);
    return last.morpheme.id.equalsIgnoreCase(morphemeName);
}
Also used : MorphemeSurface(zemberek.morphology._analyzer._SingleAnalysis.MorphemeSurface)

Aggregations

ArrayList (java.util.ArrayList)1 MorphemeSurface (zemberek.morphology._analyzer._SingleAnalysis.MorphemeSurface)1 Morpheme (zemberek.morphology._morphotactics.Morpheme)1