0

common_contexts in nltk.book returns NoneType and hence how is it possible to store its output to a variable

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

wtc variable above will return NONE.

sakeesh
  • 919
  • 1
  • 10
  • 24

1 Answers1

0

What I tried was to write the ouput of common_context to a file ans then read from it using splitlines

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()  
sakeesh
  • 919
  • 1
  • 10
  • 24