use of zemberek.morphology.analysis.AnalysisDebugData in project zemberek-nlp by ahmetaa.
the class WordGenerator method generate.
private List<Result> generate(String input, List<StemTransition> candidates, List<Morpheme> morphemes) {
if (debugMode) {
debugData = new AnalysisDebugData();
debugData.input = input;
debugData.candidateStemTransitions.addAll(candidates);
}
// generate initial search paths.
List<GenerationPath> paths = new ArrayList<>();
for (StemTransition candidate : candidates) {
// we set the tail as " " because in morphotactics, some conditions look for tail's size
// during graph walk. Because this is generation we let that condition pass always.
SearchPath searchPath = SearchPath.initialPath(candidate, " ");
List<Morpheme> morphemesInPath;
// we skip it if it matches with the initial morpheme of the graph visiting SearchPath object.
if (morphemes.size() > 0) {
if (morphemes.get(0).equals(searchPath.getCurrentState().morpheme)) {
morphemesInPath = morphemes.subList(1, morphemes.size());
} else {
morphemesInPath = new ArrayList<>(morphemes);
}
} else {
morphemesInPath = new ArrayList<>(0);
}
paths.add(new GenerationPath(searchPath, morphemesInPath));
}
// search graph.
List<GenerationPath> resultPaths = search(paths);
// generate results from successful paths.
List<Result> result = new ArrayList<>(resultPaths.size());
for (GenerationPath path : resultPaths) {
SingleAnalysis analysis = SingleAnalysis.fromSearchPath(path.path);
result.add(new Result(analysis.surfaceForm(), analysis));
if (debugMode) {
debugData.results.add(analysis);
}
}
return result;
}
Aggregations