-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.py
47 lines (41 loc) · 1.24 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# -*- coding:utf-8 -*-
from vocabulary import *
import sys
if __name__ == '__main__':
target = sys.argv[1]
word = LIST.search(str(target))
if word is not None:
print (str(word))
else:
print ("词条%s未收录") % target
# Get the synonyms
if '-syn' in sys.argv:
syns = []
for tw in word.test_ways:
if tw.synonyms is not None:
syns += tw.synonyms
print "近义词: %s" % (' '.join(syns)).upper()
count = 0
for s in syns:
syn = LIST.search(str(s))
if syn is not None:
print (str(syn))
count += 1
if count == 0:
print ("未收录%s相关的近义词") % target
# Get the synonyms
if '-ant' in sys.argv:
ants = []
for tw in word.test_ways:
if tw.antonyms is not None:
ants += tw.antonyms
print "反义词: %s" % (' '.join(ants)).upper()
count = 0
for a in ants:
ant = LIST.search(str(a))
if ant is not None:
print (str(ant))
count += 1
if count == 0:
print ("未收录%s相关的反义词") % target