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


Java NameFinderME.probs方法代码示例

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


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

示例1: tokenize

import opennlp.tools.namefind.NameFinderME; //导入方法依赖的package包/类
public Map<String, Set<String>> tokenize(String content) {
    Map<String, Set<String>> namedEntities = Maps.newHashMap();

    List<TextAnnotation> allTextAnnotations = new ArrayList<TextAnnotation>();
    String[] tokens = SimpleTokenizer.INSTANCE.tokenize(content);
    for (Map.Entry<String, TokenNameFinderModel> finderEntry : finders.entrySet()) {
        String type = finderEntry.getKey();
        NameFinderME finder = new NameFinderME(finderEntry.getValue());

        Span[] spans = finder.find(tokens);
        double[] probs = finder.probs(spans);

        for (int ni = 0; ni < spans.length; ni++) {
            allTextAnnotations.add(new TextAnnotation(type, spans[ni], probs[ni]));
        }
    }

    if (allTextAnnotations.size() > 0 ) {
        removeConflicts(allTextAnnotations);
    }
    convertTextAnnotationsToNamedEntities(tokens, allTextAnnotations, namedEntities);

    return namedEntities;
}
 
开发者ID:spinscale,项目名称:elasticsearch-opennlp-plugin,代码行数:25,代码来源:OpenNlpService.java

示例2: retrieve

import opennlp.tools.namefind.NameFinderME; //导入方法依赖的package包/类
@Override
public List<Entity> retrieve(final String input) {
  LOG.info("retrieve ...");

  final List<Entity> list = new ArrayList<>();
  final String[] sentences = FoxTextUtil.getSentences(input);
  LOG.debug("sentences: " + sentences.length);

  for (int i = 0; i < tokenNameFinderModels.length; i++) {
    if (tokenNameFinderModels[i] != null) {
      final NameFinderME nameFinder = new NameFinderME(tokenNameFinderModels[i]);
      for (final String sentence : sentences) {
        final String[] tokens = FoxTextUtil.getSentenceToken(sentence);
        LOG.debug("tokens: " + tokens.length);
        if ((tokens.length > 0) && tokens[tokens.length - 1].trim().isEmpty()) {
          tokens[tokens.length - 1] = ".";
        }

        final Span[] nameSpans = nameFinder.find(tokens);
        nameFinder.probs(nameSpans);
        for (int ii = 0; ii < nameSpans.length; ii++) {
          final Span span = nameSpans[ii];

          String word = "";
          for (int j = 0; j < (span.getEnd() - span.getStart()); j++) {
            word += tokens[span.getStart() + j] + " ";
          }
          word = word.trim();

          final float p = Entity.DEFAULT_RELEVANCE;
          // if ((FoxCfg.get("openNLPDefaultRelevance") != null)
          // && !Boolean.valueOf(FoxCfg.get("openNLPDefaultRelevance"))) {
          // p = Double.valueOf(probs[ii]).floatValue();
          // }
          final String cl = mapTypeToSupportedType(span.getType());
          if (cl != EntityClassMap.getNullCategory()) {
            list.add(getEntity(word, cl, p, getToolName()));
          }
        }
      }
      nameFinder.clearAdaptiveData();
    }
  }
  // TRACE
  if (LOG.isTraceEnabled()) {
    LOG.trace(list);
  } // TRACE
  return list;
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:50,代码来源:OpenNLPCommon.java


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