use of zemberek.morphology.TurkishMorphology.Builder in project zemberek-nlp by ahmetaa.
the class MorphologyConsole method run.
@Override
public void run() {
Builder b = TurkishMorphology.builder().setLexicon(RootLexicon.getDefault());
if (disableUnknownAnalysis) {
b.disableUnidentifiedTokenAnalyzer();
}
if (enableInformalWordAnalysis) {
b.useInformalAnalysis();
}
TurkishMorphology morphology = b.build();
String input;
System.out.println("Enter word or sentence. Type `quit` or `Ctrl+C` to exit.:");
Scanner sc = new Scanner(System.in);
input = sc.nextLine();
while (!input.equals("quit")) {
if (input.trim().length() == 0) {
System.out.println("Empty line cannot be processed.");
input = sc.nextLine();
continue;
}
SentenceAnalysis analysis = morphology.analyzeAndDisambiguate(input);
System.out.format("%nS:%s%n", input);
for (SentenceWordAnalysis sw : analysis) {
WordAnalysis wa = sw.getWordAnalysis();
System.out.println(wa.getInput());
SingleAnalysis best = sw.getBestAnalysis();
for (SingleAnalysis singleAnalysis : wa) {
boolean isBest = singleAnalysis.equals(best);
if (wa.analysisCount() == 1) {
System.out.println(singleAnalysis.formatLong());
} else {
System.out.format("%s%s%n", singleAnalysis.formatLong(), isBest ? "*" : "");
}
}
}
System.out.println();
input = sc.nextLine();
}
}
Aggregations