2014-02-27 4 views
1

하나의 특정 파이썬 파일을 실행하려고 할 때. 나는 오류 파이썬에서 입출력 오류 발생

Traceback (most recent call last): 
    File "<pyshell#4>", line 1, in <module> 
    g.stem(u"തുറക്കുക") 
    File "/usr/local/lib/python2.7/dist-packages/indicstemmer-0.1-py2.7.egg/indicstemmer/core.py", line 48, in stem 
    self.rulesDict = self.LoadRules() 
    File "/usr/local/lib/python2.7/dist-packages/indicstemmer-0.1-py2.7.egg/indicstemmer/core.py", line 81, in LoadRules 
    errors='ignore') 
    File "/usr/lib/python2.7/codecs.py", line 881, in open 
    file = __builtin__.open(filename, mode, buffering) 
IOError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/indicstemmer-0.1-py2.7.egg/indicstemmer/stemmer_ml.rules' 

문제가 여기에 무엇

다음 는 무엇입니까?

class Stemmer: 
    """ 
    Instantiate class to get the methods 
    """ 
    def __init__(self): 
     self.rules_file = os.path.join(os.path.dirname(__file__), \ 
     'stemmer_ml.rules') 
     self.rulesDict = None 
     self.normalizer = normalizer.getInstance() 

    def stem(self, text): 
     """ 
     :param text: unicode encoded malayalam string 
     :returns: dictionary with words as the key and the stemmer result 
     as the values. stems all the words in the given text and 
     returns a dictionary 
     """ 
     text = self.normalizer.normalize(text) 
     if self.rulesDict is None: 
      self.rulesDict = self.LoadRules() 
     words = text.split(" ") 
     word_count = len(words) 
     result_dict = dict() 
     word_iter = 0 
     word = "" 
     while word_iter < word_count: 
      word = words[word_iter] 
      word = self.trim(word) 
      word = word.strip('!,.?:') 
      word_length = len(word) 
      suffix_pos_itr = 2 
      word_stemmed = "" 
      while suffix_pos_itr < word_length: 
       suffix = word[suffix_pos_itr:word_length] 
       if suffix in self.rulesDict: 
        word_stemmed = word[0:suffix_pos_itr] + \ 
         self.rulesDict[suffix] 
        break 
       suffix_pos_itr = suffix_pos_itr+1 
      word_iter = word_iter+1 
      if(word_stemmed == ""): 
       word_stemmed = word 
      result_dict[ word ] = word_stemmed 
      print result_dict[2] 
     return result_dict 

    def LoadRules(self): 
     #print "Loading the rules..." 
     rules_dict = dict() 
     line = [] 
     line_number = 0 
     rule_number = 0 
     rules_file = codecs.open(self.rules_file, encoding='utf-8', \ 
      errors='ignore') 
     while 1: 
      line_number = line_number +1 
      text = unicode(rules_file.readline()) 
      if text == "": 
       break 
      if text[0] == '#': 
       continue #this is a comment - ignore 
      text = text.split("#")[0] #remove the comment part of the line 
      line_number = line_number +1 
      line = text.strip() # remove unwanted space 
      if(line == ""): 
       continue 
      if(len(line.split("=")) != 2): 
       print "[Error] Syntax Error in the Rules. Line number: ", \ 
        line_number 
       print "Line: "+ text 
       continue 
      lhs = line.split("=")[0].strip() 
      rhs = line.split("=")[1].strip() 
      if(len(rhs)>0): 
       if(lhs[0] == '"'): 
        lhs = lhs[1:len(lhs)] # if the string is "quoted" 
       if(lhs[len(lhs)-1] == '"'): 
        lhs = lhs[0:len(lhs)-1] # if the string is "quoted" 
      if(len(rhs)>0): 
       if(rhs[0] == '"'): 
        rhs = rhs[1:len(rhs)] # if the string is "quoted" 
       if(rhs[len(rhs)-1] == '"'): 
        rhs = rhs[0:len(rhs)-1]  # if the string is "quoted" 
      rule_number = rule_number+1 
      rules_dict[lhs] = rhs 
      #print "[", rule_number ,"] " +lhs + " : " +rhs 
     #print "Found ",rule_number, " rules." 
     return rules_dict 

설치 파일

from setuptools import setup, find_packages 

name = "indicstemmer" 

setup(
    name=name, 
    version="0.1", 
    license="LGPL-3.0", 
    description="Malayalam word stemmer", 

    long_description="""This application helps you to stem the words 
    in the given text. Currently supports only 
    Note that this is very experimental and uses a rule based approach. 

    """, 
    packages=find_packages(), 
    include_package_data=True, 
    setup_requires=['setuptools-git'], 
    install_requires=['setuptools','normalizer'], 
    test_suite="tests", 
    zip_safe=False, 
) 

테스트

import unittest 
from indicstemmer import getInstance 


class TestIndicStemmer(unittest.TestCase): 

    def setUp(self): 
     self.instance = getInstance() 

    def test_stemmer(self): 
     self.assertEqual(u"തുറക്കുക",self.instance.stem(u"തുറക്കുന്ന")[u"തുറക്കുന്ന"]) 

def main(): 
    suite = unittest.TestLoader().loadTestsFromTestCase(TestIndicStemmer) 
    unittest.TextTestRunner(verbosity=2).run(suite) 

if __name__ == "__main__": 
    main() 

나는 우분투 12.04 데스크톱 버전을 사용하고

+1

코드를 표시하십시오. – hanleyhansen

+0

@hanleyhansen 완료, 여기 내 코드는 –

+2

오류 메시지를 다시 읽어 보자. IOError : [Errno 2] 해당 파일이나 디렉토리가 없습니다. '/usr/local/lib/python2.7/dist-packages/indicstemmer-0.1- py2.7.egg/indicstemmer/stemmer_ml.rules''. 이런, 문제가 뭔지 궁금해. – RemcoGerlich

답변

1

오류 메시지의 중요한 라인은

File "/usr/lib/python2.7/codecs.py", line 881, in open 
    file = __builtin__.open(filename, mode, buffering) 
IOError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/indicstemmer-0.1-py2.7.egg/indicstemmer/stemmer_ml.rules' 

필수 파일 인 stemmer_ml.rules를 찾을 수 없기 때문에 지표 모듈이 제대로 설치되지 않았 음을 나타냅니다.

gstem()을 호출하기 전에 기본값을 설정할 필요가 없으며 파이썬 라이브러리의 권한으로 규칙에 도달 할 수 있는지 확인하십시오. 라이브러리 패키지 이외에 다시 설치해야합니다. 나는 파이썬의 다른 버전이 존재하는 경우 때때로 패키지가 잘못된 버전으로 설치된다는 것을 알아 챘다. 그러나이 경우에는 충돌 이전에 rules 파일로 끝났기 때문에 의심 스럽습니다.

+0

@thegrinner 괜찮아요 어떻게 내 코드를 테스트 할 수 있을까요? –

+0

@karu 방금 질문을 편집했습니다. 당신은 sabbahillel에게 물어보고 싶습니다. – thegrinner

+0

@karu 디렉토리 경로의 권한으로 인해 파일을 실제로 볼 수 있는지 확인해야합니다. 실제로 파일이있는 디렉토리로 갈 수 있다면 'ls -l'을 사용하여 볼 수 있습니다. 에디터로 가져올 수 있는지 확인하십시오. 다음은 파일을 검사하는 표준 방법입니다. – sabbahillel

관련 문제