• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ScoredObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getKGoodFactoredParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<ScoredObject<Tree>> getKGoodFactoredParses(int k) {
  if (bparser == null) {
    return null;
  }
  List<ScoredObject<Tree>> binaryTrees = bparser.getKGoodParses(k);
  if (binaryTrees == null) {
    return null;
  }
  List<ScoredObject<Tree>> trees = new ArrayList<ScoredObject<Tree>>(k);
  for (ScoredObject<Tree> tp : binaryTrees) {
    Tree t = debinarizer.transformTree(tp.object());
    t = subcategoryStripper.transformTree(t);
    trees.add(new ScoredObject<Tree>(t, tp.score()));
  }
  return trees;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:17,代码来源:LexicalizedParser.java


示例2: getKBestPCFGParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Returns the trees (and scores) corresponding to the
 * k-best derivations of the sentence.  This cannot be
 * a Counter because frequently there will be multiple
 * derivations which lead to the same parse tree.
 *
 * @param k The number of best parses to return
 * @return The list of trees with their scores (neg log prob).
 */
public List<ScoredObject<Tree>> getKBestPCFGParses(int k) {
  if (pparser == null) {
    return null;
  }
  List<ScoredObject<Tree>> binaryTrees = pparser.getKBestParses(k);
  if (binaryTrees == null) {
    return null;
  }
  List<ScoredObject<Tree>> trees = new ArrayList<ScoredObject<Tree>>(k);
  for (ScoredObject<Tree> p : binaryTrees) {
    Tree t = debinarizer.transformTree(p.object());
    t = subcategoryStripper.transformTree(t);
    trees.add(new ScoredObject<Tree>(t, p.score()));
  }
  return trees;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:26,代码来源:LexicalizedParser.java


示例3: stringToParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Convert string representing scored parses (in the charniak parser output format)
 *   to list of scored parse trees
 * @param parseStr
 * @return list of scored parse trees
 */
public List<ScoredObject<Tree>> stringToParses(String parseStr)
{
  try {
    BufferedReader br = new BufferedReader(new StringReader(parseStr));
    Iterable<List<ScoredObject<Tree>>> trees = readScoredTrees("", br);
    List<ScoredObject<Tree>> res = null;
    if (trees != null) {
      Iterator<List<ScoredObject<Tree>>> iter = trees.iterator();
      if (iter != null && iter.hasNext()) {
        res = iter.next();
      }
    }
    br.close();
    return res;
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:25,代码来源:CharniakScoredParsesReaderWriter.java


示例4: next

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<ScoredObject<Tree>> next()
{
  if (!done) {
    List<ScoredObject<Tree>> cur = next;
    next = getNext();
    processed++;
    if (next == null) {
      logger.finer("Read " + processed + " trees, from "
              + inputDesc + " in " + timing.toSecondsString() + " secs");
      done = true;
      if (closeBufferNeeded) {
        try { br.close();  } catch (IOException ex) {};
      }
    }
    return cur;
  } else {
    throw new NoSuchElementException("No more elements from " + inputDesc);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:20,代码来源:CharniakScoredParsesReaderWriter.java


示例5: getKGoodFactoredParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<ScoredObject<Tree>> getKGoodFactoredParses(int k) {
  if (bparser == null || parseSkipped) {
    return null;
  }
  List<ScoredObject<Tree>> binaryTrees = bparser.getKGoodParses(k);
  if (binaryTrees == null) {
    return null;
  }
  List<ScoredObject<Tree>> trees = new ArrayList<ScoredObject<Tree>>(k);
  for (ScoredObject<Tree> tp : binaryTrees) {
    Tree t = debinarizer.transformTree(tp.object());
    t = subcategoryStripper.transformTree(t);
    restoreOriginalWords(t);
    trees.add(new ScoredObject<Tree>(t, tp.score()));
  }
  return trees;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:18,代码来源:LexicalizedParserQuery.java


示例6: getKBestPCFGParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Returns the trees (and scores) corresponding to the
 * k-best derivations of the sentence.  This cannot be
 * a Counter because frequently there will be multiple
 * derivations which lead to the same parse tree.
 *
 * @param k The number of best parses to return
 * @return The list of trees with their scores (log prob).
 */
public List<ScoredObject<Tree>> getKBestPCFGParses(int k) {
  if (pparser == null) {
    return null;
  }
  List<ScoredObject<Tree>> binaryTrees = pparser.getKBestParses(k);
  if (binaryTrees == null) {
    return null;
  }
  List<ScoredObject<Tree>> trees = new ArrayList<ScoredObject<Tree>>(k);
  for (ScoredObject<Tree> p : binaryTrees) {
    Tree t = debinarizer.transformTree(p.object());
    t = subcategoryStripper.transformTree(t);
    restoreOriginalWords(t);
    trees.add(new ScoredObject<Tree>(t, p.score()));
  }
  return trees;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:27,代码来源:LexicalizedParserQuery.java


示例7: rerank

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
List<ScoredObject<Tree>> rerank(List<? extends HasWord> sentence, List<ScoredObject<Tree>> bestKParses) {
  RerankerQuery rq = reranker.process(sentence);

  List<ScoredObject<Tree>> reranked = new ArrayList<ScoredObject<Tree>>();
  for (ScoredObject<Tree> scoredTree : bestKParses) {
    double score = scoredTree.score();
    try {
      score = op.baseParserWeight * score + rq.score(scoredTree.object());
    } catch (NoSuchParseException e) {
      score = Double.NEGATIVE_INFINITY;
    }
    reranked.add(new ScoredObject<Tree>(scoredTree.object(), score));
  }
  Collections.sort(reranked, ScoredComparator.DESCENDING_COMPARATOR);
  return reranked;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:17,代码来源:RerankingParserQuery.java


示例8: getKGoodFactoredParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<ScoredObject<Tree>> getKGoodFactoredParses(int k) {
  if (bparser == null) {
    return null;
  }
  List<ScoredObject<Tree>> binaryTrees = bparser.getKGoodParses(k);
  if (binaryTrees == null) {
    return null;
  }
  List<ScoredObject<Tree>> trees = new ArrayList<ScoredObject<Tree>>(k);
  for (ScoredObject<Tree> tp : binaryTrees) {
    Tree t = debinarizer.transformTree(tp.object());
    t = subcategoryStripper.transformTree(t);
    restoreOriginalWords(t);
    trees.add(new ScoredObject<Tree>(t, tp.score()));
  }
  return trees;
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:18,代码来源:LexicalizedParserQuery.java


示例9: parse

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<Tree> parse(List<? extends HasWord> words, int k) {
	parserK.parse(words);
	ArrayList<Tree> trees = new ArrayList<Tree>();
	for (ScoredObject<Tree> tree : parserK.getKBestParses(k))
		trees.add(new EnglishTreebankParserParams().subcategoryStripper().transformTree(new Debinarizer(false).transformTree(tree.object())));
	return trees;
}
 
开发者ID:hakchul77,项目名称:irnlp_toolkit,代码行数:8,代码来源:StanfordNlpWrapper.java


示例10: selectFeatures

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Generic method to select features based on the feature scores vector provided as an argument.
 * @param numFeatures number of features to be selected.
 * @param scores a vector of size total number of features in the data.
 */
public void selectFeatures(int numFeatures, double[] scores) {

  List<ScoredObject<F>> scoredFeatures = new ArrayList<ScoredObject<F>>();

  for (int i = 0; i < scores.length; i++) {
    scoredFeatures.add(new ScoredObject<F>(featureIndex.get(i), scores[i]));
  }

  Collections.sort(scoredFeatures, ScoredComparator.DESCENDING_COMPARATOR);
  Index<F> newFeatureIndex = new HashIndex<F>();
  for (int i = 0; i < scoredFeatures.size() && i < numFeatures; i++) {
    newFeatureIndex.add(scoredFeatures.get(i).object());
    //System.err.println(scoredFeatures.get(i));
  }

  for (int i = 0; i < size; i++) {
    int[] newData = new int[data[i].length];
    int curIndex = 0;
    for (int j = 0; j < data[i].length; j++) {
      int index;
      if ((index = newFeatureIndex.indexOf(featureIndex.get(data[i][j]))) != -1) {
        newData[curIndex++] = index;
      }
    }
    int[] newDataTrimmed = new int[curIndex];
    System.arraycopy(newData, 0, newDataTrimmed, 0, curIndex);
    data[i] = newDataTrimmed;
  }
  featureIndex = newFeatureIndex;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:36,代码来源:Dataset.java


示例11: parsesToString

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Convert list of scored parse trees to string representing scored parses
 *   (in the charniak parser output format)
 * @param parses - list of scored parse trees
 * @return string representing scored parses
 */
public String parsesToString(List<ScoredObject<Tree>> parses)
{
  if (parses == null) return null;
  StringOutputStream os = new StringOutputStream();
  PrintWriter pw = new PrintWriter(os);
  printScoredTrees(pw, 0, parses);
  pw.close();
  return os.toString();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:16,代码来源:CharniakScoredParsesReaderWriter.java


示例12: printScoredTrees

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Print scored parse trees in format used by charniak parser
 * @param trees - trees to output
 * @param filename - file to output to
 */
public void printScoredTrees(Iterable<List<ScoredObject<Tree>>> trees, String filename)
{
  try {
    PrintWriter pw = IOUtils.getPrintWriter(filename);
    int i = 0;
    for (List<ScoredObject<Tree>> treeList:trees) {
      printScoredTrees(pw, i, treeList);
      i++;
    }
    pw.close();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:20,代码来源:CharniakScoredParsesReaderWriter.java


示例13: parse

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
@Override
public boolean parse(List<? extends HasWord> sentence) {
  boolean success = parserQuery.parse(sentence);
  if (!success) {
    return false;
  }

  List<ScoredObject<Tree>> bestKParses = parserQuery.getKBestPCFGParses(rerankerKBest);
  if (bestKParses.size() == 0) {
    return false;
  }
  scoredTrees = rerank(sentence, bestKParses);
  return true;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:15,代码来源:RerankingParserQuery.java


示例14: parseAndReport

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
@Override
public boolean parseAndReport(List<? extends HasWord> sentence, PrintWriter pwErr) {
  boolean success = parserQuery.parseAndReport(sentence, pwErr);
  if (!success) {
    return false;
  }

  List<ScoredObject<Tree>> bestKParses = parserQuery.getKBestPCFGParses(rerankerKBest);
  if (bestKParses.size() == 0) {
    return false;
  }
  scoredTrees = rerank(sentence, bestKParses);
  return true;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:15,代码来源:RerankingParserQuery.java


示例15: getBestPCFGParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
@Override
public List<ScoredObject<Tree>> getBestPCFGParses() {
  if (scoredTrees == null || scoredTrees.size() == 0) {
    throw new AssertionError();
  }
  List<ScoredObject<Tree>> equalTrees = Generics.newArrayList();
  double score = scoredTrees.get(0).score();
  int treePos = 0;
  while (treePos < scoredTrees.size() && scoredTrees.get(treePos).score() == score) {
    equalTrees.add(scoredTrees.get(treePos));
  }
  return equalTrees;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:14,代码来源:RerankingParserQuery.java


示例16: getKBestPCFGParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
@Override
public List<ScoredObject<Tree>> getKBestPCFGParses(int kbestPCFG) {
  List<ScoredObject<Tree>> trees = Generics.newArrayList();
  for (int treePos = 0; treePos < scoredTrees.size() && treePos < kbestPCFG; ++treePos) {
    trees.add(scoredTrees.get(treePos));
  }
  return trees;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:9,代码来源:RerankingParserQuery.java


示例17: getNext

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
private List<ScoredObject<Tree>> getNext()
{
  try {
    String line;
    int parsesExpected = 0;
    int sentenceId = lastSentenceId;
    ScoredObject<Tree> curParse = null;
    List<ScoredObject<Tree>> curParses = null;
    while ((line = br.readLine()) != null) {
      line = line.trim();
      if (line.length() > 0) {
        if (parsesExpected == 0) {
          // Finished processing parses
          String[] fields = wsDelimiter.split(line, 2);
          parsesExpected = Integer.parseInt(fields[0]);
          sentenceId = Integer.parseInt(fields[1]);
          if (expectConsecutiveSentenceIds) {
           if (sentenceId != lastSentenceId+1) {
              if (lastSentenceId < sentenceId) {
                StringBuilder sb = new StringBuilder("Missing sentences");
                for (int i = lastSentenceId+1; i < sentenceId; i++) {
                  sb.append(" ").append(i);
                }
                logger.warning(sb.toString());
              } else {
                logger.warning("sentenceIds are not increasing (last="
                      + lastSentenceId + ", curr=" + sentenceId + ")");
              }
            }
          }
          lastSentenceId = sentenceId;
          curParses = new ArrayList<ScoredObject<Tree>>(parsesExpected);
        } else {
          if (curParse == null) {
            // read score
            double score = Double.parseDouble(line);
            curParses.add(curParse = new ScoredObject<Tree>(null, score));
          } else {
            // Reading a parse
            curParse.setObject(Trees.readTree(line));
            curParse = null;
            parsesExpected--;
            if (parsesExpected == 0) {
              return curParses;
            }
          }
        }
      }
    }
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
  return null;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:55,代码来源:CharniakScoredParsesReaderWriter.java


示例18: getBestPCFGParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
public List<ScoredObject<Tree>> getBestPCFGParses() {
  return pparser.getBestParses();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:4,代码来源:LexicalizedParserQuery.java


示例19: getKGoodFactoredParses

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
@Override
public List<ScoredObject<Tree>> getKGoodFactoredParses(int kbest) {
  // TODO: barf?
  return null;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:6,代码来源:RerankingParserQuery.java


示例20: readScoredTrees

import edu.stanford.nlp.util.ScoredObject; //导入依赖的package包/类
/**
 * Reads scored parses from the charniak parser
 *
 * File format of the scored parses
 * <# of parses>\t<sentenceid>
 * <score>
 * <parse>
 * <score>
 * <parse>
 * ...
 *
 * @param filename  - File to read parses from
 * @return iterable with list of scored parse trees
 */
public Iterable<List<ScoredObject<Tree>>> readScoredTrees(String filename)
{
  try {
    ScoredParsesIterator iter = new ScoredParsesIterator(filename);
    return new IterableIterator<List<ScoredObject<Tree>>>(iter);
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:24,代码来源:CharniakScoredParsesReaderWriter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TelemetryClient类代码示例发布时间:2022-05-23
下一篇:
Java Model类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap