I have a sentence and an array of texts.
sentence = 'Hi I am fine. how are you'
arrayOfTexts = ['Hi','I am','how','how are','how are you']
replacedText = '** * ** fine. *** *** ***'
So what I want to do here, I want to compare the sentence words that are matched with an array of text values and replace them with stars ' * '.
Conditions:
- The first preference to replace the words is higher when multiple words are matching rather than single. Exp:
how are you
to replace withhow are you
nothow
norhow are
. You can think as higher grams replace first. - Currently, I only want up to 4 grams (4 pairs).
My solution I am converting my sentence up to 4 grams and search every pair one by one but I think its a little bit redundant.
sentenceArray = ['Hi I am fine', 'I am fine .', 'am fine . how', 'fine . how are', '. how are you','Hi I am', 'I am fine', 'am fine .', 'fine . how', '. how are', 'how are you','Hi I', 'I am', 'am fine', 'fine .', '. how', 'how are', 'are you','Hi', 'I', 'am', 'fine', '.', 'how', 'are', 'you']
My Question Is there any better way to solve this problem?