aboSamoor / polyglot

Multilingual text (NLP) processing toolkit
http://polyglot-nlp.com
Other
2.31k stars 337 forks source link

OSError: [Errno 2] No such file or directory: '/root/polyglot_data/morph2/cs' #45

Closed mariokam closed 8 years ago

mariokam commented 8 years ago

I am not able to install new models, for example czech language to test the morphology analysis:

root@mario-VirtualBox:/home/mario/python-scripts# python example.py 
Traceback (most recent call last):
  File "example.py", line 28, in <module>
    print(word2.morphemes)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/decorators.py", line 20, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/text.py", line 269, in morphemes
    words, score = self.morpheme_analyzer.viterbi_segment(self.string)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/decorators.py", line 20, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/text.py", line 265, in morpheme_analyzer
    return load_morfessor_model(lang=self.language)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/decorators.py", line 30, in memoizer
    cache[key] = obj(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/load.py", line 128, in load_morfessor_model
    p = locate_resource(src_dir, lang)
  File "/usr/local/lib/python2.7/dist-packages/polyglot-15.10.03-py2.7.egg/polyglot/load.py", line 51, in locate_resource
    return path.join(p, os.listdir(p)[0])
OSError: [Errno 2] No such file or directory: '/root/polyglot_data/morph2/cs'
root@mario-VirtualBox:/home/mario/python-scripts# 

my code is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import polyglot
from polyglot.text import Text, Word
from polyglot.detect import Detector
#from polyglot.downloader import downloader
#downloader.download("morph2.cs")

#mixed_text = u"""
#fficially the People's Republic of China (PRC), is a sovereign state located in East Asia.
#"""

#zen = Text("Beautiful is better than ugly. "
#           "Explicit is better than implicit. "
#           "Simple is better than complex.")
#print(zen.words)
#print(zen.sentences)

#detector = Detector(mixed_text)
#print(detector.language)

#word = Text("Preprocessing is an essential step.").words[0]
#print(word.morphemes)

word2 = Text("Na cestu do Německa se vydal už před dvěma roky.").words[0]
print(word2.morphemes)

from polyglot.transliteration import Transliterator
transliterator = Transliterator(source_lang="en", target_lang="cs")
print(transliterator.transliterate(u"preprocessing"))

commented lines are working well.

aboSamoor commented 8 years ago

Can you try to run the code under a normal user and not the root user.

mariokam commented 8 years ago

yes. Now the error is different:

mario@mario-VirtualBox:~/python-scripts$ python example.py 
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/mario/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
  warnings.warn(msg, UserWarning)
[u'Na']
mario@mario-VirtualBox:~/python-scripts$ 
aboSamoor commented 8 years ago

This is a warning and not an error and you need to remove write permissions for others something like

chmod -R 775 directory path

On Tue, Mar 8, 2016, 7:48 AM JohnDoe notifications@github.com wrote:

yes. Now the error is different:

mario@mario-VirtualBox:~/python-scripts$ python example.py /usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/mario/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable). warnings.warn(msg, UserWarning) [u'Na'] mario@mario-VirtualBox:~/python-scripts$

— Reply to this email directly or view it on GitHub https://github.com/aboSamoor/polyglot/issues/45#issuecomment-193831862.

mariokam commented 8 years ago

ok, now it works well. Thanks! Now is just a question of putting it into some web framework like Flask and do some string processing in Python, nice!