最近工作需要,研究学习 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. 文件和Stream

    I/O和文件 输入/输出(I/O)就是在内存和外部设备之间复制数据的过程.输入(input)就是从I/O设备复制数据到内存,输出(output)就是从内存复制数据到I/O设备. 一个文件可以理解成一串 ...

  2. 设置Apache监听多个端口

    1.在配置文件httpd.conf中Listen多个端口 Listen localhost:8033    Listen localhost:8083 ....... 2.在配置文件夹下的extra文 ...

  3. 在控制台程序中,添加config文件

    一.右击类库 → 添加 → 新建项 → 应用程序配置文件(或者选择一个XML文件,然后将名字改成XXX.config),内容如下: <?xml version="1.0" e ...

  4. SQLServer备份计划制定

    SQLServer备份计划制定 一.备份计划制定 管理-->维护计划-->维护计划向导: 可选择全库备份.差异备份.事务日志备份 为保障数据的完整性:可采用备份策略1.数据量小的场景,数据 ...

  5. 浏览器端-W3School-HTML:HTML DOM Base 对象

    ylbtech-浏览器端-W3School-HTML:HTML DOM Base 对象 1.返回顶部 1. HTML DOM Base 对象 Base 对象 Base 对象代表 HTML 的 base ...

  6. Link标签

    Link标签的属性:rel定义当前文档与目标文档之间的关系. rev定义目标文档与当前文档之间的关系. Link和@import的区别:   1.隶属上的差别      link是一个html的一个标 ...

  7. WPF 模拟迅雷TabControl界面

    WPF模拟迅雷TabControl界面 点击查看下载 <!--TabControl样式--> <Style x:Key="TabControlStyle" Tar ...

  8. linux常用命令(22)gzip命令

    减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以用 ...

  9. TensorFlow基础总结

    1.基础概念 Tensor:类型化的多维数组,图的边:Tensor所引用的并不持有具体的值,而是保持一个计算过程,可以使用session.run()或者t.eval()对tensor的值进行计算. O ...

  10. Python中调用c语言(简单版)

    Python中有时需要调用c程序中的函数.使用ctype库可以很方便地调用c语言.现说明方法,以及注意事项. c程序编译为.so文件: 我们需要的c语言文件为test.c,要从其中调用func(x,y ...