Issue
a = "The process maps are similar to Manual Excellence Process Framework (MEPF)"
input = "The process maps are similar to Manual Excellence Process Framework (MEPF)"
output = Manual Excellence Process Framework (MEPF)
I want to write a python scripts where I have that piece of text, from that I want to extract full for of given acronyms inside the brackets (MEPF)
and full form is Manual Excellence Process Framework
I want to append only full from by match each uppercase letter from inside the brackets.
my idea was when ever acronyms appears inside the bracket that will map each capital letter for example (MEPF) starting from last Letter F that will match last word befoure the bracket here it is Framwork, then P (Pocess) then E(Excellence ) finaly M (manual) so final output will be full form(Manual Excellence Process Framework) can you try once this way that will be realy helpfull for me
Solution
Using a simple regex and a bit of post-processing:
a = "I like International Business Machines (IBM). The Manual Excellence Process Framework (MEPF)"
import re
m = re.findall(r'([^)]+) \(([A-Z]+)\)', a)
out = {b: ' '.join(a.split()[-len(b):]) for a,b in m}
out
output:
{'IBM': 'International Business Machines',
'MEPF': 'Manual Excellence Process Framework'}
If you want to check the the acronym actually matches the words:
out = {b: ' '.join(a.split()[-len(b):]) for a,b in m
if all(x[0]==y for x,y in zip(a.split()[-len(b):], b))
}
example
a = "No match (ABC). I like International Business Machines (IBM). The Manual Excellence Process Framework (MEPF)."
m = re.findall(r'([^)]+) \(([A-Z]+)\)', a)
{b: ' '.join(a.split()[-len(b):]) for a,b in m
if all(x[0]==y for x,y in zip(a.split()[-len(b):], b))
}
# {'IBM': 'International Business Machines',
# 'MEPF': 'Manual Excellence Process Framework'}
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.