use of org.apache.tika.language.detect.LanguageResult in project tika by apache.
the class Language method languageDetection.
public static void languageDetection() throws IOException {
LanguageDetector detector = new OptimaizeLangDetector().loadModels();
LanguageResult result = detector.detect("Alla människor är födda fria och lika i värde och rättigheter.");
System.out.println(result.getLanguage());
}
use of org.apache.tika.language.detect.LanguageResult in project tika by apache.
the class Language method languageDetectionWithHandler.
public static void languageDetectionWithHandler() throws Exception {
LanguageHandler handler = new LanguageHandler();
new AutoDetectParser().parse(System.in, handler, new Metadata(), new ParseContext());
LanguageResult result = handler.getLanguage();
System.out.println(result.getLanguage());
}
use of org.apache.tika.language.detect.LanguageResult in project tika by apache.
the class LanguageDetectorExample method detectLanguage.
public String detectLanguage(String text) throws IOException {
LanguageDetector detector = new OptimaizeLangDetector().loadModels();
LanguageResult result = detector.detect(text);
return result.getLanguage();
}
use of org.apache.tika.language.detect.LanguageResult in project tika by apache.
the class Lingo24LangDetector method detectAll.
@Override
public List<LanguageResult> detectAll() {
List<LanguageResult> result = new ArrayList<>();
String language = detect(writer.toString());
if (language != null) {
result.add(new LanguageResult(language, LanguageConfidence.MEDIUM, 1));
} else {
result.add(new LanguageResult(language, LanguageConfidence.NONE, 0));
}
return result;
}
use of org.apache.tika.language.detect.LanguageResult in project tika by apache.
the class OptimaizeLangDetector method detectAll.
@Override
public List<LanguageResult> detectAll() {
// TODO throw exception if models haven't been loaded, or auto-load all?
List<LanguageResult> result = new ArrayList<>();
List<DetectedLanguage> rawResults = detector.getProbabilities(writer.toString());
for (DetectedLanguage rawResult : rawResults) {
// TODO figure out right level for confidence brackets.
LanguageConfidence confidence = rawResult.getProbability() > 0.9 ? LanguageConfidence.HIGH : LanguageConfidence.MEDIUM;
result.add(new LanguageResult(makeLanguageName(rawResult.getLocale()), confidence, (float) rawResult.getProbability()));
}
if (result.isEmpty()) {
result.add(LanguageResult.NULL);
}
return result;
}
Aggregations