NLTK does not show ngram results from zipped file

16 views
Skip to first unread message

Mazhar Dootio

unread,
Mar 15, 2017, 2:40:28 AM3/15/17
to nltk-users
Hellow friends;
I need your help in solving my problem of ngram results. I imported all required liberary files first than processed zipped file and than processed querty to get ngram results but it does not show results. Plz help. The coding is as below:

with zipfile.ZipFile('D:\Sindhicorpus.zip') as z:
    print (len(z.namelist()))
    for filename in z.namelist():
        if not os.path.isdir(filename):
            # read the file
            with z.open(filename, 'rU') as rf:
                line = rf.readline().decode('utf8') 
               # print(line)
(Above coding works fine)

import nltk
from nltk.collocations import *
line = ""
for val in filename:
    line += val
tokens = line.split()
bigram_measures = nltk.collocations.BigramAssocMeasures()
finder = BigramCollocationFinder.from_words(tokens)
finder.apply_freq_filter(3)
print(finder.nbest(bigram_measures.pmi, 100))

shows results only empty empty brackets  like     [ ]

Then I processed following code

from nltk import ngrams
n = 2
sixgrams = ngrams(filename.split(), n)
for grams in sixgrams:
  print(grams)

But it is also not showing any result.
plz resolve my problem.

Mazhar Ali

Dimitriadis, A. (Alexis)

unread,
Mar 15, 2017, 8:04:14 AM3/15/17
to nltk-...@googlegroups.com
You don’t show the details of your code, but `filename` is a string containing just the name of a zipped file. If you’re iterating over this string, you’ll just get single characters. 

Alexis


Dr. Alexis Dimitriadis | Assistant Professor and Senior Research Fellow | Utrecht Institute of Linguistics OTS | Utrecht University | Trans 10, 3512 JK Utrecht, room 2.33 | +31 30 253 65 68 | a.dimi...@uu.nl | www.hum.uu.nl/medewerkers/a.dimitriadis

--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages