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

Java ArrayCoreMap类代码示例

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

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



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

示例1: tokenizeFromFile

import edu.stanford.nlp.util.ArrayCoreMap; //导入依赖的package包/类
/**
 * Reads stdin through a buffer and runs only the tokenize annotator to the
 * StanfordCoreNLP pipeline. Tokens are printed to stdout one per line.
 * 
 * @param filePath
 *            The file to run the tagger on
 */
private static void tokenizeFromFile(String filePath) {
	Properties properties = new Properties();
	properties.setProperty("annotators", "tokenize");
	StanfordCoreNLP pipeline = new StanfordCoreNLP(properties);
	PrintWriter out = new PrintWriter(System.out);
	File dataFile = new File(filePath);

	Annotation annotation = null;
	try {
		annotation = new Annotation(IOUtils.slurpFile(dataFile));
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	pipeline.annotate(annotation);
	
	for (CoreMap token : annotation
			.get(CoreAnnotations.TokensAnnotation.class)) {
		ArrayCoreMap aToken = (ArrayCoreMap) token;
		out.println(aToken.toShortString(' ', "Text"));
		out.flush();
	}
}
 
开发者ID:Pro-Nouns,项目名称:StanfordCoreNLPUtility,代码行数:31,代码来源:StanfordCoreNLPUtility.java


示例2: concreteSectionToCoreMapList

import edu.stanford.nlp.util.ArrayCoreMap; //导入依赖的package包/类
public static List<CoreMap> concreteSectionToCoreMapList(final Section sect, final String commText) {
  List<CoreMap> toRet = new ArrayList<>();
  List<Sentence> sentList = sect.getSentenceList();
  int tokOffset = 0;
  for (int i = 0; i < sentList.size(); i++) {
    Sentence st = sentList.get(i);
    CoreMap cm = new ArrayCoreMap();
    cm.set(SentenceIndexAnnotation.class, i);
    final TextSpan sts = st.getTextSpan();
    final int sentCharStart = sts.getStart();
    final int sentCharEnd = sts.getEnding();
    LOGGER.debug("Setting stanford sentence BeginChar = {}", sentCharStart);
    cm.set(CharacterOffsetBeginAnnotation.class, sentCharStart);
    LOGGER.debug("Setting stanford sentence EndChar = {}", sentCharEnd);
    cm.set(CharacterOffsetEndAnnotation.class, sentCharEnd);
    String sectText = commText.substring(sentCharStart, sentCharEnd);
    LOGGER.debug("Setting text: {}", sectText);
    cm.set(TextAnnotation.class, sectText);

    Tokenization tkz = st.getTokenization();
    List<CoreLabel> clList = tokenizationToCoreLabelList(tkz, i, sentCharStart);
    final int maxIdx = clList.size();
    LOGGER.debug("Setting stanford sentence token begin: {}", tokOffset);
    cm.set(TokenBeginAnnotation.class, tokOffset);
    final int tokEnd = tokOffset + maxIdx;
    LOGGER.debug("Setting stanford sentence token end: {}", tokEnd);
    cm.set(TokenEndAnnotation.class, tokEnd);
    cm.set(TokensAnnotation.class, clList);

    tokOffset = tokEnd;
    toRet.add(cm);
  }

  return toRet;
}
 
开发者ID:hltcoe,项目名称:concrete-stanford-deprecated2,代码行数:36,代码来源:ConcreteToStanfordMapper.java


示例3: processParses

import edu.stanford.nlp.util.ArrayCoreMap; //导入依赖的package包/类
/**
 * Start from parsed trees, and run the coref.
 */
public List<EntityMention> processParses(Collection<Tree> trees) {
  CoreLabelTokenFactory tokenfactory = new CoreLabelTokenFactory();
  List<EntityMention> entities = null;

  // Create an empty Annotation
  Annotation document = new Annotation("");

  try {
    // Setup the sentences using CoreMaps and CoreLabels.
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    for( Tree tree : trees ) {
      List<CoreLabel> sentence = new ArrayList<CoreLabel>();
      CoreMap sent = new ArrayCoreMap(1);
      sent.set(TokensAnnotation.class,sentence);
      sentences.add(sent);

      // Now add the leaves from the trees as separate tokens.
      List<String> strs = TreeOperator.stringLeavesFromTree(tree);
      List<String> pos = TreeOperator.posTagsFromTree(tree);
      int start = 0, index = 0;
      for( String str : strs ) {
        CoreLabel label = tokenfactory.makeToken(str, start, start+str.length());
        start += str.length() + 1;
        label.set(PartOfSpeechAnnotation.class, pos.get(index++));
        sentence.add(label);
      }

      // Now add the parse tree.
      sent.set(TreeAnnotation.class, tree);
    }
    // Add all sentences as an annotation to the document.
    document.set(CoreAnnotations.SentencesAnnotation.class, sentences);

    //    for( CoreMap sen : sentences ) {
    //      System.out.println(sen);
    //    }

    // NOTE: You can see each annotator get created in the StanfordCoreNLP.java class. 
    //       Look at its function getDefaultAnnotatorPool()
    pipeline.annotate(document);

    //    System.out.println("AFTER");
    //    for( CoreMap sen : sentences )
    //      System.out.println(sen);      

    // This is the coreference link graph
    // Each chain stores a set of mentions that link to each other,
    // along with a method for getting the most representative mention
    // Both sentence and token offsets start at 1!
    Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class);
    //    for( Integer id : graph.keySet() ) System.out.println(id + "\t" + graph.get(id));
    entities = extractEntities(graph);
    
  } catch( Exception ex ) {
    System.out.println("--STANFORD COREF EXCEPTION-- Parses skipped...");
    ex.printStackTrace();
  }
    
  return entities;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:64,代码来源:CorefStanford.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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