Hit the synonym of the word forest, should be the product of the last century, the word is relatively old, but at least can also use synonyms of the role of the word forest, with the Word2vec to obtain similar function comparison, the two play a comparative effect, see the specific application bar1.First download the TXT,CSDN with synonyms on the link: http://download.csdn.net/download/answerme11/73077712.The contents of the TXT are as follows: each line is composed of a series of entriesThe letters and numbers of each line of the outfit indicate the category"=" stands for "equal" and "synonymous";“#"On behalf of" unequal ","category ", belonging to the relevant words; "@" stands for "self-containment", "independence", which in the dictionary neitherThere are synonyms, there are no related words.
3.python calls the synonym for the word forest Code
def get_sym(w,word_set):
# w: input word
# word_set: 同义词词集或相关词词集
results=[]
if(len(w)==1):
for each in word_set:
for word in each:
if w == word:
results.append(each)
break
else:
for each in word_set:
for word in each:
if w in word:
results.append(each)
break
return results
f=open(‘同义词.txt‘,‘r‘)
lines=f.readlines()
sym_words=[]
sym_class_words=[]
# 从txt中获取词条,构建同义词词集sym_words和相关词词集sym_class_words
for line in lines:
line=line.replace(‘\n‘,‘‘)
items=line.split(‘ ‘)
index=items[0]
if(index[-1]==‘=‘):
sym_words.append(items[1:])
if (index[-1] == ‘#‘):
sym_class_words.append(items[1:])
print(sym_words)
print(64*‘*‘)
print(sym_class_words)
while True:
w=input()
print(‘同义词‘,66*‘*‘)
print(get_sym(w, sym_words))
print(‘同类词‘, 66 * ‘*‘)
print(get_sym(w, sym_class_words))
Operation Result:
Null
List of attachments
Hit synonym word forest python usage example