【问题标题】:How do i extract only abbreviation following acronyms inside the brackets by mapping each Capital letter如何通过映射每个大写字母仅提取括号内首字母缩略词后的缩写
【发布时间】:2022-01-25 11:07:13
【问题描述】:
 a = "The process maps are similar to Manual Excellence Process Framework (MEPF)"

input = "流程图类似于手动卓越流程框架 (MEPF)"

输出 = 手动卓越流程框架 (MEPF)

我想编写一个 python 脚本,其中我有那段文本,我想从中提取完整的括号内给定的首字母缩略词 (MEPF) 和完整形式是 Manual Excellence Process Framework 我只想从 by匹配括号内的每个大写字母。

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

【问题讨论】:

  • 您期望的确切输出是什么?
  • input = "流程图类似于手动卓越流程框架 (MEPF)" 输出 = 手动卓越流程框架 (MEPF)
  • 输入将是任何句子或段落,输出将是括号内大写字母首字母缩写词的缩写输入=“流程图类似于手动卓越流程框架(MEPF)”输出=手动卓越流程框架(MEPF)

标签: python python-3.x text nlp artificial-intelligence


【解决方案1】:

我把你的问题作为一个挑战我是一个初学者,所以我希望这个答案对你有用,谢谢你的问题:

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)

【讨论】:

  • 非常感谢您的输入,我的想法是,当括号内出现首字母缩略词时,它将映射每个大写字母,例如(MEPF),从最后一个字母 F 开始,将匹配括号前的最后一个单词这里是框架,然后是 P(流程),然后是 E(卓越),最后是 M(手动),所以最终输出将是完整的形式(手动卓越流程框架)你可以尝试一次这种方式,这对我很有帮助
  • 我尝试了示例文本 a = "CCI 已通过了针对 United Breweries Ltd (UBL)、SABMiller India Ltd(现更名为 Anheuser Busch InBev India Ltd (AB InBev) 和 Carlsberg)的最终命令印度私人有限公司(CIPL)等实体。”我得到了不同的输出。有点没想到。
【解决方案2】:

使用简单的正则表达式和一些后处理:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-21
    • 2019-08-25
    • 1970-01-01
    • 2021-07-26
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多