4

I am writing an algorithm which identifies sentences in given text, split each sentence into words & return these words after some validations.

I want to implement the same with the help of multi threading.

I'm calling my function which deals with each sentence in threading.thread() for which it throws an error:

AttributeError: 'WordListCorpusReader' object has no attribute '_LazyCorpusLoader__args'  

However, there are few blogs which suggest to use "wn.ensure_loaded()" function.

But python throws an error saying ensure_loaded() is not defined.

Can someone help me solve this.

EDIT:

text = "This is my sample text. I want to break it into sentences"  
sentences=(re.split(r"(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s",text))  
wn.ensure_loaded()      
co = CoOccurence()     #CoOccurence is a class in my package which will work on the sentences  
for sentence in sentences:  
    t = Thread(target=co.__prepareHash__, args=(sentence,)) #co.__prepareHash__   is an other method which works around the sentences  
    threads.append(t)  
    t.start()  

flag =1  
while (flag):  
    flag = __isThreadAlive__()  

This throws me an error: Attribute error: 'WordNetCorpusReader' object has no attribute '_LazyCorpusLoader__args'
When I try to check wn.ensure_loaded(), it throws AttributeError: 'module' object has no attribute 'ensure_loaded'

with ref. to : this SO question

Thank You

Community
  • 1
  • 1
Alekhya Vemavarapu
  • 1,145
  • 1
  • 10
  • 26
  • Can you provide a bit more code context? – lenz Oct 12 '15 at 08:54
  • @lenz Added some code, hope it'll give you some context – Alekhya Vemavarapu Oct 12 '15 at 09:11
  • First: why is the exception about the concept "dog"? I don't see anything related to "dog" in your testing text. Second: The solution in the linked SO post is "to access the `wn` object *before* you enter into your threading." It doesn't look like you are doing that. – lenz Oct 12 '15 at 09:15
  • kindly ignore the example of dog as it doesn't have any significance here. I'm using wn.ensure_loading() in the third line (edited) . Pl. check – Alekhya Vemavarapu Oct 12 '15 at 09:19
  • How do you import/assign to the name `wn`? I think the exception caused by calling `wn.ensure_loaded()` might lead you to the root of the problem. – lenz Oct 12 '15 at 09:30
  • @lenz from nltk.corpus import wordnet as wn – Alekhya Vemavarapu Oct 12 '15 at 09:34
  • can you please look into this http://stackoverflow.com/questions/33077639/python-difference-in-pydev-python-idle Because the same programming is executing very well from IDLE. Issue is when I run the same from eclipse PyDev – Alekhya Vemavarapu Oct 12 '15 at 09:36
  • 1
    Oh well. It's hard to debug that from a distance. I can only suggest what you should check next: maybe the two interpreters use separate NLTK data directories (or even installations), and probably in one of them some (wordnet corpus?) data are missing, or the installed NLTK versions differ... – lenz Oct 12 '15 at 09:41

0 Answers0