gsi-upm / senpy-plugins-community

Open source senpy plugins
Apache License 2.0
6 stars 6 forks source link

wnaffect plugin deactivate exception (can't pickle file object) #5

Open drevicko opened 7 years ago

drevicko commented 7 years ago

This looks like an object fairly deep in an object heirarchy. Could it be a file object stored in the WordNetCorpusReader??

^CBye!
ERROR:senpy.extensions:Error deactivating plugin emotion-wnaffect: can't pickle file objects
ERROR:senpy.extensions:Trace: Traceback (most recent call last):
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/site-packages/senpy/extensions.py", line 319, in deact
    plugin.deactivate()
  File "./emotion-wnaffect.py", line 88, in deactivate
    self.save()
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/site-packages/senpy/plugins/__init__.py", line 120, in save
    pickle.dump(self._sh, f)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 1376, in dump
    Pickler(file, protocol).dump(obj)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 655, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 669, in _batch_setitems
    save(v)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 425, in save_reduce
    save(state)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 655, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 669, in _batch_setitems
    save(v)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 655, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 669, in _batch_setitems
    save(v)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 425, in save_reduce
    save(state)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 655, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 669, in _batch_setitems
    save(v)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/Users/drevicko/anaconda/envs/python2/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects
drevicko commented 7 years ago

deleting the WordNetCorpusReader from self.sh in the plugins activate() method does indeed fix the problem.

It seems that class is not piclable, at least not without some massaging.

militarpancho commented 7 years ago

That is not happen to me: Senpy version 0.8.7 Server running on port 0.0.0.0:5000. Ctrl+C to quit [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package wordnet to /root/nltk_data... [nltk_data] Package wordnet is already up-to-date! INFO:senpy.extensions:Plugin activated: sentiment-basic ^CBye! INFO:senpy.extensions:Plugin deactivated: emotion-wnaffect INFO:senpy.extensions:Plugin deactivated: Ekman2FSRE INFO:senpy.extensions:Plugin deactivated: sentiment-140 INFO:senpy.extensions:Plugin deactivated: Ekman2PAD INFO:senpy.extensions:Plugin deactivated: ExamplePlugin INFO:senpy.extensions:Plugin deactivated: sentiment-meaningCloud INFO:senpy.extensions:Plugin deactivated: emotion-anew INFO:senpy.extensions:Plugin deactivated: affect INFO:senpy.extensions:Plugin deactivated: sentiment-vader INFO:senpy.extensions:Plugin deactivated: sentiment-basic Are you using senpy 0.8.7 version? On the other hand, in case the problem does not a version problem, i think deleting WordNetCorpusReader from self.sh is a good idea

drevicko commented 7 years ago

Maybe it's a python 2/3 thing? I've been using python 3 here.

But yes, not shelving the WordnetCorpusBuilder could be a good idea.

fyi: I've been building a multilingual wordnet in python 3 (since I can't do pos tagging). I'm converting wn1.6 ids in wn-affect to wn3.0 ids so I can use nltk.corpus.wordnet (which uses wn3.0) and don't need wn1.6.

I'll try to have a look once I get my next version running.

drevicko commented 7 years ago

I would guess it's my nltk version that's different. I can investigate if you prefer to keep the WordnetCorpusBuilder in the shelf.

btw: I've built a similar plugin (will be adding it here soon - it's in my fork if you're interested). The main things are 1) it uses the "open multilingual wordnet" in combination with NUIG's polylingual wordnet, so it covers some 40 languages and 2) it doesn't do word sense disambiguation, but instead counts a word if ANY of it's senses are in wordnet-affect emotion classes. Oh, I've also modified/expanded the classes used somewhat, especially for disgust, and added surprise. It uses wn-affect heirarchy levels 5, 6 and 7. Not yet tested in python 2 (hence I've not made a pull request yet).