python - 模块“pytextrank”没有属性“parse_doc”
问题描述
我正在执行 nlp 任务。我已经编写了以下代码。在执行时,它显示以下错误。任何解决错误的建议都会有所帮助。我在 google colab 中有 python 3 env。
# Pytextrank
import pytextrank
import json
# Sample text
sample_text = 'I Like Flipkart. He likes Amazone. she likes Snapdeal. Flipkart and amazone is on top of google search.'
# Create dictionary to feed into json file
file_dic = {"id" : 0,"text" : sample_text}
file_dic = json.dumps(file_dic)
loaded_file_dic = json.loads(file_dic)
# Create test.json and feed file_dic into it.
with open('test.json', 'w') as outfile:
json.dump(loaded_file_dic, outfile)
path_stage0 = "test.json"
path_stage1 = "o1.json"
# Extract keyword using pytextrank
with open(path_stage1, 'w') as f:
for graf in pytextrank.parse_doc(pytextrank.json_iter(path_stage0)):
f.write("%s\n" % pytextrank.pretty_print(graf._asdict()))
print(pytextrank.pretty_print(graf._asdict()))
我收到以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-33-286ce104df34> in <module>()
20 # Extract keyword using pytextrank
21 with open(path_stage1, 'w') as f:
---> 22 for graf in
pytextrank.parse_doc(pytextrank.json_iter(path_stage0)):
23 f.write("%s\n" % pytextrank.pretty_print(graf._asdict()))
24 print(pytextrank.pretty_print(graf._asdict()))
AttributeError: module 'pytextrank' has no attribute 'parse_doc'
解决方案
在 Python 中实现 TextRank 以用于 spaCy 管道
import spacy
import pytextrank
nlp = spacy.load('en_core_web_sm')
tr = pytextrank.TextRank()
nlp.add_pipe(tr.PipelineComponent, name='textrank', last=True)
# Sample text
sample_text = 'I Like Flipkart. He likes Amazone. she likes Snapdeal. Flipkart and amazone is on top of google search.'
#funct
for p in doc._.phrases:
print(p.text)
推荐阅读
- c# - System.Text.Json 不知道响应
- api - PayPal REST API 应用程序,为什么有多个返回 URL
- google-chrome - 为什么图像显示在原始文件 URL 中,而不是使用 Chrome 显示在 html 中?其他浏览器没问题
- java - 如何指示 Jackson ObjectMapper 不将数字字段值转换为字符串属性?
- c# - 如何正确绑定 XAML 中的 ObservableCollection?
- powershell - Powershell 从对象中选择 NoteProperty 类型对象
- swift - Swift - 如何访问单元格名称
- python - 为什么 system("cls") 在 Python 中无法正常工作,因为它编写了一些奇怪的箭头字符?
- vector - Rust - 如何从函数返回多个变量,以便在调用函数的范围之外可以访问它们?
- python - 位置 args 元组的索引 1 超出范围