如何使用正则表达式在Python中查找定义?

问题描述

这是我的教授给我们提供的线索:

text = '''I make my own cheese. Cheese is a dairy product,derived from milk and produced in wide ranges of flavors,textures and forms by coagulation of the milk protein casein. I personally really love cheese. Casein: a family of related phosphoproteins. These proteins are commonly found in mammalian milk'''

for r in re.finditer('\w+',text):  #Here,I would split my text into sentences
    word = r.group(0)
    if re.search(r'lly\b',word): #Here,I would identify a type of sentence
        print(word)
    if re.search(r'tion\b',word):   #Here,I would identify another type of sentence
        print(word)

基本上,我从自己的文本中收集到的是两种定义:一个集成在句子中的单词,通常后跟一个描述性动词(“ Cheese is ...”),另一个是定义的单词,后跟一个冒号及其定义词(发明的单词?)(“ Casein:[... ]“)。我整个星期都在绞尽脑汁,试图找到一种方法来提取和打印这些句子而没有任何运气。作为一个语言专业的专业人士,我们将不胜感激。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...