From 783b04be1e3712ae4595cc6c73ebfb6328cc398f Mon Sep 17 00:00:00 2001 From: William Hayes Date: Fri, 13 Nov 2020 15:16:02 -0500 Subject: [PATCH] fixed naked nsarg species bug --- bel/resources/namespace.py | 16 +++++++++++----- bel/terms/terms.py | 9 +++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bel/resources/namespace.py b/bel/resources/namespace.py index aea237e..6dd74fc 100644 --- a/bel/resources/namespace.py +++ b/bel/resources/namespace.py @@ -218,9 +218,9 @@ def terms_iterator_for_arangodb(f: IO, version: str): term_key = term["key"] namespace = term["namespace"] - species_id = term.get("species_id", None) - # Skip if species not listed in species_list - if species_list and species_id and species_id not in species_list: + # Skip if species not listed in config species_list + species_key = term.get("species_key", None) + if species_list and species_key and species_key not in species_list: continue # Can't use original key formatted for Arangodb as some keys are longer than allowed (_key < 255 chars) @@ -346,8 +346,8 @@ def terms_iterator_for_elasticsearch(f: IO, index_name: str, statistics: dict): ns, id_ = equivalence.split(":", 1) statistics["equivalenced_namespaces"][ns] += 1 - # Filter species if enabled in config - species_key = term.get("species_key", "") + # Skip if species not listed in config species_list + species_key = term.get("species_key", None) if species_list and species_key and species_key not in species_list: continue @@ -362,6 +362,12 @@ def terms_iterator_for_elasticsearch(f: IO, index_name: str, statistics: dict): term.pop("parent_keys", "") term.pop("equivalence_keys", "") + # Must not have species_key attribute to allow naked NSArg queries with filtered species + # but allow non-species terms to be matched as well + if term.get("species_key", "") == "": + term.pop("species_key") + term.pop("species_label") + record = { "_op_type": "index", "_index": index_name, diff --git a/bel/terms/terms.py b/bel/terms/terms.py index 407de18..9c00e8e 100644 --- a/bel/terms/terms.py +++ b/bel/terms/terms.py @@ -338,11 +338,12 @@ def get_term_completions( if entity_types: grp = [et for et in entity_types if et in settings.species_entity_types] - if grp and species_keys: - if isinstance(species_keys, str): - species_keys = [species_keys] + if isinstance(species_keys, str): + species_keys = [species_keys] - # Allow non-species specific terms to be found + # Allow non-species specific terms to be found along with species=[species_keys] + # grp is set if inside a function and if not entity_types and annotation_types are None + if species_keys and (grp or (not entity_types and not annotation_types)): filters.append( { "bool": {