[英]How to modify an identified noun phrase A to B or C--->A to B or A to C in Spacy, Regular Expression python
I have identified the noun phrase A to B or C by using spaCy rule-based matcher.我使用基于 spaCy 规则的匹配器识别了名词短语 A 到 B 或 C。 However, I want to modify the obtained result:
但是,我想修改获得的结果:
A to B or C--->A to B or A to C
And make sure that the original meaning is correct.并确保原意是正确的。
How can I do this in python by using regular expression + spacy or nltk or anything else is helpful?如何在 python 中通过使用正则表达式 + spacy 或 nltk 或其他有帮助的方法来做到这一点?
Thanks!谢谢!
I would use re.sub
as follows:我会使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.