简体   繁体   English

如何通过映射每个大写字母仅提取括号内首字母缩略词后的缩写

[英]How do i extract only abbreviation following acronyms inside the brackets by mapping each Capital letter

 a = "The process maps are similar to Manual Excellence Process Framework (MEPF)"

input = "The process maps are similar to Manual Excellence Process Framework (MEPF)" input = "流程图类似于手动卓越流程框架 (MEPF)"

output = Manual Excellence Process Framework (MEPF) output = 手动卓越流程框架 (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.我想编写一个 python 脚本,其中我有那段文本,我想从中提取完整的括号内的给定首字母缩略词(MEPF) ,完整形式是Manual Excellence Process Framework我想要 append 仅从匹配每个括号内的大写字母。

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我的想法是,当括号内出现首字母缩略词时,将 map 每个大写字母(例如,MEPF)从最后一个字母 F 开始,匹配括号前的最后一个单词,这里是框架,然后是 P(Pocess),然后是 E(Excellence) M (manual) so final output will be full form(Manual Excellence Process Framework) 你能试试这种方式对我很有帮助吗

i make your question as a challenge i am a beginner so i hope to be this answer useful for you and thank you for you question:我把你的问题作为一个挑战我是一个初学者,所以我希望这个答案对你有用,谢谢你的问题:

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)

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: 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'}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当且仅当前一个字母不是大写字母时,才如何在大写字母前插入空格? - How do I insert space before capital letter if and only if previous letter is not capital? 如何使用正则表达式提取第二个大写字母后的所有文本(数字、字母、符号)? - How do I extract with regex all the text (numbers, letters, symbols) after the second capital letter? 如何在 python 中使用 ascii 仅将首字母更改为大写 - How do I only change first letter into a capital using ascii in python 如何获得每个字母的协调并提取一个numpy数组中的字母? - How do I get the coordination of each letter and also extract the letter in a numpy array? 如何让我的代码将其中包含大写字母的单词的首字母大写? (猪拉丁语) - How do I make my code capitalize the first letter of the word that has a capital letter in it? (Pig Latin) 如何在Python中获取第一个大写字母,然后再获取每个不跟另一个大写字母的字母? - How to get the first capital letter and then each that isn't followed by another capital letter in Python? 如何根据序列中的大写字母提取起点和终点? - How to extract start and end sites based on capital letter in a sequence? 我可以将“用户名”中的字母更改为大写字母,并使用相同的用户名进行注册。 我该如何解决? - I'm able to change a letter in “username” to a capital letter and register still with the same username. How do I fix this? 如何用“*”替换以下出现的第一个字母? - How do I replace the following occurrences of the first letter with a "*"? 根据字母数和长度提取带括号的首字母缩写词和缩写词 - Extract parenthesized acronyms and abbreviations based on letter count and length
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM