繁体   English   中英

如何将 nltk.book 的 output、common_contexts function 转换为变量

[英]How to take output of nltk.book, common_contexts function to a variable

nltk.book 中的 common_contexts 返回 NoneType ,因此如何将其 output 存储到变量中

from nltk.book import *
wtc=text1.common_contexts(['you'])
print(wtc)
print(type(wtc))

上面的 wtc 变量将返回 NONE。

我尝试将 common_context 的输出写入文件,然后使用拆分线从中读取

from nltk.book import *
import contextlib
fnallst=[]
for w in set(text2): ## we choose text2 as text2 has lesser distinct word
  filename = "C:\\Users\\username\Log"
  with open(filename,'w') as f:
   with contextlib.redirect_stdout(f):
    text2.common_contexts([w])
  with open(filename) as f:
   wct2 = f.read().splitlines()  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM