[英]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.