19 package org.sleuthkit.autopsy.keywordsearch;
21 import com.optimaize.langdetect.LanguageDetectorBuilder;
22 import com.optimaize.langdetect.i18n.LdLocale;
23 import com.optimaize.langdetect.ngram.NgramExtractors;
24 import com.optimaize.langdetect.profiles.LanguageProfileReader;
25 import com.optimaize.langdetect.text.CommonTextObjectFactories;
26 import com.optimaize.langdetect.text.TextObject;
27 import com.optimaize.langdetect.text.TextObjectFactory;
29 import java.io.IOException;
30 import java.io.UncheckedIOException;
31 import java.util.Optional;
37 class LanguageDetector {
39 private com.optimaize.langdetect.LanguageDetector impl;
40 private TextObjectFactory textObjectFactory;
44 impl = LanguageDetectorBuilder.create(NgramExtractors.standard())
45 .withProfiles(
new LanguageProfileReader().readAllBuiltIn())
47 textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
48 }
catch (IOException e) {
51 throw new UncheckedIOException(e);
55 Optional<Language> detect(String text) {
56 TextObject textObject = textObjectFactory.forText(text);
57 Optional<LdLocale> localeOpt = impl.detect(textObject).transform(Optional::of).or(Optional.empty());
static Optional< Language > fromValue(String value)