我是靠谱客的博主 眯眯眼缘分,这篇文章主要介绍自然语言学习笔记之——hanlp环境配置anaconda 安装hanLpidea安装NLP,现在分享给大家,希望可以做个参考。

 hanlp的环境配置还是比较简单的,这里我主要配置了两个环境,一个是java环境和python,具体如下:

目录

anaconda 安装hanLp

idea安装NLP


anaconda 安装hanLp

1 指定清华镜像,加速下载:

复制代码
1
>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyhanlp

 2下载hanlp

 3 测试,如图所示安装成功:

代码测试:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
from pyhanlp import * def main(): HanLP.Config.enableDebug() # 为了避免你等得无聊,开启调试模式说点什么:-) print(HanLP.segment("王国维和服务员")) if __name__ == '__main__': main()

结果:

复制代码
1
[王国维/nr, 和/cc, 服务员/nnt]

idea安装NLP

首先构建一个maven工程,然后在pom.xml文件中添加依赖如下,即可:

复制代码
1
2
3
4
5
<dependency> <groupId>com.hankcs</groupId> <artifactId>hanlp</artifactId> <version>portable-1.7.5</version> </dependency>

代码测试:

编写如下代码,测试正确安装

复制代码
1
2
3
4
5
6
7
import com.hankcs.hanlp.HanLP; public class NLPtext { public static void main(String[] args) { System.out.println(HanLP.segment("你好,欢迎使用HanLP汉语处理包!")); } }

输出结果如下:

复制代码
1
[你好/l, ,/w, 欢迎/v, 使用/v, HanLP/nx, 汉语/nz, 处理/v, 包/v, !/w]

为了方便在后续中使用分析中的数据。

需要将在anaconda中下载的数据拷贝到的idea项目中,该数据在

拷贝到:

 

 代码测试:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package NLPLearn.chapter02; import com.hankcs.hanlp.corpus.io.IOUtil; import com.hankcs.hanlp.dictionary.CoreDictionary; import java.util.TreeMap; public class dictLoad { public static void main(String[] args) throws Exception{ TreeMap<String, CoreDictionary.Attribute> dictionary = IOUtil.loadDictionary("data/dictionary/CoreNatureDictionary.mini.txt"); System.out.println(dictionary.size()); System.out.println(dictionary.keySet().iterator().next()); } }

结果:

复制代码
1
2
85584 ±

最后

以上就是眯眯眼缘分最近收集整理的关于自然语言学习笔记之——hanlp环境配置anaconda 安装hanLpidea安装NLP的全部内容,更多相关自然语言学习笔记之——hanlp环境配置anaconda内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部