diff --git a/code/ARAX/NodeSynonymizer/node_synonymizer.py b/code/ARAX/NodeSynonymizer/node_synonymizer.py index 0d24cf247..aafe89f3b 100644 --- a/code/ARAX/NodeSynonymizer/node_synonymizer.py +++ b/code/ARAX/NodeSynonymizer/node_synonymizer.py @@ -7,6 +7,7 @@ import string import sys import time +import math from collections import defaultdict, Counter from typing import Optional, Union, List, Set, Dict, Tuple @@ -403,6 +404,17 @@ def get_normalizer_results(self, entities: Optional[Union[str, Set[str], List[st if normalizer_info: normalizer_info["knowledge_graph"] = self._get_cluster_graph(normalizer_info) + # Attempt to squash NaNs, which are not legal in JSON. Turn them into nulls + if 'knowledge_graph' in normalizer_info and 'edges' in normalizer_info["knowledge_graph"]: + for edge_name, edge_data in normalizer_info["knowledge_graph"]['edges'].items(): + if 'attributes' in edge_data: + for attribute in edge_data['attributes']: + try: + if 'value' in attribute and math.isnan(attribute['value']): + attribute['value'] = None + except: + pass + if debug: print(f"Took {round(time.time() - start, 5)} seconds") return results_dict