I have sentences.
text="The president of America is <PERSON>Barack Obama</PERSON>. He was born on August 4, 1961. Obama was reelected president in November 2012".
I want to put <PERSON></PERSON> tag in "Obama", so the result will be like this:
The president of America is <PERSON>Barack Obama</PERSON>. He was born on August 4, 1961. <PERSON>Obama</PERSON> was reelected president in November 2012".
I want to find substring(example: Obama) that there is no tag <PERSON> before the substring and there is no tag </PERSON> after the substring, but I don't know the right syntax for regex in python.
**I'm new to python :''
With simple regex re.sub(namedEntity, "<PERSON>"+namedEntity+"</PERSON>", text) will give an output
The president of America is <PERSON>Barack <PERSON>Obama</PERSON></PERSON>. He was born on August 4, 1961. <PERSON>Obama</PERSON> was reelected president in November 2012".
this is my code(using python2.7)
import re
result=re.sub(r"((?!<PERSON>).*"+namedEntity+".*(?!</PERSON>))","<PERSON>"+namedEntity+"</PERSON>",text)
print "result: "+result
The output
result: <PERSON>Obama</PERSON>
And I don't know that is the first "Obama" or the second one.
Thanks for your help before