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

The following examples show how to use com.cybozu.labs.langdetect.util.LangProfile. 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: DetectorFactory.java    From weslang with 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 File: DetectorFactory.java    From weslang with 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
Source File: SecureDetectorFactory.java    From elasticsearch-ingest-langdetect with Apache License 2.0 5 votes vote down vote up
@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 File: DetectorFactory.java    From language-detection with 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 File: DetectorFactory.java    From language-detection with 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 File: FR.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #7
Source File: SO.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #8
Source File: ET.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #9
Source File: EN.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #10
Source File: LV.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #11
Source File: SQ.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #12
Source File: OC.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #13
Source File: BE.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #14
Source File: SR.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #15
Source File: ID.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #16
Source File: SW.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #17
Source File: HR.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #18
Source File: FI.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #19
Source File: KN.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #20
Source File: VI.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #21
Source File: NL.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #22
Source File: HE.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #23
Source File: PT.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #24
Source File: DA.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #25
Source File: AST.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #26
Source File: SL.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #27
Source File: HU.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #28
Source File: CA.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #29
Source File: TH.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}
 
Example #30
Source File: CY.java    From language-detection with Apache License 2.0 4 votes vote down vote up
public final LangProfile getLangProfile() {
  return new LangProfile(name, freq, n_words);
}