Stanford CoreNLP使用
来源:互联网 发布:程序员需要读的书 编辑:程序博客网 时间:2024/05/16 18:19
package dong.aid;import java.util.List;import java.util.Properties;import edu.stanford.nlp.dcoref.CorefCoreAnnotations.CorefChainAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;import edu.stanford.nlp.ling.CoreLabel;import edu.stanford.nlp.pipeline.Annotation;import edu.stanford.nlp.pipeline.StanfordCoreNLP;import edu.stanford.nlp.semgraph.SemanticGraph;import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation;import edu.stanford.nlp.trees.Tree;import edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation;import edu.stanford.nlp.util.CoreMap;public class Testing_StanfordNLP2 {public static void main(String[] args) { Properties props = new Properties(); props.put("annotators", "tokenize,ssplit,pos,lemma,ner, parse"); /* tokenize Tokenizes the text. * ssplit Splits a sequence of tokens into sentences. * pos Labels tokens with their POS tag. * parse * * */ StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String txtWord = "Beijing sing Lenovo.";//"Stanford University is located in Stanford. It is one of best good universities"; Annotation document = new Annotation(txtWord); pipeline.annotate(document); // these are all the sentences in this document //下面的sentences 中包含了所有分析结果,遍历即可获知结果。 List<CoreMap> sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) {// a CoreLabel is a CoreMap with additional token-specific methods for (CoreLabel token: sentence.get(TokensAnnotation.class)) {// this is the text of the token String word = token.get(TextAnnotation.class); String lema = token.get(LemmaAnnotation.class); // this is the POS tag of the token String pos = token.get(PartOfSpeechAnnotation.class); // this is the NER label of the token String ne = token.get(NamedEntityTagAnnotation.class); // logger.info(word+","+lema);// originWord = lema;// originFlag = true; System.out.println(word+"\t"+pos+"\t"+lema+"\t"+ne); } // this is the parse tree of the current sentence Tree tree = sentence.get(TreeAnnotation.class); System.out.println(tree.toString()); // this is the Stanford dependency graph of the current sentence SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class); System.out.println(dependencies.toString()); }}}
0 0
- Stanford CoreNLP使用
- Eclipse下使用Stanford CoreNLP的方法
- 使用Stanford CoreNLP工具包处理中文
- Stanford CoreNLP 3.6.0 使用入门
- 使用Stanford CoreNLP工具包处理中文
- Stanford CoreNLP 介绍
- Stanford CoreNLP API
- 如何使用Stanford CoreNlp做中文情感分析
- stanford corenlp自定义切词类
- Stanford coreNLP源码学习(1)
- Stanford CoreNLP遇到的问题
- 1.getting started Stanford CoreNLP
- Stanford CoreNLP 进行中文分词
- Stanford CoreNLP学习日记1
- Stanford CoreNLP学习日记2
- Stanford CoreNLP学习日记3
- Stanford CoreNLP学习日记4
- Stanford CoreNLP学习日记5
- jetty-runner-*.jar 运行war小例子
- zoj2000 Palindrome Numbers
- 有序单链表转BST树+时间复杂度要求O(n)
- 四则运算
- Lua_Math标准库
- Stanford CoreNLP使用
- HDU 2217 Visit 枚举求解
- p52第二单元22题
- P54 第49题 求和
- Lua教程(2):C++和Lua相互传递数据
- 第一篇
- tp 单字母函数详解
- 冒泡排序和快速排序
- 那天,我刚吃过晚饭后