i can not research related words for a Chinese word in CNW #198
-
is there a way that i can research related words (like,antonym,similar)for a Chinese word? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Please take a look at #161 (comment) where I show how to find antonyms for Japanese. It should be easy to adapt to other languages and other relationships. |
Beta Was this translation helpful? Give feedback.
-
thans you so much,but i still meet some problems,when i process my data,here are my coding and track: `# 遍历词列表
print(f"Found {len(results)} results") # 打印找到的结果数量`
could you find the problems about my code?thank you very much! |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm not sure what you are trying to do. But one error is that |
Beta Was this translation helpful? Give feedback.
-
Hi,Fcbond!i am so sorry that i was not introduce what i want to do.
My goal is researching lexical chian in Chinese texts.
To achieve this, I should use wn this python lib to get synset for each line Chinese word in txt(this line include a lemma and pos).
Second, I want to konw the synset of every chinese word in zh.
third, for geting the sematic relationships of chinese word , i must use ili to get the same english synset,and find its hypernym,meronym,holonym,etc.
Final,all results should save to a new .txt.
In my code, i think the errors can be find in this part:
for synset in synsets:
# 获取ILI
ili = synset.ili
print(type(ili))
#print(dir(ili))
if not isinstance(ili, str):
print(f"ILI id of synset {synset} is {ili.id}.")
print(f"Error: ili of synset {synset} is not a string.")
print(f"ILI definition of synset {synset} is {ili.definition}.")
continue
if ili is not None and isinstance(ili, str):
# 在oewn:2023中获取英文同义词集
eng_synsets = wn.synsets(ili=ili, lexicon='oewn:2023')
for eng_synset in eng_synsets:
# 获取定义、上位词、下位词、meronym、holoym,antonym、synonym和similar的同义词集
definition = eng_synset.definition()
hypernyms = eng_synset.hypernyms()
hyponyms = eng_synset.hyponyms()
meronyms = eng_synset.part_meronyms()
holonyms = eng_synset.part_holonyms()
antonyms = eng_synset.lemmas()[0].antonyms() if eng_synset.lemmas() else []
synonyms = eng_synset.lemma_names()
similars = eng_synset.similar_tos()
# 添加到结果列表
results.append([i+1, word, synset, ili, definition, synonyms, hypernyms, hyponyms, meronyms, holonyms, antonyms, similars])
print(f"Found {len(results)} results") # 打印找到的结果数量
# 保存到文本文件
with open('results.txt', 'w', encoding='utf-8') as f:
for result in results:
f.write('\t'.join(str(r) for r in result) + '\n')
print("Results saved to 'results.txt'") # 打印保存结果的消息
and i also print the one of content in terminal:
Read 5 words from 'word.txt'
[Synset('omw-cmn-02402425-n'), Synset('omw-cmn-02403003-n')]
Found 2 synsets for word '牛'
<class 'wn.ILI'>
ILI id of synset Synset('omw-cmn-02402425-n') is i48233.
Error: ili of synset Synset('omw-cmn-02402425-n') is not a string.
ILI definition of synset Synset('omw-cmn-02402425-n') is <bound method ILI.definition of ILI('i48233')>.
So the reason is ili is not a string?
I am so sorry to bother you,!
…________________________________
From: Francis Bond ***@***.***>
Sent: Thursday, March 14, 2024 5:21 AM
To: goodmami/wn ***@***.***>
Cc: Xu Yue ***@***.***>; Author ***@***.***>
Subject: Re: [goodmami/wn] i can not research related words for a Chinese word in CNW (Discussion #198)
Hi,
I'm not sure what you are trying to do.
But one error is that definition is a method, so should be definition()
―
Reply to this email directly, view it on GitHub<#198 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ARRIME3NYNJCOVLYCI72JPTYYC7NZAVCNFSM6AAAAABESIERD2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DONZYHA2TG>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi @xy1137030414, it looks like you are having trouble looking up related synsets for some First, the ili = synset.ili
...
if ili is not None and isinstance(ili, str):
... That But you should not have to do this manual step as Wn will handle most of the technical details. For example: >>> cmn = wn.Wordnet('omw-cmn', expand='omw-en')
>>> cmn.synsets("牛")
[Synset('omw-cmn-02402425-n'), Synset('omw-cmn-02403003-n')]
>>> cmn.synsets("牛")[0].hypernyms() # Wn will look up hypernyms in omw-en via the ILI
[Synset('omw-cmn-02402010-n')]
>>> cmn.synsets("牛")[0].hypernyms()[0].lemmas()
['牛属动物'] You can read more about this from the Cross-lingual Relation Traversal docs. Finally, I have some other recommendations:
|
Beta Was this translation helpful? Give feedback.
Please take a look at #161 (comment) where I show how to find antonyms for Japanese.
It should be easy to adapt to other languages and other relationships.