def wrapper(*args, **kwargs): with open(os.path.join(DATA_DIR, data_name), 'rb') as f: data = func(json.loads(f.read()), *args, **kwargs) if should_cache: cache(data, os.path.join( OUTPUT_DIR, data_name.split(".")[0] + ".p") ) return data
def create_trie(): dictionary = load(os.path.join(OUTPUT_DIR, "element_data.p")) # read dictionary file into a trie trie = TrieNode() words = [] for key in dictionary: words += key.split(" ") for key in set(words): trie.insert(key) for key in SYMBOL_MAPPING.keys(): trie.insert(key) cache(trie, os.path.join(OUTPUT_DIR, "trie.p"))
for key, value in result.iteritems()) return dict((" ".join(sorted(set(key.split(" ")))), value) for key, value in result.iteritems()) def parse_out_isotopes(data): for key, value in data.iteritems(): if key in ELEMENT_MAPPING: isotopes = [] for k in value.keys(): try: val = int(str(k)) assert val == float(str(k)) isotopes.append((k, value.pop(k))) except: pass if isotopes: data[key]["isotopes"] = dict(isotopes) return data if __name__ == "__main__": result = merge_dicts( load(os.path.join(OUTPUT_DIR, "atomic_ionization_output.p")), load(os.path.join(OUTPUT_DIR, "atomic_weight_compositions.p"))) look_up = get_the_big_dict(parse_out_isotopes(result)) print "\n".join(look_up.keys()) print look_up["hydrogen"] cache(look_up, os.path.join(OUTPUT_DIR, "element_data.p"))