vi3k6i5 / flashtext

Extract Keywords from sentence or Replace keywords in sentences.
MIT License
5.57k stars 599 forks source link

Throws Index Error For this Mapping #79

Closed AdityaSoni19031997 closed 4 years ago

AdityaSoni19031997 commented 5 years ago

Thanks for your lib :) but why is there this error on this mapping? (no empty strings as such)

mis_spell_mapping = {
    'whattsup': 'WhatsApp', 'whatasapp':'WhatsApp', 'whatsupp':'WhatsApp','whatcus':'what cause', 'arewhatsapp': 'are WhatsApp', 'Hwhat':'what',
    'Whwhat': 'What', 'whatshapp':'WhatsApp', 'howhat':'how that','Whybis':'Why is', 'laowhy86':'Foreigners who do not respect China',
    'Whyco-education':'Why co-education',"Howddo":"How do", 'Howeber':'However', 'Showh':'Show',
    "Willowmagic":'Willow magic', 'WillsEye':'Will Eye', 'Williby':'will by'
}
  File "/root/anaconda3/envs/fastaiv3/lib/python3.6/site-packages/flashtext/keyword.py", line 665, in replace_keywords
    current_word += orig_sentence[idy]
IndexError: string index out of range
f_misspell = KeywordProcessor()
for k,v in mis_spell_mapping.items(): 
    f_misspell[k] = v

def spacing_some_connect_words(text): 
    return f_misspell.replace_keywords(text)
df['abc'] = df['abc'].apply(spacing_some_connect_words)
AdityaSoni19031997 commented 5 years ago

Never mind, I guess I probably found the fix! (Will update) Thanks again for the lib :)

vi3k6i5 commented 5 years ago

Welcome.

On Thu, Apr 25, 2019, 9:30 PM Aditya Soni notifications@github.com wrote:

Never mind, I guess I found the fix! Thanks again for the lib :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vi3k6i5/flashtext/issues/79#issuecomment-486734390, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXY3QVTGNGJ4EVWV4ICJYTPSHISZANCNFSM4HIOEIGQ .

AdityaSoni19031997 commented 5 years ago

The fix is https://github.com/vi3k6i5/flashtext/issues/44#issuecomment-446903401, you can make an update :)

Edit Update -> Using the fix didn't help at all but the error is at the same character as mentioned there...

flashtext fails on this