AttributeError: module ‘hanlp.utils.rules‘ has no attribute ‘tokenize_english‘
最近在看Python人工智能20个小时玩转NLP自然语言处理【黑马程序员】_哔哩哔哩_bilibili
在p37文本处理的基本方法中提到了hanlp的使用
其中有这么一段代码,其目的是使用hanlp进行英文分词
import hanlp
tokenizer = hanlp.utils.rules.tokenize_english
tokenizer('Mr. Hankcs bought hankcs.com for 1.5 thousand dollars.')
正确执行结果应该为:
['Mr.', 'Hankcs', 'bought', 'hankcs.com', 'for', '1.5', 'thousand', 'dollars', '.']
但,我的环境报错AttributeError: module 'hanlp.utils.rules' has no attribute 'tokenize_english'
我看视频评论很多也报这个错误,但网上的解决方案不仅少,而且我试了好多个都没用。主要原因是:hanlp.utils.rules中没有tokenize_english。但视频有条评论提到“from hanlp.utils.english_tokenize import tokenize_english
在https://github.com/hankcs/HanLP/blob/doc-zh/README.md 查看文件结构”虽然试过但也没效果,想着是不是时间太久,hanlp版本(不知道叫版本还是什么!!!!)不一样。而且看连接中的文件结构也找不到相关的tokenize_english,但给了我个启发,直接去hanlp文件里面找,想着会不会是换的位置不一样,果然在C:\ProgramData\Anaconda3\Lib\site-packages\hanlp\utils\lang中发现有个en的文件,其中的english_tokenizer.py里面就有一个tokenize_english。
于是:
from hanlp.utils.lang.en.english_tokenizer import tokenize_english
tokenizer = tokenize_english
tokenizer('Mr. Hankcs bought hankcs.com for 1.5 thousand dollars.')
可行(结果一样,不知道和视频中hanlp.utils.rules.tokenize_english是不是一个东西,应该是!!!)
当然后面直接用这串代码也行,不过想方便一点与视频里面代码同步,可以在hanlp.utils.rules里面加上
import hanlp.utils.lang.en.english_tokenizerdef tokenize_english(text):return hanlp.utils.lang.en.english_tokenizer.tokenize_english(text)
本人python小白,import导入总感觉有问题,有一点乱,请各位不要笑,大家可以改的简短一点(其实我试了好多自认为没问题的导入方式,结果出现莫名其妙的错误,完全没有规律可言,算了,虽然这个不顺眼,但是符合预期结果就行)!!!!
即可用视频中的代码:
import hanlp
tokenizer = hanlp.utils.rules.tokenize_english
tokenizer('Mr. Hankcs bought hankcs.com for 1.5 thousand dollars.')
AttributeError: module ‘hanlp.utils.rules‘ has no attribute ‘tokenize_english‘相关推荐
- 成功解决AttributeError: module 'torch.utils' has no attribute 'data'
成功解决AttributeError: module 'torch.utils' has no attribute 'data' 目录 解决问题 解决思路 解决方法 解决问题 AttributeErr ...
- __main__.py:AttributeError: module 'labelme.utils' has no attribute 'draw_label'
实现labelme批量json_to_dataset方法中 https://blog.csdn.net/yql_617540298/article/details/81110685#comments ...
- AttributeError: module 'labelme.utils' has no attribute 'draw_label'
实现labelme批量json_to_dataset方法中 https://blog.csdn.net/yql_617540298/article/details/81110685#comments ...
- attributeError: module ‘keras.utils‘ has no attribute ‘get_file‘
attributeError: module 'keras.utils' has no attribute 'get_file' 将代码改为: from keras.utils.data_utils ...
- AttributeError: module ‘labelme.utils‘ has no attribute ‘draw_label‘
AttributeError: module 'labelme.utils' has no attribute 'draw_label' 安装指定版本labelme pip install label ...
- module ‘sklearn.utils._openmp_helpers‘ has no attribute ‘__pyx_capi__‘
使用imblearn对数据重采样时,导入包的过程出现了以下错误: module 'sklearn.utils._openmp_helpers' has no attribute '__pyx_capi ...
- 解决tensorflow报错:AttributeError: module ‘tensorflow.keras.backend‘ has no attribute ‘get_session‘ 问题
欢迎大家关注笔者,你的关注是我持续更博的最大动力 原创文章,转载告知,盗版必究 解决tensorflow报错:AttributeError: module 'tensorflow.keras.back ...
- 成功解决 AttributeError: module ‘keras.engine.topology‘ has no attribute ‘load_weights_from_hdf5_group_b
成功解决 AttributeError: module 'keras.engine.topology' has no attribute 'load_weights_from_hdf5_group_b ...
- 成功解决AttributeError: module ‘dask.array.numpy_compat‘ has no attribute ‘take_along_axis‘
成功解决AttributeError: module 'dask.array.numpy_compat' has no attribute 'take_along_axis' 目录 解决问题 解决思路 ...
- 成功解决AttributeError: module 'tensorflow.nn.rnn_cell' has no attribute 'linear'
成功解决AttributeError: module 'tensorflow.nn.rnn_cell' has no attribute 'linear' 目录 解决问题 解决思路 解决方法 解决问题 ...
最新文章
- 野比的示波器案例(Winfrom用户控件)
- Web开发工具包收藏
- Ubuntu 12.10中的8个新功能,Quantal Quetzal
- 剑指offer三从头到尾打印链表
- volatile和原子操作
- linux 备份命令
- 关于计算机组件游戏,电脑Windows10系统提示缺少游戏组件的解决方法
- LAMP架构源码部署(入门级别超详细步骤)
- PDF查看器之pdfvuer
- PHP写评论模块,uchome2.0 日志评论模块分析(php代码及js代码分析)
- PX PT 磅 EM 以及PS中字间距VA单位的解释
- i春秋_我很简单_解题记录
- win7开启ftp被动模式_Win7上防火墙开放FTP服务以及ping解决方案
- 如何判断mp4的moov的位置
- 零碎的知识点及常用特效
- 爱因斯坦犯了什么错?
- Kinect的介绍和应用【转】
- cmd批处理,webStrom/phpStrom/.....IDE工具编译
- Ubuntu 12.04-12.10 Linux 3D桌面完全教程,显卡驱动安装方法,compiz特效介绍,常见问题解答
- cma检测认证机构推荐 检测机构的分类