mohabmes/Arabycia

if len(word['solution']) > 1: TypeError: list indices must be integers or slices, not str

Opened this issue · 6 comments

Hi ;

Thank ypu for ypour great work . when i execute your code i get this error :

/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py:246: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if returnval is "pos": return str[1]
[nltk_data] Downloading package punkt to /home/nassera/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
loading dictPrefixes ... loaded 299 entries
loading dictStems ... loaded 38600 lemmas and 82158 entries
loading dictSuffixes ... loaded 618 entries
Traceback (most recent call last):
  File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 297, in <module>
    print(arabycia.analyze())
  File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 17, in analyze
    self.find_ambiguity()
  File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 134, in find_ambiguity
    if len(word['solution']) > 1:
TypeError: list indices must be integers or slices, not str

Hi @nassera2014,

Hmm, I couldn't wrap my head around the problem, Would you kindly tell me a test case to generate the same issue?

Thank you for your feedback, i get this error after exucuting the same test in Arabycia code :
`import nltk
nltk.download('punkt')
arabycia = Arabycia()

text = 'يستعيد الكاتب في هذه الرواية كيف تحولت من مدينة للانوار الي مدينة للاشباح'
arabycia.set_raw_text(text)
print(arabycia.analyze())

text = 'يستجمع المؤرخ أفكاره'
arabycia.set_raw_text(text)
arabycia.analyze_text()
search_result = arabycia.text_search("جمع")
print(search_result)`

Please confirm if this branch solved your issue.

Thank you , i executed your modified code; and i get the same error :
loading dictPrefixes ... loaded 299 entries loading dictStems ... loaded 38600 lemmas and 82158 entries loading dictSuffixes ... loaded 618 entries Traceback (most recent call last): File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 296, in <module> arabycia.analyze() File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 17, in analyze self.find_ambiguity() File "/home/nassera/PycharmProjects/MyProject/TM_FB/Arabycia.py", line 134, in find_ambiguity if len(self.full_analyzed_data[index]['solution']) > 1: TypeError: list indices must be integers or slices, not str

@nassera2014 What is your python version?

@mohabmes my Python version is 3.8