【问题标题】:How to modify an identified noun phrase A to B or C--->A to B or A to C in Spacy, Regular Expression python如何在Spacy,正则表达式python中修改已识别的名词短语A到B或C--->A到B或A到C
【发布时间】:2021-07-04 01:04:50
【问题描述】:

我已经使用 spaCy 基于规则的匹配器识别了名词短语 A 到 B 或 C。但是,我想修改得到的结果:

A to B or C--->A to B or A to C

并确保原意正确。

如何在 python 中通过使用正则表达式 + spacy 或 nltk 或其他有帮助的方法来做到这一点?

谢谢!

【问题讨论】:

    标签: python regex nltk spacy


    【解决方案1】:

    我会使用re.sub 如下:

    inp = "A to B or C"
    output = re.sub(r'\b(\S+) to (\S+) or (\S+)\b', r'\1 to \2 or \1 to \3', inp)
    print(output)  # A to B or A to C
    

    【讨论】:

    • 谢谢,为什么我只在IDE中输入这三行加上“import re”没有得到任何输出?
    • @Nina 不知道,我在演示工具中运行了我的代码,它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2019-04-01
    • 2014-09-20
    相关资源
    最近更新 更多