0

Is there Anyway I can replace nouns from one strings to another. Like I have 2 strings

e.g.

original = "his name is Javed Aaqib.He lives in Karachi"

gen = " They call him Aab Khan. His residence is in Karachi."

Now here I want to replace fake noun (Aab Khan) with original noun (Javed Aaqib) i.e. after replacing gen should be "They call him Javed Aaqib"

I have extracted Named Entities using spacy but stuck in logic how to match the fake names them as there are multiple nouns in text.

Harshana
  • 5,151
  • 1
  • 17
  • 27

1 Answers1

0

You can use the solution here in the best response as part of your solution.

At the end of the code on link above add:

person_names = filter(lambda x: 'PERSON' in x[1], named_entities_str_tag)
print(person_names)

person_names will be a list of persons name on the sentence, in your case it'll be only one, for you to replace with the desired one.

  • actually i dont have a signal name i have vast variety of name, its basically from news so can be anything. btw I have used spacy to extract name entities then applied some logics in case of multiple names – Ashba jawed Nov 30 '20 at 11:42