|
2 | 2 | HowNetDict Class |
3 | 3 | ================= |
4 | 4 | """ |
5 | | - |
6 | | -import os |
7 | 5 | import pickle |
8 | | -import sys |
9 | | -from typing import Dict, Any |
10 | | - |
11 | | -from anytree import Node, RenderTree |
12 | | -from anytree.exporter import DictExporter, JsonExporter |
13 | 6 |
|
14 | 7 | from .Sense import Sense |
15 | 8 | from .Sememe import Sememe |
@@ -44,9 +37,8 @@ def __init__(self, init_sim=False, init_babel=False): |
44 | 37 | init_babel (`bool`) : whether to initialize the BabelNet synest search module. |
45 | 38 | ''' |
46 | 39 | try: |
47 | | - package_directory = os.path.dirname(os.path.abspath(__file__)) |
48 | | - sememe_dir, sememe_triples_dir, data_dir = [os.path.join(package_directory, file_name) for file_name in [ |
49 | | - 'resources/sememe_all', 'resources/sememe_triples_taxonomy.txt', 'resources/HowNet_dict_complete']] |
| 40 | + sememe_dir, sememe_triples_dir, data_dir = [ |
| 41 | + 'resources/sememe_all', 'resources/sememe_triples_taxonomy.txt', 'resources/HowNet_dict_complete'] |
50 | 42 |
|
51 | 43 | # Initialize sememe list from sememe_all. |
52 | 44 | self.sememe_dic = dict() |
@@ -497,18 +489,15 @@ def initialize_similarity_calculation(self): |
497 | 489 | Implementation is contributed by Jun Yan, which is based on the paper : |
498 | 490 | "Jiangming Liu, Jinan Xu, Yujie Zhang. An Approach of Hybrid Hierarchical Structure for Word Similarity Computing by HowNet. In Proceedings of IJCNLP" |
499 | 491 | """ |
500 | | - sememe_sim_table_pickle_path = 'resources/sememe_sim_table' |
501 | | - sense_tree_path = 'resources/sense_tree' |
502 | | - sense_syn_path = 'resources/synonym' |
| 492 | + sememe_sim_table_pickle_path, sense_tree_path, sense_syn_path = ['resources/sememe_sim_table', 'resources/sense_tree', 'resources/synonym'] |
503 | 493 |
|
504 | | - package_directory = os.path.dirname(os.path.abspath(__file__)) |
505 | 494 | try: |
506 | 495 | self.sememe_sim_table = pickle.load( |
507 | | - get_resource(os.path.join(package_directory, sememe_sim_table_pickle_path), "rb")) |
| 496 | + get_resource(sememe_sim_table_pickle_path, "rb")) |
508 | 497 | self.sense_tree_dic = pickle.load( |
509 | | - get_resource(os.path.join(package_directory, sense_tree_path), 'rb')) |
| 498 | + get_resource(sense_tree_path, 'rb')) |
510 | 499 | self.sense_syn_dic = pickle.load( |
511 | | - get_resource(os.path.join(package_directory, sense_syn_path), 'rb')) |
| 500 | + get_resource(sense_syn_path, 'rb')) |
512 | 501 | except FileNotFoundError as e: |
513 | 502 | print( |
514 | 503 | "Enabling Word Similarity Calculation requires specific data files, please check the completeness of your download package.") |
@@ -718,10 +707,9 @@ def initialize_babelnet_dict(self): |
718 | 707 | """Initialize the BabelNet Synset dict. |
719 | 708 | """ |
720 | 709 | babel_data_path = 'resources/babel_data' |
721 | | - package_directory = os.path.dirname(os.path.abspath(__file__)) |
722 | 710 | try: |
723 | 711 | babel_synset_list = pickle.load( |
724 | | - get_resource(os.path.join(package_directory, babel_data_path), "rb")) |
| 712 | + get_resource(babel_data_path, "rb")) |
725 | 713 |
|
726 | 714 | self.synset_dic = {} |
727 | 715 | self.en_synset_dic = {} |
|
0 commit comments