我想在两个拼写错误丰富的列表中找出相似的临床术语。现在,我使用SequenceMatcher来查找最相似的内容。示例:
from difflib import SequenceMatcher
def similar(a, b):
return round(SequenceMatcher(None, a, b).ratio()*100, 1)
print similar('hypertesnion','hypertension') # 91.7
print similar('high blood pressure','hypertension') # 19.4
在第二种情况下,“高血压”和“高血压”之间的相似性很低,但它们实际上是相似的术语。还需要注意的是,在列表中,“高血压”和“高血压”都有不同的拼写。
有没有办法在这些临床术语中捕捉到相似性?
我想有两件事是必须的。首先,纠正拼写,然后将它们编码为单个术语以计算相似度。
编辑:或者,有没有办法使用同义词列表创建模型,以便将它们编码到单个术语中,如果我有一个列表样本编码,如下所示:
'hypertension' 'hypertension'
'hypertesnio' 'hypertension'
'high blood pressure' 'hypertension'
'increased blood pressure' 'hypertension'
'raised blodd presure' 'hypertension'
发布于 2018-03-06 18:54:43
您应该探索使用word2vec,以及使用它们带来的相似性、洞察力和单词之间的关系。大多数自然语言处理库都支持word2vec,我在http://bio.nlplab.org/上找到了一个针对医疗数据进行训练的模型。在医疗保健领域,可以有其他的word2vec模型可以与诸如Spacy、sklearn等库一起使用,以进行相似性匹配。
正如您已经指出的,您仍然需要单独处理拼写错误
发布于 2018-03-07 03:38:41
这是一种公认存在缺陷的方法,它采用了一系列症状,因为你可能会在临床试验中发现它们被记录下来,并将它们转换为根据某些标准可能可以接受的列表。
symptoms = [
'hyprtension',
'hi blood pressure',
'high blod pressure',
'increased blood pressure',
'bad headache',
'migraine',
'migraine headache',
'mygrain',
]
canonical_inverted_dictionary = {
'high blood pressure': 'hypertension',
'increased blood pressure': 'hypertension',
'hypersion': 'hypertension',
'migraine': 'migraine',
}
from difflib import SequenceMatcher
def mapper(raw_term, threshold=0.7):
best = 0
for term in canonical_inverted_dictionary:
ratio = SequenceMatcher(None, raw_term, canonical_inverted_dictionary[term]).ratio()
if ratio > best:
best = ratio
best_item = term
if best > threshold:
return canonical_inverted_dictionary[best_item]
for symptom in symptoms:
print (symptom, mapper(symptom))
输出是这样的:
hyprtension hypertension
hi blood pressure None
high blod pressure None
increased blood pressure None
bad headache None
migraine migraine
migraine headache None
mygrain migraine
简而言之,SequenceMatcher并不能真正胜任处理自然语言的任务。它无法辨别“高血压”和“高血压”的相似之处。然而,这段代码确实说明了一个原则。这就是说,你可以使用代码来“识别”短语,比如“嗨血压”作为“高血压”,然后使用倒排字典将它们转换成一些标准术语,比如“高血压”。
我怀疑,在许多情况下,通过使用词干拆分传入的术语,然后寻找单词的合法替代品,最后在倒排字典中查找这些单词,在实践中可能会做到这一点。
https://stackoverflow.com/questions/49116205
复制相似问题