Skip to content

Commit a0a288d

Browse files
committed
meaning: support multiple word input
1 parent c9e9465 commit a0a288d

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

PyDictionary/core.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,29 @@ def antonym(term, formatted=False):
113113
@staticmethod
114114
def meaning(term, disable_errors=False):
115115
if len(term.split()) > 1:
116-
print("Error: A Term must be only a single word")
117-
else:
118-
try:
119-
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
120-
term))
121-
types = html.findAll("h3")
122-
length = len(types)
123-
lists = html.findAll("ul")
124-
out = {}
125-
for a in types:
126-
reg = str(lists[types.index(a)])
127-
meanings = []
128-
for x in re.findall(r'\((.*?)\)', reg):
129-
if 'often followed by' in x:
130-
pass
131-
elif len(x) > 5 or ' ' in str(x):
132-
meanings.append(x)
133-
name = a.text
134-
out[name] = meanings
135-
return out
136-
except Exception as e:
137-
if disable_errors == False:
138-
print("Error: The Following Error occured: %s" % e)
116+
term="+".join(term.split())
117+
118+
try:
119+
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
120+
term))
121+
types = html.findAll("h3")
122+
length = len(types)
123+
lists = html.findAll("ul")
124+
out = {}
125+
for a in types:
126+
reg = str(lists[types.index(a)])
127+
meanings = []
128+
for x in re.findall(r'\((.*?)\)', reg):
129+
if 'often followed by' in x:
130+
pass
131+
elif len(x) > 5 or ' ' in str(x):
132+
meanings.append(x)
133+
name = a.text
134+
out[name] = meanings
135+
return out
136+
except Exception as e:
137+
if disable_errors == False:
138+
print("Error: The Following Error occured: %s" % e)
139139

140140
if __name__ == '__main__':
141141
d = PyDictionary('honest','happy')

PyDictionary/test_pydictionary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class PyDictionaryTest(unittest.TestCase):
1010
def testMeaning(self):
1111
self.assertIsInstance(dictionary.meaning('python'),dict)
12+
self.assertIsInstance(dictionary.meaning("neural network"), dict)
1213
def testSynonym(self):
1314
self.assertIsInstance(dictionary.synonym('happy'),list)
1415
def testAntonym(self):

0 commit comments

Comments
 (0)