【发布时间】:2019-07-11 14:29:31
【问题描述】:
背景
我正在使用 NeuroNER http://neuroner.com/ 来标记文本数据 sample_string,如下所示。
sample_string = 'Patient Jane Candy was seen by Dr. Smith on 12/1/2000 and her number is 1111112222'
输出(使用 NeuroNER)
我的输出是字典列表dic_list
dic_list = [
{'id': 'T1', 'type': 'PATIENT', 'start': 8, 'end': 11, 'text': 'Jane'},
{'id': 'T2', 'type': 'PATIENT', 'start': 13, 'end': 17, 'text': 'Candy'},
{'id': 'T3', 'type': 'DOCTOR', 'start': 35, 'end': 39, 'text': 'Smith'},
{'id': 'T4', 'type': 'DATE', 'start': 44, 'end': 52, 'text': '12/1/2000'},
{'id': 'T5', 'type': 'PHONE', 'start': 72, 'end': 81, 'text': '1111112222'}]
传奇
id = 文本 ID
type = 正在识别的文本类型
start = 已识别文本的起始位置
end = 已识别文本的结束位置
text = 已识别的文本
目标
由于text(例如Jane)的位置由start 和end 给出,我想在我的列表@987654340 中将每个text 从dic_list 更改为**BLOCK** @
期望的输出
sample_string = 'Patient **BLOCK** **BLOCK** was seen by Dr. **BLOCK** on **BLOCK** and her number is **BLOCK**
问题
我尝试过Replacing a character from a certain index 和Edit the values in a list of dictionaries?,但它们并不是我想要的
如何实现我想要的输出?
【问题讨论】:
-
请显示您尝试使用的实际代码并解释具体是什么不起作用。
-
注意:开始和结束似乎与某些字段中“文本”的长度或文件中的位置不匹配。
-
dic_list已更新。我为混乱道歉
标签: python python-3.x list loops dictionary