|
colors = { |
|
'GeneOrGeneProduct': '#aad4aa', |
|
'DiseaseOrPhenotypicFeature': '#f8b400', |
|
'ChemicalEntity': '#a4c2f4', |
|
'OrganismTaxon': '#ffb6c1', |
|
'SequenceVariant': '#e2b0ff', |
|
'CellLine': '#ffcc99' |
|
} |
|
|
|
def annotate_sentence(sentence, predictions): |
|
output = [] |
|
i = 0 |
|
for p in predictions: |
|
|
|
if sentence[i:p['start']] != '': |
|
output.append(sentence[i:p['start']]) |
|
|
|
|
|
if sentence[p['start']:p['end']] != '': |
|
output.append( |
|
(sentence[p['start']:p['end']], p['entity_group'], colors[p['entity_group']]) |
|
if p['entity_group'] != 'null' |
|
else sentence[p['start']:p['end']] |
|
) |
|
|
|
i = p['end'] |
|
|
|
|
|
if sentence[i:] != '': |
|
output.append(sentence[p['end']:]) |
|
return output |