optimaize / language-detector

Language Detection Library for Java
Apache License 2.0
569 stars 165 forks source link

Better Android support #13

Open fabiankessler opened 10 years ago

fabiankessler commented 10 years ago

As done here https://github.com/rmtheis/language-detection

danielgomezrico commented 9 years ago

Just tried 0.5 on android 'com.optimaize.languagedetector:language-detector:0.5'

I get Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.Character$UnicodeScript"when I try to recognize with

    public class Translator {

    private LanguageDetector languageDetector;

    public Translator() {
        try {
            List<LanguageProfile> languageProfiles = new LanguageProfileReader().readAllBuiltIn();
            languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
                    .withProfiles(languageProfiles)
                    .build();
        } catch (IOException e) {
            Log.e("AAA", "ERROR", e);
        }
    }

    public LdLocale recognize(String text) {
        TextObjectFactory textObjectFactory = text.length() > 10 ? forDetectingOnLargeText() : forIndexingCleanText();
        Optional<LdLocale> locale = languageDetector.detect(textObjectFactory.forText(text));
        return locale.isPresent() ? locale.get() : null;
    }
}

translator = new Translator();
translate.recognize("this is a text really big that I am trying to write")

@fabiankessler You know why?

epfisztner commented 8 years ago

@danielgomezrico because on android the Character.UnicodeScript doesn't exist, but the RemoveMinorityScriptsTextFilter uses this class.

eclectice commented 8 years ago

@epfisztner @caipivara Character.UnicodeScript has recently been added into Android API 24

https://developer.android.com/reference/java/lang/Character.UnicodeScript.html