Skip to content

Commit 637f6a7

Browse files
committed
update ch to zh
1 parent 28b61c2 commit 637f6a7

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

OpenHowNet/Standards.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, use_sim=False):
2323
package_directory = os.path.dirname(os.path.abspath(__file__))
2424
data_dir = os.path.join(package_directory, "HowNet_dict_complete")
2525
self.en_map = dict()
26-
self.ch_map = dict()
26+
self.zh_map = dict()
2727
self.ids = dict()
2828

2929
# load dict complete
@@ -33,13 +33,13 @@ def __init__(self, use_sim=False):
3333
for key in word_dict:
3434
now_dict = word_dict[key]
3535
en_word = now_dict["en_word"].strip()
36-
ch_word = now_dict["ch_word"].strip()
36+
zh_word = now_dict["zh_word"].strip()
3737
if en_word not in self.en_map:
3838
self.en_map[en_word] = list()
3939
self.en_map[en_word].append(now_dict)
40-
if ch_word not in self.ch_map:
41-
self.ch_map[ch_word] = list()
42-
self.ch_map[ch_word].append(now_dict)
40+
if zh_word not in self.zh_map:
41+
self.zh_map[zh_word] = list()
42+
self.zh_map[zh_word].append(now_dict)
4343
if now_dict["No"] not in self.ids:
4444
self.ids[now_dict["No"]] = list()
4545
self.ids[now_dict['No']].append(now_dict)
@@ -70,8 +70,8 @@ def __getitem__(self, item):
7070
return res
7171
if item in self.en_map:
7272
res.extend(self.en_map[item])
73-
if item in self.ch_map:
74-
res.extend(self.ch_map[item])
73+
if item in self.zh_map:
74+
res.extend(self.zh_map[item])
7575
if item in self.ids:
7676
res.extend(self.ids[item])
7777
return res
@@ -92,8 +92,8 @@ def get(self, word, language=None):
9292
if (word in self.en_map):
9393
res = self.en_map[word]
9494
elif language == "zh":
95-
if (word in self.ch_map):
96-
res = self.ch_map[word]
95+
if (word in self.zh_map):
96+
res = self.zh_map[word]
9797
else:
9898
res = self[word]
9999
return res
@@ -103,7 +103,7 @@ def get_zh_words(self):
103103
Get all Chinese words annotated in HowNet
104104
:return: (list) All annotated Chinese words in HowNet.
105105
"""
106-
return list(self.ch_map.keys())
106+
return list(self.zh_map.keys())
107107

108108
def get_en_words(self):
109109
"""
@@ -230,9 +230,9 @@ def has(self, item, language=None):
230230
if language == "en":
231231
return item in self.en_map
232232
elif language == "zh":
233-
return item in self.ch_map
233+
return item in self.zh_map
234234

235-
return item in self.en_map or item in self.ch_map or item in self.ids
235+
return item in self.en_map or item in self.zh_map or item in self.ids
236236

237237
def get_all_sememes(self):
238238
"""

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ By default, the api will search the target word in both English and Chinese anno
9999
>>> print(len(result_list))
100100
6
101101
>>> print(result_list[0])
102-
{'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'ch_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'ch_word': '苹果', 'en_word': 'apple'}
102+
{'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'zh_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'zh_word': '苹果', 'en_word': 'apple'}
103103

104104
>>> hownet_dict.get("test_for_non_exist_word")
105105
[]
@@ -130,7 +130,7 @@ To boost the efficiency of the search process, you can specify the language of t
130130
>>> print("Number of monolingual results: ",len(result_list))
131131
Number of monolingual results: 6
132132
>>> print("Example of monolingual results: ",result_list[0])
133-
Example of monolingual results: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'ch_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'ch_word': '苹果', 'en_word': 'apple'}
133+
Example of monolingual results: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'zh_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'zh_word': '苹果', 'en_word': 'apple'}
134134

135135
>>> print("Number of all the results: ",len(hownet_dict.get("X")))
136136
Number of all the results: 5
@@ -146,8 +146,8 @@ Number of English results: 2
146146
#### Get All Words Annotated in HowNet
147147

148148
```python
149-
>>> ch_word_list = hownet_dict.get_zh_words()
150-
>>> print(ch_word_list[:30])
149+
>>> zh_word_list = hownet_dict.get_zh_words()
150+
>>> print(zh_word_list[:30])
151151
['', '"', '#', '#号标签', '$', '%', "'", '(', ')', '*', '+', '-', '--', '...', '...出什么问题', '...底', '...底下', '...发生故障', '...发生了什么', '...何如', '...家里有几口人', '...检测呈阳性', '...检测呈阴性', '...来', '...内', '...为止', '...也同样使然', '...以来', '...以内', '...以上']
152152

153153
>>> en_word_list = hownet_dict.get_en_words()
@@ -238,7 +238,7 @@ Two ways to see the corresponding annotation data
238238
>>> # two results are the same, only displaying one
239239
{'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}',
240240
'en_grammar': 'noun',
241-
'ch_grammar': 'noun',
241+
'zh_grammar': 'noun',
242242
'No': '127151',
243243
'syn': [
244244
{'id': '004024', 'text': 'IBM'},
@@ -262,7 +262,7 @@ Two ways to see the corresponding annotation data
262262
{'id': '172264', 'text': '膝上型电脑'},
263263
{'id': '172265', 'text': '膝上型电脑'}
264264
],
265-
'ch_word': '苹果',
265+
'zh_word': '苹果',
266266
'en_word': 'apple'}
267267
```
268268

@@ -298,7 +298,7 @@ The similarity metrics are based on sememes.
298298

299299
```python
300300
>>> hownet_dict["004024"]
301-
['Def', 'en_grammar', 'ch_grammar', 'No', 'syn', 'ch_word', 'en_word']
301+
['Def', 'en_grammar', 'zh_grammar', 'No', 'syn', 'zh_word', 'en_word']
302302
```
303303

304304
#### Get all sememes

README_ZH.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ hownet_dict = OpenHowNet.HowNetDict()
9393
>>> print("检索数量:",len(result_list))
9494
>>> print("检索结果范例:",result_list[0])
9595
检索数量: 6
96-
检索结果范例: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'ch_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'ch_word': '苹果', 'en_word': 'apple'}
96+
检索结果范例: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'zh_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'zh_word': '苹果', 'en_word': 'apple'}
9797

9898
>>> hownet_dict.get("test_for_non_exist_word")
9999
[]
@@ -124,7 +124,7 @@ Display #1 sememe tree
124124
>>> print("单语检索数量:",len(result_list))
125125
单语检索数量: 6
126126
>>> print("单语检索结果范例:",result_list[0])
127-
单语检索结果范例: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'ch_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'ch_word': '苹果', 'en_word': 'apple'}
127+
单语检索结果范例: {'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}', 'en_grammar': 'noun', 'zh_grammar': 'noun', 'No': '127151', 'syn': [{'id': '004024', 'text': 'IBM'}, {'id': '041684', 'text': '戴尔'}, {'id': '049006', 'text': '东芝'}, {'id': '106795', 'text': '联想'}, {'id': '156029', 'text': '索尼'}, {'id': '004203', 'text': 'iPad'}, {'id': '019457', 'text': '笔记本'}, {'id': '019458', 'text': '笔记本电脑'}, {'id': '019459', 'text': '笔记本电脑'}, {'id': '019460', 'text': '笔记本电脑'}, {'id': '019461', 'text': '笔记本电脑'}, {'id': '019463', 'text': '笔记簿电脑'}, {'id': '019464', 'text': '笔记簿电脑'}, {'id': '020567', 'text': '便携式电脑'}, {'id': '020568', 'text': '便携式计算机'}, {'id': '020569', 'text': '便携式计算机'}, {'id': '127224', 'text': '平板电脑'}, {'id': '127225', 'text': '平板电脑'}, {'id': '172264', 'text': '膝上型电脑'}, {'id': '172265', 'text': '膝上型电脑'}], 'zh_word': '苹果', 'en_word': 'apple'}
128128

129129
>>> print("混合检索结果数量:",len(hownet_dict.get("X")))
130130
混合检索结果数量: 5
@@ -140,8 +140,8 @@ Display #1 sememe tree
140140
#### 获取所有HowNet中的词语
141141

142142
```python
143-
>>> ch_word_list = hownet_dict.get_zh_words()
144-
>>> print(ch_word_list[:30])
143+
>>> zh_word_list = hownet_dict.get_zh_words()
144+
>>> print(zh_word_list[:30])
145145
['', '"', '#', '#号标签', '$', '%', "'", '(', ')', '*', '+', '-', '--', '...', '...出什么问题', '...底', '...底下', '...发生故障', '...发生了什么', '...何如', '...家里有几口人', '...检测呈阳性', '...检测呈阴性', '...来', '...内', '...为止', '...也同样使然', '...以来', '...以内', '...以上']
146146

147147
>>> en_word_list = hownet_dict.get_en_words()
@@ -232,7 +232,7 @@ Display #1 sememe tree
232232
>>> # two results are the same, only displaying one
233233
{'Def': '{computer|电脑:modifier={PatternValue|样式值:CoEvent={able|能:scope={bring|携带:patient={$}}}}{SpeBrand|特定牌子}}',
234234
'en_grammar': 'noun',
235-
'ch_grammar': 'noun',
235+
'zh_grammar': 'noun',
236236
'No': '127151',
237237
'syn': [
238238
{'id': '004024', 'text': 'IBM'},
@@ -256,7 +256,7 @@ Display #1 sememe tree
256256
{'id': '172264', 'text': '膝上型电脑'},
257257
{'id': '172265', 'text': '膝上型电脑'}
258258
],
259-
'ch_word': '苹果',
259+
'zh_word': '苹果',
260260
'en_word': 'apple'}
261261
```
262262

@@ -292,7 +292,7 @@ Display #1 sememe tree
292292

293293
```python
294294
>>> hownet_dict["004024"]
295-
['Def', 'en_grammar', 'ch_grammar', 'No', 'syn', 'ch_word', 'en_word']
295+
['Def', 'en_grammar', 'zh_grammar', 'No', 'syn', 'zh_word', 'en_word']
296296
```
297297

298298
#### 获取所有义原

0 commit comments

Comments
 (0)