Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion medcat-trainer/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ volumes:
networks:
gateway-auth_gateway-net:
name: ${MCT_GATEWAY_NETWORK_NAME:-gateway-auth_gateway-net}
external: true
# external: true # Uncomment if using an existing gateway auth network.
67 changes: 34 additions & 33 deletions medcat-trainer/webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,45 +777,46 @@ def annotate_text(request):
logger.warning(f'Failed to get children for CUI {parent_cui}: {e}')
cuis_set = expanded_cuis

with temp_changed_config(cat.config.components.linking, 'filters', cuis_set):
with temp_changed_config(cat.config.components.linking.filters, 'cuis', cuis_set):
spacy_doc = cat(message)

ents = []
anno_tkns = []
for ent in spacy_doc.linked_ents:
cnt = Entity.objects.filter(label=ent.cui).count()
inc_ent = all(tkn not in anno_tkns for tkn in ent)
if inc_ent and cnt != 0:
meta_annotations = []
if 'meta_cat_meta_anns' in ent.get_available_addon_paths():
meta_anns = ent.get_addon_data('meta_cat_meta_anns')
for meta_ann_task, pred in meta_anns.items():
# Extract value and confidence from pred
# pred can be a dict, object, or string
if isinstance(pred, dict):
pred_value = pred.get('value', str(pred))
pred_confidence = pred.get('confidence', None)
elif hasattr(pred, 'value'):
pred_value = pred.value
pred_confidence = getattr(pred, 'confidence', None)
else:
pred_value = str(pred)
pred_confidence = None
meta_annotations.append({
'task': meta_ann_task,
'value': pred_value,
'confidence': pred_confidence
})
anno_tkns.extend([tkn for tkn in ent])
entity = Entity.objects.get(label=ent.cui)
ents.append({
'entity': entity.id,
'value': ent.base.text,
'start_ind': ent.base.start_char_index,
'end_ind': ent.base.end_char_index,
'acc': ent.context_similarity,
'meta_annotations': meta_annotations
})
if not inc_ent:
continue
meta_annotations = []
if 'meta_cat_meta_anns' in ent.get_available_addon_paths():
meta_anns = ent.get_addon_data('meta_cat_meta_anns')
for meta_ann_task, pred in meta_anns.items():
# Extract value and confidence from pred
# pred can be a dict, object, or string
if isinstance(pred, dict):
pred_value = pred.get('value', str(pred))
pred_confidence = pred.get('confidence', None)
elif hasattr(pred, 'value'):
pred_value = pred.value
pred_confidence = getattr(pred, 'confidence', None)
else:
pred_value = str(pred)
pred_confidence = None
meta_annotations.append({
'task': meta_ann_task,
'value': pred_value,
'confidence': pred_confidence
})
anno_tkns.extend([tkn for tkn in ent])
entity = Entity.objects.filter(label=ent.cui).first()
ents.append({
'entity': entity.id if entity is not None else -1,
'cui': ent.cui,
'value': ent.base.text,
'start_ind': ent.base.start_char_index,
'end_ind': ent.base.end_char_index,
'acc': ent.context_similarity,
'meta_annotations': meta_annotations
})

ents.sort(key=lambda e: e['start_ind'])
out = {'message': message, 'entities': ents}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default {
methods: {
fetchDetail (selectedEnt, cdbSearchIndex, callback) {
if (selectedEnt && Object.keys(selectedEnt).length) {
if (selectedEnt.cui) {
this.fetchConcept(selectedEnt, cdbSearchIndex, callback)
return
}
const queryEntId = selectedEnt.id
this.$http.get(`/api/entities/${selectedEnt.entity}/`).then(resp => {
if (selectedEnt && queryEntId === selectedEnt.id) {
Expand Down