首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块“pytextrank”没有属性“parse_doc”

模块“pytextrank”没有属性“parse_doc”
EN

Stack Overflow用户
提问于 2019-12-14 13:56:13
回答 2查看 988关注 0票数 2

我正在执行nlp任务。我写了以下代码。在执行时,它显示以下错误。任何解决错误的建议都会很有帮助。我在google colab中使用python 3 env。

代码语言:javascript
复制
# 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()))

我收到以下错误:

代码语言:javascript
复制
  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'   
EN

回答 2

Stack Overflow用户

发布于 2020-02-16 01:24:09

在spaCy管道中使用Python语言实现TextRank

代码语言:javascript
复制
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)
票数 1
EN

Stack Overflow用户

发布于 2020-02-15 07:56:21

有一个更新的PyTextRank版本简化了调用代码,并使这些步骤变得不必要:https://spacy.io/universe/project/spacy-pytextrank

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59332687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档