Search in sources :

Example 1 with AnalysisDebugData

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;
}
Also used : SingleAnalysis(zemberek.morphology.analysis.SingleAnalysis) AnalysisDebugData(zemberek.morphology.analysis.AnalysisDebugData) StemTransition(zemberek.morphology.morphotactics.StemTransition) Morpheme(zemberek.morphology.morphotactics.Morpheme) ArrayList(java.util.ArrayList) SearchPath(zemberek.morphology.analysis.SearchPath)

Aggregations

ArrayList (java.util.ArrayList)1 AnalysisDebugData (zemberek.morphology.analysis.AnalysisDebugData)1 SearchPath (zemberek.morphology.analysis.SearchPath)1 SingleAnalysis (zemberek.morphology.analysis.SingleAnalysis)1 Morpheme (zemberek.morphology.morphotactics.Morpheme)1 StemTransition (zemberek.morphology.morphotactics.StemTransition)1