Java Code Examples for com.cybozu.labs.langdetect.util.LangProfile

The following examples show how to use com.cybozu.labs.langdetect.util.LangProfile. These examples are extracted from open source projects. 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 Project: weslang   Source File: DetectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Load profiles from specified directory.
 * This method must be called once before language detection.
 *
 * @param profileDirectory profile directory path
 * @throws LangDetectException  Can't open profiles(error code = {@link ErrorCode#FileLoadError})
 *                              or profile's format is wrong (error code = {@link ErrorCode#FormatError})
 */
public static void loadProfile(List<String> json_profiles) throws LangDetectException {
    int index = 0;
    int langsize = json_profiles.size();
    if (langsize < 2)
        throw new LangDetectException(ErrorCode.NeedLoadProfileError, "Need more than 2 profiles");

    for (String json: json_profiles) {
        try {
            LangProfile profile = JSON.decode(json, LangProfile.class);
            addProfile(profile, index, langsize);
            ++index;
        } catch (JSONException e) {
            throw new LangDetectException(ErrorCode.FormatError, "profile format error");
        }
    }
}
 
Example 2
Source Project: weslang   Source File: DetectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param profile
 * @param langsize
 * @param index
 * @throws LangDetectException
 */
static /* package scope */ void addProfile(LangProfile profile, int index, int langsize) throws LangDetectException {
    String lang = profile.name;
    if (instance_.langlist.contains(lang)) {
        throw new LangDetectException(ErrorCode.DuplicateLangError, "duplicate the same language profile");
    }
    instance_.langlist.add(lang);
    for (String word: profile.freq.keySet()) {
        if (!instance_.wordLangProbMap.containsKey(word)) {
            instance_.wordLangProbMap.put(word, new double[langsize]);
        }
        int length = word.length();
        if (length >= 1 && length <= 3) {
            double prob = profile.freq.get(word).doubleValue() / profile.n_words[length - 1];
            instance_.wordLangProbMap.get(word)[index] = prob;
        }
    }
}
 
Example 3
@SuppressWarnings("unchecked")
private static LangProfile createLangProfile(Map<String, Object> data) {
    LangProfile langProfile = new LangProfile();
    List<Integer> nWords = (List<Integer>) data.get("n_words");
    langProfile.n_words = new int[nWords.size()];
    for(int i = 0;i < langProfile.n_words.length;i++)
        langProfile.n_words[i] = nWords.get(i);

    langProfile.name = (String) data.get("name");
    langProfile.freq = (HashMap<String, Integer>) data.get("freq");

    return langProfile;
}
 
Example 4
Source Project: language-detection   Source File: DetectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static void loadProfile(List<LangProfile> profiles) {
  int index = 0;
  int langsize = profiles.size();
  for (LangProfile profile: profiles) {
    addProfile(profile, index, langsize);
    ++index;
  }

}
 
Example 5
Source Project: language-detection   Source File: DetectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param profile
 * @param langsize 
 * @param index 
 * @throws LangDetectException 
 */
static /* package scope */ void addProfile(LangProfile profile, int index, int langsize) {
    String lang = profile.name;
    instance_.langlist.add(lang);
    for (String word: profile.freq.keySet()) {
        if (!instance_.wordLangProbMap.containsKey(word)) {
            instance_.wordLangProbMap.put(word, new double[langsize]);
        }
        int length = word.length();
        if (length >= 1 && length <= 3) {
            double prob = profile.freq.get(word).doubleValue() / profile.n_words[length - 1];
            instance_.wordLangProbMap.get(word)[index] = prob;
        }
    }
}
 
Example 6
Source Project: language-detection   Source File: HR.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 7
Source Project: language-detection   Source File: SW.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 8
Source Project: language-detection   Source File: ES.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 9
Source Project: language-detection   Source File: YI.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 10
Source Project: language-detection   Source File: HI.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 11
Source Project: language-detection   Source File: BG.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 12
Source Project: language-detection   Source File: LT.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 13
Source Project: language-detection   Source File: JA.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 14
Source Project: language-detection   Source File: AF.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 15
Source Project: language-detection   Source File: AR.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 16
Source Project: language-detection   Source File: SK.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 17
Source Project: language-detection   Source File: ZHTW.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 18
Source Project: language-detection   Source File: GA.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 19
Source Project: language-detection   Source File: FA.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 20
Source Project: language-detection   Source File: AN.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 21
Source Project: language-detection   Source File: TR.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 22
Source Project: language-detection   Source File: PA.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 23
Source Project: language-detection   Source File: UK.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 24
Source Project: language-detection   Source File: SV.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 25
Source Project: language-detection   Source File: BR.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 26
Source Project: language-detection   Source File: TA.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 27
Source Project: language-detection   Source File: MK.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 28
Source Project: language-detection   Source File: CS.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 29
Source Project: language-detection   Source File: NE.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example 30
Source Project: language-detection   Source File: TE.java    License: Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}