
OpenHownet API는 Hownet에서 정보를 검색하고, Sememe 트리 표시, Semememe을 통해 단어 유사성을 계산하는 편리한 방법을 제공하는 Thunlp에 의해 개발되었습니다. 또한 웹 사이트를 방문하여 온라인으로 단어의 검색 및 전시를 즐기십시오.
연구에서 OpenHownet에서 제공 한 데이터 또는 API를 사용하는 경우 다음 논문을 인용하십시오.
@article{qi2019openhownet,
title={OpenHowNet: An Open Sememe-based Lexical Knowledge Base},
author={Qi, Fanchao and Yang, Chenghao and Liu, Zhiyuan and Dong, Qiang and Sun, Maosong and Dong, Zhendong},
journal={arXiv preprint arXiv:1901.09957},
year={2019},
}
Hownet은 가장 일반적인 Sememe 지식 기반입니다. Sememe은 언어학의 최소 의미 단위로 정의되며 일부 언어 학자들은 모든 언어에서 모든 단어의 의미가 제한된 정액 세트로 표시 될 수 있다고 생각합니다. Zhendong Dong과 그의 아들 Qiang Dong 은이 아이디어를 실천했으며 거의 30 년 동안 Hownet을 구축하는 데 약 2,000 개의 신분증을 정의하고 20 만 개 이상의 영어와 중국어 단어를 주석을 달아주었습니다.
Hownet이 구성되었으므로 다양한 NLP 작업에 널리 사용되었습니다. 이 논문 목록을 참조하여 모든 Hownet 관련 연구를 살펴볼 수 있습니다.
Hownet Core Data File (즉 여기에서 다운로드 할 수있는 Hownet Dictionary)은 중국어 및 영어 단어 및 문구로 표시되는 237,973 개의 개념 (또는 감각)으로 구성됩니다. Hownet의 각 개념은 Sememe 기반 정의, POS 태그, 감정 방향, 예제 문장 등으로 주석을 달 수 있습니다. 여기에 Hownet에 개념이 어떻게 주석이 달리는 지에 대한 예입니다.
NO.=000000026417 # Concept ID
W_C=不惜 # Chinese word
G_C=verb # POS tag of the Chinese word
S_C=PlusFeeling|正面情感 # Sentiment orientation
E_C=~牺牲业余时间,~付出全部精力,~出卖自己的灵魂 # Example sentences of the Chinese word
W_E=do not hesitate to # English word
G_E=verb # POS tag of the English word
S_E=PlusFeeling|正面情感 # Sentiment orientation
E_E= # Example sentences of the English word
DEF={willing|愿意} # Sememe-based definition
RMK=
OpenHownet API를 설치하려면 다음 두 가지 방법 중 하나를 선택할 수 있습니다.
pip install OpenHowNetgit clone https://github.com/thunlp/OpenHowNet/
cd OpenHowNet
python setup.py install다음 코드 스 니펫은 OpenHownet API의 몇 가지 기본 기능을 보여줍니다. 이 Jupyter 노트북을 다운로드하여 코드를 실행할 수도 있습니다. 더 많은 기능과 자세한 정보를 보려면 문서로 이동하십시오.
import OpenHowNet
hownet_dict = OpenHowNet . HowNetDict () Hownet 데이터를 다운로드하지 않은 경우 오류가 발생합니다. 이 경우 OpenHowNet.download() 먼저 실행해야합니다.
기본적으로 API는 주어진 단어 (영어 또는 중국어)로 표시되는 모든 개념 (감각)을 HowNet을 검색하고 Sense 클래스의 인스턴스 목록을 반환합니다. 검색 시간을 줄이기 위해 언어를 설정할 수도 있습니다. 주어진 단어가 Hownet에 존재하지 않으면이 API는 빈 목록을 반환합니다.
> >> # Get all the senses represented by the word "苹果".
>> > result_list = hownet_dict . get_sense ( "苹果" )
> >> print ( "The number of retrievals: " , len ( result_list ))
The number of retrievals : 8
> >> print ( "An example of retrievals: " , result_list )
An example of retrievals : [ No . 244401 | apple |苹果, No . 244402 | malus pumila |苹果, No . 244403 | orchard apple tree |苹果, No . 244396 | apple |苹果, No . 244397 | apple |苹果, No . 244398 | IPHONE |苹果, No . 244399 | apple |苹果, No . 244400 | iphone |苹果]Sense 인스턴스로 감각의 자세한 정보를 얻을 수 있습니다.
> >> sense_example = result_list [ 0 ]
> >> print ( "Sense example:" , sense_example )
Sense example : No . 244401 | apple |苹果
> >> print ( "Sense id: " , sense_example . No )
Sense id : 000000244401
> >> print ( "English word in the sense: " , sense_example . en_word )
English word in the sense : apple
> >> print ( "Chinese word in the sense: " , sense_example . zh_word )
Chinese word in the sense : 苹果
> >> print ( "HowNet Def of the sense: " , sense_example . Def )
HowNet Def of the sense : { tree |树:{ reproduce |生殖: PatientProduct = { fruit |水果}, agent = { ~ }}}
>> > print ( "Sememe list of the sense: " , sense_example . get_sememe_list ())
Sememe list of the sense : { fruit |水果, tree |树, reproduce |生殖}감각의 구조화 된 Sememe 기반 정의를 시각화 할 수 있습니다 (즉, "Sememe Tree").
> >> sense_example . visualize_sememe_tree ()
[ sense ] No .244401 | apple |苹果
└── [ None ] tree |树
└── [ agent ] reproduce |生殖
└── [ PatientProduct ] fruit |水果이 패키지는 Hownet에서 모든 감각, 단어 및 신분을 얻기 위해 API를 제공합니다.
> >> all_senses = hownet_dict . get_all_senses ()
> >> print ( "The number of all senses: {}" . format ( len ( all_senses )))
The number of all senses : 237974
> >> zh_word_list = hownet_dict . get_zh_words ()
> >> print ( "Chinese words in HowNet: " , zh_word_list [: 30 ])
Chinese words in HowNet : [ '' , '"' , '#' , '#号标签' , '$' , '$.J.' , '$A.' , '$NZ.' , '%' , "'" , '(' , ')' , '*' , '+' , ',' , '-' , '--' , '.' , '...' , '...为止' , '...也同样使然' , '...以上' , '...以内' , '...以来' , '...何如' , '...内' , '...出什么问题' , '...发生了什么' , '...发生故障' , '...家里有几口人' ]
> >> en_word_list = hownet_dict . get_en_words ()
> >> print ( "English words in HowNet: " , en_word_list [: 30 ])
English words in HowNet : [ 'A' , 'An' , 'Frenchmen' , 'Frenchwomen' , 'Ottomans' , 'a' , 'aardwolves' , 'abaci' , 'abandoned' , 'abbreviated' , 'abode' , 'aboideaux' , 'aboiteaux' , 'abscissae' , 'absorbed' , 'acanthi' , 'acari' , 'accepted' , 'acciaccature' , 'acclaimed' , 'accommodating' , 'accompanied' , 'accounting' , 'accused' , 'acetabula' , 'acetified' , 'aching' , 'acicula' , 'acini' , 'acquired' ]
> >> all_sememes = hownet_dict . get_all_sememes ()
> >> print ( 'There are {} sememes in HowNet' . format ( len ( all_sememes )))
There are 2540 sememes in HowNet 주어진 단어로 표시되는 감각의 Sememe 기반 정의를 검색 할 수 있습니다. 기본적으로 패키지는 단어로 표시되는 모든 감각을 검색하고 Sememe 목록을 개별적으로 반환합니다.
> >> hownet_dict . get_sememes_by_word ( word = '苹果' , display = 'list' , merge = False , expanded_layer = - 1 , K = None )
[{ 'sense' : No . 244396 | apple |苹果,
'sememes' : { PatternValue |样式值, SpeBrand |特定牌子, able |能, bring |携带, computer |电脑}},
{ 'sense' : No . 244397 | apple |苹果,
'sememes' : { fruit |水果}},
{ 'sense' : No . 244398 | IPHONE |苹果,
'sememes' : { PatternValue |样式值, SpeBrand |特定牌子, able |能, bring |携带, communicate |交流, tool |用具}},
{ 'sense' : No . 244399 | apple |苹果,
'sememes' : { PatternValue |样式值, SpeBrand |特定牌子, able |能, bring |携带, communicate |交流, tool |用具}},
{ 'sense' : No . 244400 | iphone |苹果,
'sememes' : { PatternValue |样式值, SpeBrand |特定牌子, able |能, bring |携带, communicate |交流, tool |用具}},
{ 'sense' : No . 244401 | apple |苹果,
'sememes' : { fruit |水果, reproduce |生殖, tree |树}},
{ 'sense' : No . 244402 | malus pumila |苹果,
'sememes' : { fruit |水果, reproduce |生殖, tree |树}},
{ 'sense' : No . 244403 | orchard apple tree |苹果,
'sememes' : { fruit |水果, reproduce |生殖, tree |树}}] display 변경하면 SENSENT의 SENEMES를 목록 양식 ( list ), 사전 형식 ( dict ), 트리 노드 양식 ( tree ) 및 시각화 양식 ( visual )으로 표시 할 수 있습니다.
# Get the sememes in the form of dictionary
> >> hownet_dict . get_sememes_by_word ( word = '苹果' , display = 'dict' )[ 0 ]
{ 'sense' : No . 244396 | apple |苹果, 'sememes' : { 'role' : 'sense' , 'name' : No . 244396 | apple |苹果, 'children' : [{ 'role' : 'None' , 'name' : computer |电脑, 'children' : [{ 'role' : 'modifier' , 'name' : PatternValue |样式值, 'children' : [{ 'role' : 'CoEvent' , 'name' : able |能, 'children' : [{ 'role' : 'scope' , 'name' : bring |携带, 'children' : [{ 'role' : 'patient' , 'name' : '$' }]}]}]}, { 'role' : 'patient' , 'name' : SpeBrand |特定牌子}]}]}}
# Get the sememes in the form of tree node (get the root node of the sememe tree)
> >> d . get_sememes_by_word ( word = '苹果' , display = 'tree' )[ 0 ]
{ 'sense' : No . 244396 | apple |苹果, 'sememes' : Node ( '/No.244396|apple|苹果' , role = 'sense' )}
# Visualize the sememes (Set K to control the num of visualized tree to print)
> >> d . get_sememes_by_word ( word = '苹果' , display = 'visual' , K = 2 )
Find 8 result ( s )
Display #0 sememe tree
[ sense ] No .244396 | apple |苹果
└── [ None ] computer |电脑
├── [ modifier ] PatternValue |样式值
│ └── [ CoEvent ] able |能
│ └── [ scope ] bring |携带
│ └── [ patient ]$
└── [ patient ] SpeBrand |特定牌子
Display #1 sememe tree
[ sense ] No .244397 | apple |苹果
└── [ None ] fruit |水果게다가, display=='list' 일 때, 모든 sememe 목록을 하나로 병합하고 매개 변수 expanded_layer 를 변경하여 Sememe 트리의 확장 레이어를 제한하도록 선택할 수 있습니다 (-1은 모든 레이어를 확장하는 것을 의미합니다).
> >> hownet_dict . get_sememes_by_word ( word = '苹果' , display = 'list' , merge = True , expanded_layer = - 1 , K = None )
{ PatternValue |样式值, SpeBrand |特定牌子, able |能, bring |携带, communicate |交流, computer |电脑, fruit |水果,
reproduce |生殖, tool |用具, tree |树}정액을 나타내는 단어 (영어 또는 중국어)를 입력하여 두 정서 간의 관계를 얻을 수 있습니다. (sememe1, relation, sememe2)의 삼중 항을 표시하도록 선택할 수 있습니다.
> >> relations = hownet_dict . get_sememe_relation ( 'FormValue' , '圆' , return_triples = False )
> >> print ( relations )
'hyponym'
> >> triples = hownet_dict . get_sememe_relation ( 'FormValue' , '圆' , return_triples = True )
> >> print ( triples )
[( FormValue |形状值, 'hyponym' , round |圆)]Sememe과 특정 관계가있는 모든 Sememes를 검색 할 수 있습니다. 마찬가지로 Sememe은 단어 (영어 또는 중국어)로 표시되어야하지만 관계는 소문자로되어 있어야합니다.
> >> triples = hownet_dict . get_related_sememes ( 'FormValue' , relation = 'hyponym' , return_triples = True )
> >> print ( triples )
[( FormValue |形状值, 'hyponym' , round |圆), ( FormValue |形状值, 'hyponym' , unformed |不成形), ( AppearanceValue |外观值, 'hyponym' , FormValue |形状值), ( FormValue |形状值, 'hyponym' , angular |角), ( FormValue |形状值, 'hyponym' , square |方), ( FormValue |形状值, 'hyponym' , netlike |网), ( FormValue |形状值, 'hyponym' , formed |成形)]구현은 논문을 기반으로합니다.
Jiangming Liu, Jinan Xu, Yujie Zhang. Hownet의 단어 유사성 컴퓨팅을위한 하이브리드 계층 구조의 접근. IJCNLP 2013의 절차에서. [PDF]
유사성 계산을 위해로드하는 데 필요한 일부 파일이 있으므로 초기화 오버 헤드는 이전보다 클 것입니다.
우선 hownet_dict 객체를 다음과 같이 초기화 할 수 있습니다.
> >> hownet_dict_advanced = OpenHowNet . HowNetDict ( init_sim = True )
Initializing OpenHowNet succeeded !
Initializing similarity calculation succeeded !사용하기 전까지 유사성 계산의 초기화를 연기 할 수도 있습니다.
> >> hownet_dict . initialize_similarity_calculation ()
Initializing similarity calculation succeeded !의미가있는 Sememe 기반 정의와 동일한 감각을 얻을 수 있습니다.
> >> s = hownet_dict_advanced . get_sense ( '苹果' )[ 0 ]
> >> hownet_dict_advanced . get_sense_synonyns ( s )[: 10 ]
[ No . 110999 | pear |山梨, No . 111007 | hawthorn |山楂, No . 111009 | haw |山楂树, No . 111010 | hawthorn |山楂树, No . 111268 | Chinese hawthorn |山里红, No . 122955 | Pistacia vera |开心果树, No . 122956 | pistachio |开心果树, No . 122957 | pistachio tree |开心果树, No . 135467 | almond tree |扁桃, No . 154699 | fig |无花果]패키지는 주어진 단어로 표시되는 감각을 검색하고 가장 가까운 Top-K 감각을 얻고 해당 단어를 반환합니다. 주어진 단어의 언어를 설정해야합니다.
또한 단어의 POS를 설정하고 유사성을 출력하도록 선택하고 차이 감각에 속하는 모든 단어를 단일 목록으로 병합 할 수 있습니다. 자세한 내용은 문서를 참조하십시오.
입력 단어가 Hownet에 있지 않으면 API는 빈 목록을 반환합니다.
> >> hownet_dict_advanced . get_nearest_words ( '苹果' , language = 'zh' , K = 5 )
{ No . 244396 | apple |苹果: [ 'IBM' , '东芝' , '华为' , '戴尔' , '索尼' ],
No . 244397 | apple |苹果: [ '丑橘' , '乌梅' , '五敛子' , '凤梨' , '刺梨' ],
No . 244398 | IPHONE |苹果: [ 'OPPO' , '华为' , '苹果' , '智能手机' , '彩笔' ],
No . 244399 | apple |苹果: [ 'OPPO' , '华为' , '苹果' , '智能手机' , '彩笔' ],
No . 244400 | iphone |苹果: [ 'OPPO' , '华为' , '苹果' , '智能手机' , '彩笔' ],
No . 244401 | apple |苹果: [ '山梨' , '山楂' , '山楂树' , '山里红' , '开心果树' ],
No . 244402 | malus pumila |苹果: [ '山梨' , '山楂' , '山楂树' , '山里红' , '开心果树' ],
No . 244403 | orchard apple tree |苹果: [ '山梨' , '山楂' , '山楂树' , '山里红' , '开心果树' ]}
> >> hownet_dict_advanced . get_nearest_words ( '苹果' , language = 'zh' , K = 5 , merge = True )
[ 'IBM' , '东芝' , '华为' , '戴尔' , '索尼' ] 주어진 두 단어 중 하나가 Hownet에 존재하지 않으면 -1 반환합니다.
> >> print ( 'The similarity of 苹果 and 梨 is {}.' . format ( hownet_dict_advanced . calculate_word_similarity ( '苹果' , '梨' )))
The similarity of 苹果 and 梨 is 1.0 .이 패키지는 Babelnet (Babelnet Synset)의 Synsets 정보에 대한 쿼리 기능을 통합합니다. Babelnet은 Babelnet Synsets로 구성된 다국어 백과 사전으로, 각각 동일한 의미를 가진 다국어 동의어를 포함합니다. 다음 작업은 일부 Babelnet Synsets에 대해 Sememes에 주석을 달며이 부분의 기능은 주석 결과를 기반으로합니다.
다국어 Sememe 지식 기반 구축을 위해 : Babelnet Synsets에 대한 예측 예측 . Fanchao Qi, Liang Chang, Maosong Sun, Sicong Ouyang 및 Zhiyuan Liu . AAAI-20. [PDF] [코드]
우선 Babelnet Synset Dictionary를 초기화해야합니다.
> >> hownet_dict . initialize_babelnet_dict ()
Initializing BabelNet synset Dict succeeded !
# Or you can initialize when create the HowNetDict instance
>> > hownet_dict_advanced = HowNetDict ( init_babel = True )
Initializing OpenHowNet succeeded !
Initializing BabelNet synset Dict succeeded !다음 API를 사용하면 Babelnet Synset (중국어 및 영어 동의어, 정의, 그림 URL 등)에서 풍부한 정보를 쿼리 할 수 있습니다.
> >> syn_list = hownet_dict_advanced . get_synset ( '黄色' )
> >> print ( "{} results are retrieved and take the first one as an example" . format ( len ( syn_list )))
3 results are retrieved and take the first one as an example
>> > syn_example = syn_list [ 0 ]
> >> print ( "Synset: {}" . format ( syn_example ))
Synset : bn : 00113968 a | yellow |黄
> >> print ( "English synonyms: {}" . format ( syn_example . en_synonyms ))
English synonyms : [ 'yellow' , 'yellowish' , 'xanthous' ]
> >> print ( "Chinese synonyms: {}" . format ( syn_example . zh_synonyms ))
Chinese synonyms : [ '黄' , '黄色' , '淡黄色+的' , '黄色+的' , '微黄色' , '微黄色+的' , '黄+的' , '淡黄色' ]
> >> print ( "English glosses: {}" . format ( syn_example . en_glosses ))
English glosses : [ 'Of the color intermediate between green and orange in the color spectrum; of something resembling the color of an egg yolk' , 'Having the colour of a yolk, a lemon or gold.' ]
> >> print ( "Chinese glosses: {}" . format ( syn_example . zh_glosses ))
Chinese glosses : [ '像丝瓜花或向日葵花的颜色。' ]주어진 Synset과 관련된 Babelnet Synsets를 얻을 수 있습니다.
> >> related_synsets = syn_example . get_related_synsets ()
> >> print ( "There are {} synsets that have relation with the {}, they are: " . format ( len ( related_synsets ), syn_example ))
There are 6 synsets that have relation with the bn : 00113968 a | yellow |黄, they are :
>> > print ( related_synsets )
[ bn : 00099663 a | chromatic |彩色, bn : 00029925 n | egg_yolk |蛋黄, bn : 00092876 v | resemble |相似, bn : 00020726 n | color |颜色, bn : 00020748 n | visible_spectrum |可见光, bn : 00081866 n | yellow |黄色]Babelnet Synsets에 단어를 입력하여 Babelnet Synsets의 제도를 얻을 수 있습니다.
> >> print ( hownet_dict_advanced . get_sememes_by_word_in_BabelNet ( '黄色' ))
[{ 'synset' : bn : 00113968 a | yellow |黄, 'sememes' : [ yellow |黄]}, { 'synset' : bn : 00101430 a | dirty |淫秽的, 'sememes' : [ lascivious |淫, dirty |龊, despicable |卑劣, BadSocial |坏风气]}, { 'synset' : bn : 00081866 n | yellow |黄色, 'sememes' : [ yellow |黄]}]
> >> print ( hownet_dict_advanced . get_sememes_by_word_in_BabelNet ( '黄色' , merge = True ))
[ lascivious |淫, despicable |卑劣, BadSocial |坏风气, dirty |龊, yellow |黄]자세한 지침은 문서를 참조하십시오.
코드 또는 데이터가 도움이되면 다음 논문을 인용하십시오.
@article{qi2019openhownet,
title={Openhownet: An open sememe-based lexical knowledge base},
author={Qi, Fanchao and Yang, Chenghao and Liu, Zhiyuan and Dong, Qiang and Sun, Maosong and Dong, Zhendong},
journal={arXiv preprint arXiv:1901.09957},
year={2019}
}