'Python compare two masked strings and return one masked string

I'm working on a PII detection project. Right now, I have a set of different Regex rules and keyword replacements which return the first version of a masked string. For example:

Ik <NAAM> te bereiken op <EMAIL> en woon in <PLAATS>. Mijn adres is <ADRES> <GETAL>, <POSTCODE>. 
Mijn naam is <NAAM>. Dit is het IBAN van de Rabobank: <IBAN>. 

After this, I want to apply NLP entity tagging which possibly results in even more tags. For example:

Ik <PERSON> ben te bereiken op <URL> en woon in <GPE>. Mijn adres is <FAC> <NUM>, <NUM>. 
Mijn naam is <PERSON>. Dit is het IBAN van de <ORG>: <IBAN>. 

I want to combine the two and prefer the tags of the first string but enrich that string with the extra tags from the second one. So the result will be:

Ik <NAAM> te bereiken op <EMAIL> en woon in <PLAATS>. Mijn adres is <ADRES> <GETAL>, <POSTCODE>. 
Mijn naam is <NAAM>. Dit is het IBAN van de <ORG>: <IBAN>. 

The extra tag in this case is the last <ORG>

Any help on how to achieve this using Python will be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source