Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added multiword support as in issue #55 #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions PyDictionary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,62 +80,62 @@ def getAntonyms(self, formatted=True):
@staticmethod
def synonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-synonym'})
spans = section.findAll('a')
synonyms = [span.text.strip() for span in spans]
if formatted:
return {term: synonyms}
return synonyms
except:
print("{0} has no Synonyms in the API".format(term))
term="+".join(term.split())

try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-synonym'})
spans = section.findAll('a')
synonyms = [span.text.strip() for span in spans]
if formatted:
return {term: synonyms}
return synonyms
except:
print("{0} has no Synonyms in the API".format(term))


@staticmethod
def antonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-antonym'})
spans = section.findAll('a')
antonyms = [span.text.strip() for span in spans]
if formatted:
return {term: antonyms}
return antonyms
except:
print("{0} has no Antonyms in the API".format(term))
term="+".join(term.split())

try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-antonym'})
spans = section.findAll('a')
antonyms = [span.text.strip() for span in spans]
if formatted:
return {term: antonyms}
return antonyms
except:
print("{0} has no Antonyms in the API".format(term))

@staticmethod
def meaning(term, disable_errors=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
term))
types = html.findAll("h3")
length = len(types)
lists = html.findAll("ul")
out = {}
for a in types:
reg = str(lists[types.index(a)])
meanings = []
for x in re.findall(r'\((.*?)\)', reg):
if 'often followed by' in x:
pass
elif len(x) > 5 or ' ' in str(x):
meanings.append(x)
name = a.text
out[name] = meanings
return out
except Exception as e:
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)
term="+".join(term.split())

try:
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
term))
types = html.findAll("h3")
length = len(types)
lists = html.findAll("ul")
out = {}
for a in types:
reg = str(lists[types.index(a)])
meanings = []
for x in re.findall(r'\((.*?)\)', reg):
if 'often followed by' in x:
pass
elif len(x) > 5 or ' ' in str(x):
meanings.append(x)
name = a.text
out[name] = meanings
return out
except Exception as e:
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)

if __name__ == '__main__':
d = PyDictionary('honest','happy')
Expand Down