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


Java Detector.getProbabilities方法代码示例

本文整理汇总了Java中com.cybozu.labs.langdetect.Detector.getProbabilities方法的典型用法代码示例。如果您正苦于以下问题:Java Detector.getProbabilities方法的具体用法?Java Detector.getProbabilities怎么用?Java Detector.getProbabilities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cybozu.labs.langdetect.Detector的用法示例。


在下文中一共展示了Detector.getProbabilities方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: detectLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
@Override
protected List<DetectedLanguage> detectLanguage(String content) {
    List<DetectedLanguage> detectedLanguages = Lists.newArrayList();
    if (StringUtils.isEmpty(content)) {
        return detectedLanguages;
    }
    try {
        Detector detector = DetectorFactory.create();
        detector.append(content);
        ArrayList<Language> languages = detector.getProbabilities();
        for (Language language : languages) {
            detectedLanguages.add(new DetectedLanguage(language.lang, language.prob));
        }
    } catch (LangDetectException e) {
    }
    return detectedLanguages;
}
 
开发者ID:smalldirector,项目名称:solr-multilingual-analyzer,代码行数:18,代码来源:MultiLangDetectLanguageIdentifierUpdateProcessor.java

示例2: detectLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
private List<DetectedLanguage> detectLanguage(String content) {
	if (content.trim().length() == 0) { // to be consistent with the tika impl?
		log.debug("No input text to detect language from, returning empty list");
		return Collections.emptyList();
	}

	try {
		Detector detector = DetectorFactory.create();
		detector.append(content);
		ArrayList<Language> langlist = detector.getProbabilities();
		ArrayList<DetectedLanguage> solrLangList = new ArrayList<>();
		for (Language l: langlist) 
		{
			if((autoDetectQueryLocales.size() == 0) || (autoDetectQueryLocales.contains(l.lang)))
			{
			    solrLangList.add(new DetectedLanguage(l.lang, l.prob));
			}
		}
		return solrLangList;
	} catch (LangDetectException e) {
		log.debug("Could not determine language, returning empty list: ", e);
		return Collections.emptyList();
	}
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:25,代码来源:AbstractQParser.java

示例3: detect

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
@Override
public DetectionResult detect(String text) {
  Detector detector;
  try {
    detector = DetectorFactory.create();
  } catch (LangDetectException e) {
    // TODO(skreft): log the reason
    return UNKNOWN;
  }

  detector.append(text);
  List<Language> results = detector.getProbabilities();
  if (!results.isEmpty()) {
    Language bestLang = results.get(0);
    return new DetectionResult(bestLang.lang, bestLang.prob);
  }

  return UNKNOWN;
}
 
开发者ID:deezer,项目名称:weslang,代码行数:20,代码来源:DetectionServiceImplLanguageDetection.java

示例4: detectLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
@Override
protected List<DetectedLanguage> detectLanguage(String content) {
  if (content.trim().length() == 0) { // to be consistent with the tika impl?
    log.debug("No input text to detect language from, returning empty list");
    return Collections.emptyList();
  }
  
  try {
    Detector detector = DetectorFactory.create();
    detector.append(content);
    ArrayList<Language> langlist = detector.getProbabilities();
    ArrayList<DetectedLanguage> solrLangList = new ArrayList<DetectedLanguage>();
    for (Language l: langlist) {
      solrLangList.add(new DetectedLanguage(l.lang, l.prob));
    }
    return solrLangList;
  } catch (LangDetectException e) {
    log.debug("Could not determine language, returning empty list: ", e);
    return Collections.emptyList();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:22,代码来源:LangDetectLanguageIdentifierUpdateProcessor.java

示例5: identifyLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
@Override
public String identifyLanguage(String html)
        throws IOException
{
    // extracting plain html text
    Document doc = Jsoup.parse(html);
    String text = doc.text();

    // we might have removed everything -> no lang
    if (text.isEmpty()) {
        return UNKNOWN_LANGUAGE;
    }

    try {
        Detector detector = DetectorFactory.create();
        detector.append(text);
        String detectedLang = detector.detect();

        ArrayList<Language> detectedProbabilities = detector.getProbabilities();

        if (detectedProbabilities.get(0).prob > PROBABILITY_THRESHOLD) {
            return detectedLang;
        }
        else {
            return UNKNOWN_LANGUAGE;
        }
    }
    catch (LangDetectException e) {
        return UNKNOWN_LANGUAGE;
    }
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:32,代码来源:CybozuLanguageIdentifier.java

示例6: detectLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
@Override
protected List<DetectedLanguage> detectLanguage(SolrInputDocument doc) {
  try {
    Detector detector = DetectorFactory.create();
    detector.setMaxTextLength(maxTotalChars);

    for (String fieldName : inputFields) {
      log.debug("Appending field " + fieldName);
      if (doc.containsKey(fieldName)) {
        Collection<Object> fieldValues = doc.getFieldValues(fieldName);
        if (fieldValues != null) {
          for (Object content : fieldValues) {
            if (content instanceof String) {
              String stringContent = (String) content;
              if (stringContent.length() > maxFieldValueChars) {
                detector.append(stringContent.substring(0, maxFieldValueChars));
              } else {
                detector.append(stringContent);
              }
              detector.append(" ");
            } else {
              log.warn("Field " + fieldName + " not a String value, not including in detection");
            }
          }
        }
      }
    }
    ArrayList<Language> langlist = detector.getProbabilities();
    ArrayList<DetectedLanguage> solrLangList = new ArrayList<>();
    for (Language l: langlist) {
      solrLangList.add(new DetectedLanguage(l.lang, l.prob));
    }
    return solrLangList;
  } catch (LangDetectException e) {
    log.debug("Could not determine language, returning empty list: ", e);
    return Collections.emptyList();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:LangDetectLanguageIdentifierUpdateProcessor.java

示例7: isEnglish

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
/**
 * Try to detect the language of the text in the String.
 * 
 * @param page
 * @return true if the String contains English language, false otherwise
 */
public Boolean isEnglish(String content) {
    try {

        if (content == null || content.isEmpty()) {
            return false;
        }

        Detector detector = DetectorFactory.create();
        detector.append(content);
        ArrayList<Language> langs = detector.getProbabilities();

        if (langs.size() == 0) {
            return false;
        }

        for (Language l : langs) {
            if (l.lang.equals("en")) {
                return true;
            }
        }
        return false;
    } catch (Exception ex) {
        logger.warn("Problem while detecting language in text: " + content, ex);
        return false;
    }
}
 
开发者ID:ViDA-NYU,项目名称:ache,代码行数:33,代码来源:LangDetection.java

示例8: detectLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
/**
 * Perform the detection 
 * 
 * @param text to test
 * @return the detected language
 */
public LanguageDetectionResult detectLanguage(String text) {
    try {
        Detector detector = DetectorFactory.create(0.15);
        // issue#47 correction
        detector.append(text.toLowerCase());
        ArrayList<Language> languages = detector.getProbabilities();
        Language detectedLanguage =  
                extractLangWithHighestProbability(languages);
        return new LanguageDetectionResult(detectedLanguage, text, languages.size()>1);
    } catch (LangDetectException ex) {
        LOGGER.warn(ex);
    }
    return null;
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:21,代码来源:LanguageDetector.java

示例9: detectMostLikelyLanguage

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
public Language detectMostLikelyLanguage(String text) {
    try {
        Detector d = DetectorFactory.create();
        d.append(text);
        List<Language> languages = d.getProbabilities();
        if (languages != null && languages.size() > 0) {
            return languages.get(0);
        } else {
            return null;
        }
    } catch (LangDetectException e) {
        //logger.warn("Could not detect language.  Error was: ", e);
        return null;
    }
}
 
开发者ID:Sotera,项目名称:zephyr-sample-project,代码行数:16,代码来源:LanguageDetector.java

示例10: detectLangs

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
public ArrayList<Language> detectLangs(String text) throws LangDetectException {
    Detector detector = DetectorFactory.create();
    detector.append(text);
    return detector.getProbabilities();
}
 
开发者ID:NERD-project,项目名称:nerd-api,代码行数:6,代码来源:TDocument.java

示例11: detectLangs

import com.cybozu.labs.langdetect.Detector; //导入方法依赖的package包/类
public ArrayList<Language> detectLangs(String text) 
throws LangDetectException {
    Detector detector = DetectorFactory.create();
    detector.append(text);
    return detector.getProbabilities();
}
 
开发者ID:NERD-project,项目名称:nerd-api,代码行数:7,代码来源:LanguageDetect.java


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