簡體   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 = "流程圖類似於手動卓越流程框架 (MEPF)"

output = 手動卓越流程框架 (MEPF)

我想編寫一個 python 腳本,其中我有那段文本,我想從中提取完整的括號內的給定首字母縮略詞(MEPF) ,完整形式是Manual Excellence Process Framework我想要 append 僅從匹配每個括號內的大寫字母。

我的想法是,當括號內出現首字母縮略詞時,將 map 每個大寫字母(例如,MEPF)從最后一個字母 F 開始,匹配括號前的最后一個單詞,這里是框架,然后是 P(Pocess),然后是 E(Excellence) M (manual) so final output will be full form(Manual Excellence Process Framework) 你能試試這種方式對我很有幫助嗎

我把你的問題作為一個挑戰我是一個初學者,所以我希望這個答案對你有用,謝謝你的問題:

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)

使用一個簡單的正則表達式和一些后處理:

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

如果要檢查首字母縮寫詞是否與單詞匹配:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM