最近工作需要,研究学习 NLP ,但是 苦于官方文档太过纷繁,容易找不到重点,于是打算自己写一份学习线路

NLP 路线图

好博客韩小阳

斯坦福NLP公开课

统计学习方法

好博客

链接地址:https://pan.baidu.com/s/1myVT-yMzqzJIcl50mGs2JA
提取密码:tw6r

参考文档:

StanfordNLPAPI

依照 印度小哥的 视频 跑了一个小 demo

step 1 用 IDEA 构建一个 maven 项目,引入 相关依赖包,当前依赖包最新版本为 3.9.2

<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
<classifier>models</classifier>
</dependency> <!--添加中文支持--> <dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
<classifier>models-chinese</classifier>
</dependency>

step 2 使用 nlp 包

package com.ghc.corhort.query.utils;

import edu.stanford.nlp.coref.CorefCoreAnnotations;
import edu.stanford.nlp.coref.data.CorefChain;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeCoreAnnotations;
import edu.stanford.nlp.util.CoreMap; import java.util.*; /**
* @author :Frank Li
* @date :Created in 2019/8/7 13:39
* @description:${description}
* @modified By:
* @version: $version$
*/
public class Demo {
public static void main(String[] args) {
// creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); // read some text in the text variable
String text = "I like eat apple!"; // create an empty Annotation just with the given text
Annotation document = new Annotation(text); // run all Annotators on this text
pipeline.annotate(document); // these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for(CoreMap sentence: sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// this is the NER label of the token
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class); System.out.println("word:"+word+"-->pos:"+pos+"-->ne:"+ne);
} // this is the parse tree of the current sentence
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); System.out.println(String.format("tree:\n%s",tree.toString()));
// this is the Stanford dependency graph of the current sentence
SemanticGraph dependencies = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
} // 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(CorefCoreAnnotations.CorefChainAnnotation.class);
}
}

输出结果

浅度原理


stanford corenlp的TokensRegex
最近做一些音乐类、读物类的自然语言理解,就调研使用了下Stanford corenlp,记录下来。 功能
Stanford Corenlp是一套自然语言分析工具集包括: POS(part of speech tagger)-标注词性
NER(named entity recognizer)-实体名识别
Parser树-分析句子的语法结构,如识别出短语词组、主谓宾等
Coreference Resolution-指代消解,找出句子中代表同一个实体的词。下文的I/my,Nader/he表示的是同一个人
   Sentiment Analysis-情感分析
Bootstrapped pattern learning-自展的模式学习(也不知道翻译对不对,大概就是可以无监督的提取一些模式,如提取实体名)
Open IE(Information Extraction)-从纯文本中提取有结构关系组,如"Barack Obama was born in Hawaii" =》 (Barack Obama; was born in; Hawaii)
需求
语音交互类的应用(如语音助手、智能音箱echo)收到的通常是口语化的自然语言,如:我想听一个段子,给我来个牛郎织女的故事,要想精确的返回结果,就需要提出有用的主题词,段子/牛郎织女/故事。看了一圈就想使用下corenlp的TokensRegex,基于tokens序列的正则表达式。因为它提供的可用的工具有:正则表达式、分词、词性、实体类别,另外还可以自己指定实体类别,如指定牛郎织女是READ类别的实体。

接下来要做 nlp2sql 的事情了



StanfordNLP for JAVA demo的更多相关文章

  1. Rancher之Pipeline JAVA demo

    Rancher Pipeline Pipeline,简单来说,就是一套运行于Rancher上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程. Ranc ...

  2. jdk自带的数据库derby的基本使用以及注意事项(mac为例),附java demo

    文章目录 安装 环境变量 验证是否安装成功 启动 本地启动 允许远程连接的启动方式: 在启动过程中可能遇到的错误(远程连接的时候会出现): 1 2 连接测试,创建数据库 方法一(推荐) 方法二 jav ...

  3. 腾讯云>>云通信>>TLS后台API在mac上JAVA DEMO搭建

    1.相关文档地址 2.相关demo代码 代码部分作了修改,使用了commons-io中的IOUtils.toString简化了io操作 public class Demo { public stati ...

  4. mongdb Java demo

    接触MONGDB,感觉用起来还挺好.今天做了一个小demo. 一.启动mongdb的服务

  5. JSON WEB TOKEN - 告别session和cookie - java demo

    JWT简介 JWT认证流程: 用户登录成功,生成token,返回一个对象(包含token,用户名) 每次请求都带上这个对象(通过js存储在电脑) jwt过滤器会校验token解密之后的name是否和用 ...

  6. GraphQL Java Demo代码

    mvn 引用GraphQL <dependency> <groupId>com.graphql-java</groupId> <artifactId>g ...

  7. 中间件 activeMQ Jms Java Demo

    一.什么是ActiveMQ 百度解释: ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provi ...

  8. Comet入门及最简单的Java Demo

    在浏览网页的时候,假设有新的消息,怎样接收到?HTTP协议不能由server主动给client发送消息. 1.刷微博.逛论坛贴吧,想看最新的信息怎么办?F5刷新一下就OK了! 2.上面一种方式是被动的 ...

  9. 汇率换算自然语言理解功能JAVA DEMO

    >>>>>>>>>>>>>>>>>>>>>>>> 欢迎转 ...

随机推荐

  1. Error:Connection activation failed: No suitable device found for this connection

    原文链接: https://blog.csdn.net/baiboya/article/details/80452822 ens33这个网卡一直无法激活,在网上找了半天,找到这个博主的文章,才解决,虽 ...

  2. 20175212童皓桢 《Java程序设计》第十周学习总结

    学号 2016-2017-2 <Java程序设计>第X周学习总结 教材学习内容总结 一.Java中的线程的状态 建的线程在它的一个完整的生命周期中通常要经历如下的四种状态: 1.新建: 当 ...

  3. Shell中的条件测试和循环语句

    1.条件测试:test或[ 如果测试结果为真,则该命令的Exit Status为0,如果测试结果为假,则命令的Exit Status为0 运行结果: 带与.或.非的测试命令[ ! EXPR ] : E ...

  4. 石川es6课程---1-2、ES6简介

    石川es6课程---1-2.ES6简介 一.总结 一句话总结: 从ECMAScript的历史发展来看,太顺了的时候总会遇到一挫折,比如ecma4 1.ECMAScript 和 JavaScript关系 ...

  5. leetcode 82 删除排序列表中的重复元素II

    与83类似,不过需要注意去除连续的重复片段的情况,如2 2 3 3这种情况,以及[1,1]这种情况下最终的cur为NULL,因此不能再令cur=cur->next; /** * Definiti ...

  6. Windows 10下怎么远程连接 Ubuntu 16.0.4(方案二)

    使用TeamViewer实现远程桌面连接 背景: 有些朋友反映,借助Ubuntu自带的桌面共享工具desktop sharing会有不再同一网端下出现连接不稳定或者掉线的问题,那么现在我们就可以借助第 ...

  7. 收货确定 BAPI BAPI_GOODSMVT_CREATE

    CLEAR gmhead.     gmhead-pstng_date = ls_table-gzdate."sy-datum .     gmhead-doc_date = sy-datu ...

  8. ibatis使用iterate实现批量插入insert正确写法

    由于想批量入库提升效率,最近实现了ibatis的批量插入,结果一直报错 :StringIndexOutOfBoundsException ,原来是value中的格式不正确. 本人邮箱:techqu@1 ...

  9. [译]深入 NGINX: 为性能和扩展所做之设计

    来自:http://ifeve.com/inside-nginx-how-we-designed-for-performance-scale/ 这篇文章写了nginx的设计,写的很仔细全面, 同时里面 ...

  10. LeetCode.12-整数转罗马数字符串(Integer to Roman)

    这是悦乐书的第351次更新,第376篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第6题(顺位题号是12).罗马数字由七个不同的符号表示:I,V,X,L,C,D和M. ...