Java Code Examples for com.optimaize.langdetect.i18n.LdLocale#fromString()

The following examples show how to use com.optimaize.langdetect.i18n.LdLocale#fromString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TechnicalLanguageDetectorImplTest.java    From language-detector with Apache License 2.0 6 votes vote down vote up
private LanguageDetector makeDetector() {
    //building exactly like the old detector behaved.
    LanguageDetectorBuilder detectorBuilder = LanguageDetectorBuilder.create(NgramExtractor.gramLengths(1))
            .affixFactor(1.0)
            .shortTextAlgorithm(0);

    LanguageProfileBuilder profileBuilder = new LanguageProfileBuilder(LdLocale.fromString("en"));
    add(detectorBuilder, profileBuilder, TRAINING_EN);

    profileBuilder = new LanguageProfileBuilder(LdLocale.fromString("fr"));
    add(detectorBuilder, profileBuilder, TRAINING_FR);

    profileBuilder = new LanguageProfileBuilder(LdLocale.fromString("ja"));
    add(detectorBuilder, profileBuilder, TRAINING_JA);

    return detectorBuilder.build();
}
 
Example 2
Source File: OldLangProfileConverter.java    From language-detector with Apache License 2.0 5 votes vote down vote up
public static LanguageProfile convert(LangProfile langProfile) {
    LdLocale locale;
    try {
        locale = LdLocale.fromString(langProfile.getName());
    } catch (Exception e) {
        throw new RuntimeException("Profile file name logic was changed in v0.5, please update your custom profiles!", e);
    }
    LanguageProfileBuilder builder = new LanguageProfileBuilder(locale);
    for (Map.Entry<String, Integer> entry : langProfile.getFreq().entrySet()) {
        builder.addGram(entry.getKey(), entry.getValue());
    }
    return builder.build();
}
 
Example 3
Source File: LanguageProfileReader.java    From language-detector with Apache License 2.0 5 votes vote down vote up
private boolean looksLikeLanguageProfileName(String fileName) {
    if (fileName.contains(".")) {
        return false;
    }
    try {
        LdLocale.fromString(fileName);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 4
Source File: DetectedLanguageTest.java    From language-detector with Apache License 2.0 5 votes vote down vote up
@Test
public final void basic() {
    DetectedLanguage lang = new DetectedLanguage(LdLocale.fromString("en"), 1.0);
    assertEquals(lang.getLocale().getLanguage(), "en");
    assertEquals(lang.getProbability(), 1.0, 0.0001);
    assertEquals(lang.toString(), "DetectedLanguage[en:1.0]");
}
 
Example 5
Source File: LanguageProfileBuilder.java    From language-detector with Apache License 2.0 4 votes vote down vote up
@Deprecated
public LanguageProfileBuilder(@NotNull String locale) {
    this.locale = LdLocale.fromString(locale);
}
 
Example 6
Source File: DetectedLanguageTest.java    From language-detector with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public final void invalidProbability() {
    new DetectedLanguage(LdLocale.fromString("en"), 1.1);
}