当前位置: 首页>>代码示例>>Java>>正文


Java LangProfile类代码示例

本文整理汇总了Java中com.cybozu.labs.langdetect.util.LangProfile的典型用法代码示例。如果您正苦于以下问题:Java LangProfile类的具体用法?Java LangProfile怎么用?Java LangProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LangProfile类属于com.cybozu.labs.langdetect.util包,在下文中一共展示了LangProfile类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadProfile

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
/**
 * Load profiles from specified directory.
 * This method must be called once before language detection.
 *
 * @param json_profiles all json-encoded profiles
 * @throws LangDetectException Can't open profiles(error code = {@link ErrorCode#FileLoadError})
 *                             or profile's format is wrong (error code = {@link ErrorCode#FormatError})
 */
public void loadProfile(final List<String> json_profiles) throws LangDetectException {
    final int langsize = json_profiles.size();
    if (langsize < 2)
        throw new LangDetectException(ErrorCode.NeedLoadProfileError, "Need more than 2 profiles");

    int index = 0;
    for (final String json : json_profiles) {
        try {
            final LangProfile profile = JSON.decode(json, LangProfile.class);
            addProfile(profile, index, langsize);
            ++index;
        } catch (JSONException e) {
            throw new LangDetectException(ErrorCode.FormatError, "profile format error");
        }
    }
}
 
开发者ID:malcolmgreaves,项目名称:language-detection,代码行数:25,代码来源:DetectorFactory.java

示例2: addProfile

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
/**
 * @param profile  profile
 * @param index    index
 * @param langsize language size
 * @throws LangDetectException if there's a problem
 */
public void addProfile(
        final LangProfile profile,
        final int index,
        final int langsize) throws LangDetectException {

    final String lang = profile.name;
    if (langlist.contains(lang)) {
        throw new LangDetectException(ErrorCode.DuplicateLangError, "duplicate the same language profile");
    }
    langlist.add(lang);

    for (final String word : profile.freq.keySet()) {
        if (!wordLangProbMap.containsKey(word)) {
            wordLangProbMap.put(word, new double[langsize]);
        }
        final int length = word.length();
        if (length >= 1 && length <= 3) {
            final double prob = profile.freq.get(word).doubleValue() / profile.n_words[length - 1];
            wordLangProbMap.get(word)[index] = prob;
        }
    }
}
 
开发者ID:malcolmgreaves,项目名称:language-detection,代码行数:29,代码来源:DetectorFactory.java

示例3: loadProfile

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:deezer,项目名称:weslang,代码行数:25,代码来源:DetectorFactory.java

示例4: addProfile

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
/**
 * @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;
        }
    }
}
 
开发者ID:deezer,项目名称:weslang,代码行数:24,代码来源:DetectorFactory.java

示例5: createLangProfile

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
@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;
}
 
开发者ID:spinscale,项目名称:elasticsearch-ingest-langdetect,代码行数:14,代码来源:SecureDetectorFactory.java

示例6: generateProfileFromText

import com.cybozu.labs.langdetect.util.LangProfile; //导入依赖的package包/类
/**
 * Generate Language Profile from Text File
 * <p>
 * <pre>
 * usage: --genprofile-text -l [language code] [text file path]
 * </pre>
 */
private void generateProfileFromText() {
    if (arglist.size() != 1) {
        System.err.println("Need to specify text file path");
        return;
    }
    File file = new File(arglist.get(0));
    if (!file.exists()) {
        System.err.println("Need to specify existing text file path");
        return;
    }

    String lang = get("lang");
    if (lang == null) {
        System.err.println("Need to specify langage code(-l)");
        return;
    }

    FileOutputStream os = null;
    try {
        LangProfile profile = GenProfile.loadFromText(lang, file);
        profile.omitLessFreq();

        File profile_path = new File(lang);
        os = new FileOutputStream(profile_path);
        JSON.encode(profile, os);
    } catch (JSONException | LangDetectException | IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (os != null) os.close();
        } catch (IOException ignored) {
        }
    }
}
 
开发者ID:malcolmgreaves,项目名称:language-detection,代码行数:42,代码来源:Command.java


注:本文中的com.cybozu.labs.langdetect.util.LangProfile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。