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);
}
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);
}
Aggregations