如何从包含数值的段落中提取句子。有一个约束。数值应介于 0 到 85 之间
How to extract sentences from the paragraph which contains numeric value. There is one constraint. The numeric value should be between 0 To 85
我需要 python 的正则表达式模式。或者,如果您有任何其他方法,请随时分享。
我已经编写了用于提取仅提取数值的句子的正则表达式(模式:([^.]*?\d+[^.]*\.))。但是我不知道如何限制那个数值。
只提取数值句子的模式([^.]*?\d+[^.]*\.)
示例:
The patient is suffering from fever. Their relatives come to visit them. The patient age is 20 year. His brother could not visit him due to some other work. There is another patient whose age is 30 year old. The second patient is watching him from window.
输出:
['The patient age is 20 year', 'There is another patient whose age is 30 year old']
如果我们假设句点只会出现在句子的结尾,那么以下方法可能会奏效:
inp = 'The patient is suffering from fever. Their relatives come to visit them. The patient age is 20 year. His brother could not visit him due to some other work. There is another patient whose age is 30 year old. The second patient is watching him from window.'
matches = re.findall(r'\s*([^.]*\b(?:[1-7]?[0-9]|8[0-5])\b[^.]*\.)', inp)
print(matches)
这会打印:
['The patient age is 20 year.', 'There is another patient whose age is 30 year old.']
请注意,正则表达式的 (?:[1-7]?[0-9]|8[0-5])
部分匹配 0 到 85(含)。
我需要 python 的正则表达式模式。或者,如果您有任何其他方法,请随时分享。
我已经编写了用于提取仅提取数值的句子的正则表达式(模式:([^.]*?\d+[^.]*\.))。但是我不知道如何限制那个数值。
只提取数值句子的模式([^.]*?\d+[^.]*\.)
示例:
The patient is suffering from fever. Their relatives come to visit them. The patient age is 20 year. His brother could not visit him due to some other work. There is another patient whose age is 30 year old. The second patient is watching him from window.
输出:
['The patient age is 20 year', 'There is another patient whose age is 30 year old']
如果我们假设句点只会出现在句子的结尾,那么以下方法可能会奏效:
inp = 'The patient is suffering from fever. Their relatives come to visit them. The patient age is 20 year. His brother could not visit him due to some other work. There is another patient whose age is 30 year old. The second patient is watching him from window.'
matches = re.findall(r'\s*([^.]*\b(?:[1-7]?[0-9]|8[0-5])\b[^.]*\.)', inp)
print(matches)
这会打印:
['The patient age is 20 year.', 'There is another patient whose age is 30 year old.']
请注意,正则表达式的 (?:[1-7]?[0-9]|8[0-5])
部分匹配 0 到 85(含)。