spacy - Spacy NLP 示例:无法将标记转换为小写,抛出错误
问题描述
from collections import defaultdict
item_ratings = defaultdict(list)
for idx, review in data.iterrows():
doc = nlp(review.text)
matches = matcher(doc)
found_items = set(doc[match[1]:match[2]].lower_ for match in matches)
for item in found_items:
item_ratings[item].append(review.stars)
错误:
AttributeError: 'spacy.tokens.span.Span' object has no attribute 'lower_'
我需要标记为小写,我该怎么做?
解决方案
found_items = set(doc[match[1]:match[2]].text.lower() for match in matches)
就像错误所说的那样,Span
对象没有lower_
. 您可以使用text
then that' 只是一个字符串,以便您可以将其小写。
推荐阅读
- c++ - 编写单元测试并需要控制 c++ 链接器
- firebase - 有关在 Firebase 实时后端创建具有帖子节点的社交应用程序的提示/建议
- oauth-2.0 - 清除本地状态后,授权码流程如何记住用户?
- json - Django 休息框架 charfilter json
- python - 如何在python函数错误代码“名称'男性'未定义”中声明函数内的变量
- java - 直接从 main 访问链表节点
- git - 无法从 git 授权 github
- computer-science - 比较两个二叉堆是否相等的最著名的界限是什么?
- apache-kafka - Kafka RoundRobin 分区程序未将消息分发到所有分区
- sql - 我应该如何将 URL 添加到我的 SQL 案例语句中?