def _get_grounding(entity):
    db_refs = {'TEXT': entity['text']}
    groundings = entity.get('grounding')
    if not groundings:
        return db_refs
    def get_ont_concept(concept):
        if concept.startswith('/'):
            concept = concept[1:]
            concept = concept.replace(' ', '_')
            while concept not in hume_onto_entries:
                parts = concept.split('/')
                if len(parts) == 1:
                    break
                concept = '/'.join(parts[:-1])
        return concept
    raw_grounding_entries = [(get_ont_concept(g['ontologyConcept']),
                              g['value']) for g in groundings]
    grounding_dict = {}
    for cat, score in raw_grounding_entries:
        if (cat not in grounding_dict) or (score > grounding_dict[cat]):
            grounding_dict[cat] = score
    grounding_entries = sorted(list(set(grounding_dict.items())),
                               key=lambda x: (x[1], x[0].count('/'), x[0]),
                               reverse=True)
    if grounding_entries:
        db_refs['HUME'] = grounding_entries
    return db_refs