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

add method to get usage of a word in sentences #46

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
29 changes: 29 additions & 0 deletions PyDictionary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,35 @@ def meaning(term, disable_errors=False):
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)

@staticmethod
def usage(term, min_length= 5, disable_errors=False):
"""
:param term: The word we are looking for meanings and usages
:param min_length: minimum length of the sentence to filter on
:param disable_errors: if False, print errors if there is some error
:return: returns a dictionary with keys begin (noun, verb). One with meanings and other with usages
"""
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")
usage_out = []
for a in types:
reg = str(lists[types.index(a)])
for x in re.findall(r"<i>\"(.*?)\"", reg):
if 'often followed by' in x:
pass
elif len(x) >= min_length and term in str(x):
usage_out.append(x)
return usage_out
except Exception as e:
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)

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