コード例 #1
0
def load_dictionary(dictionary_path):
    """
    load dictionary
    
    Parameters
    ----------
    dictionary_path : str
        a path of dictionary
    """
    dictionary = DictionaryDataset(dictionary_path=dictionary_path)

    return dictionary.data
コード例 #2
0
def cache_or_load_dictionary():
    dictionary_name = os.path.splitext(os.path.basename(
        args.dictionary_path))[0]

    cached_dictionary_path = os.path.join(
        './tmp', "cached_{}.pk".format(dictionary_name))

    # If exist, load the cached dictionary
    if os.path.exists(cached_dictionary_path):
        with open(cached_dictionary_path, 'rb') as fin:
            cached_dictionary = pickle.load(fin)
        print("Loaded dictionary from cached file {}".format(
            cached_dictionary_path))

        dictionary, dict_sparse_embeds, dict_dense_embeds = (
            cached_dictionary['dictionary'],
            cached_dictionary['dict_sparse_embeds'],
            cached_dictionary['dict_dense_embeds'],
        )

    else:
        dictionary = DictionaryDataset(
            dictionary_path=args.dictionary_path).data
        dictionary_names = dictionary[:, 0]
        dict_sparse_embeds = biosyn.embed_sparse(names=dictionary_names,
                                                 show_progress=True)
        dict_dense_embeds = biosyn.embed_dense(names=dictionary_names,
                                               show_progress=True)
        cached_dictionary = {
            'dictionary': dictionary,
            'dict_sparse_embeds': dict_sparse_embeds,
            'dict_dense_embeds': dict_dense_embeds
        }

        if not os.path.exists('./tmp'):
            os.mkdir('./tmp')
        with open(cached_dictionary_path, 'wb') as fin:
            pickle.dump(cached_dictionary, fin)
        print("Saving dictionary into cached file {}".format(
            cached_dictionary_path))

    return dictionary, dict_sparse_embeds, dict_dense_embeds
コード例 #3
0
ファイル: eval.py プロジェクト: soochem/BioSyn
def load_dictionary(dictionary_path):
    dictionary = DictionaryDataset(dictionary_path=dictionary_path)
    return dictionary.data