0

I have a data set on main memory. It contains a set of Persian sentences. When I search in my memory I get good result, But when I put ی or ک in my keyword, I don't get a search result.

my search func:

UPDATE:

def word_lookup(self,word,ayas):
    pos = []
    return_value = []


try:

    for aya in ayas:

        self.aya_list = aya[3].split()
        word_cnt = 0
        pos = []
        for aya_ in self.aya_list:
            if word in aya_:
                pos.append(word_cnt)
                return_value.append([aya[0],aya[1],aya[2],pos])
            word_cnt += 1
except Exception as e:
    print(e)
return return_value
calling functions
word_lookup("my unicode keyword",  a set of ayas)

How can I solve it?

I use python3.

PersianGulf
  • 2,845
  • 6
  • 47
  • 67
  • 1
    How do you search when you "get good result"? What is "my keyword"? Can you show some code, preferably [example]? With your description, it's like making a phone call to a doctor and saying "guess what's wrong with my nose!" – Amadan Jul 23 '19 at 05:22
  • Please share some sample code. It will help SO users to debug the issue better. – Tajinder Jul 23 '19 at 05:22
  • I used list and `in` @Amadan – PersianGulf Jul 23 '19 at 05:25
  • I update my question.@Amadan @Tajinder – PersianGulf Jul 23 '19 at 05:31
  • because `ی` and `ک` have two character-codes. Arabic one and Persian one, take a look at [https://stackoverflow.com/questions/5616063/characters-%D9%8A-and-%DB%8C-and-the-difference-in-persian-mysql](https://stackoverflow.com/questions/5616063/characters-%D9%8A-and-%DB%8C-and-the-difference-in-persian-mysql) – Muhammad Vakili Jul 23 '19 at 05:44
  • @PersianGulf also add a sample input for `word` and `ayas` – Tajinder Jul 23 '19 at 07:38

1 Answers1

0

You can do the following patch:

if re.match(r'\b\w*ی.*', word):
      word = re.sub(r'ی',r'ﻱ', word)

  if re.match(r'\b\w*ک.*', word):
      word = re.sub(r'ک',r'ﻙ', word)
PersianGulf
  • 2,845
  • 6
  • 47
  • 67