a = "The process maps are similar to Manual Excellence Process Framework (MEPF)"input =“过程图类似于手工卓越过程框架(MEPF)”
产出=人工卓越流程框架(MEPF)
我想在这里编写一个python脚本,其中我有一段文本,我想从中提取方括号(MEPF)中给定的缩略词的完整,而完整的表单是Manual Excellence Process Framework,我只想通过匹配括号中的每个大写字母来追加Manual Excellence Process Framework。
我的想法是,当缩略词出现在括号内时--例如,从最后一个字母F开始映射每个大写字母(MEPF) --这里的括号是Framwork,然后是P (Pocess),最后是M(手动),所以最终输出将是完全形式的(手动卓越过程框架),您能尝试一下这种方法吗?
发布于 2021-12-25 10:55:03
使用简单的正则表达式和一些后处理:
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产出:
{'IBM': 'International Business Machines',
'MEPF': 'Manual Excellence Process Framework'}如果您想检查首字母缩写是否与单词实际匹配:
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))
}示例
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'}发布于 2021-12-25 10:42:52
我把你的问题作为一个挑战,我是一个初学者,所以我希望这个答案对你有用,并感谢你的提问:
a = "process maps are similar to Manual Excellence Process
Framework (MEPF)"
full = ''
ind = a.index('(')
ind2 = a.index(')')
acr = a[ind+1:ind2]
for i in a.split():
for j in range (len(acr)):
if acr[j] == i[0] and len(i) > 1:
word = i
full = full + word + ' '
print(full)https://stackoverflow.com/questions/70479299
复制相似问题