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)
def meaning(term): regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') try: if len(term.split()) > 1 or regex.search(term) != None: 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: return 0 except: return 0
def meaning(term): 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: print("Error: The Following Error occured: %s" % e)
def meaning(term): 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=" + term) types = html.findAll("h3") if types[0].text == u'Your search did not return any results.': return {'temp': None} if types[ 0].text == u'Sorry, your search can only contain letters, numbers, spaces, hyphens, periods, slashes, and/or apostrophes.': return {'temp': None} 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: print("Error: The Following Error occured: %s" % e)
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)
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))
def antonym(word, formatted=False): try: data = _get_soup_object("http://www.thesaurus.com/browse/{0}".format(word)) terms = data.select("section.antonyms")[0].findAll("li") if len(terms) > 5: terms = terms[:5:] li = [] for t in terms: li.append(t.select("span.text")[0].getText()) if formatted: return {word: li} return li except: return None
def synonym(term, formatted=False): try: data = _get_soup_object("http://www.thesaurus.com/browse/{0}".format(term)) terms = data.select("div#filters-0")[0].findAll("li") if len(terms) > 5: terms = terms[:5:] li = [] for t in terms: li.append(t.select("span.text")[0].getText()) if formatted: return {term: li} return li except: return None
def antonym(word, formatted=False): if len(word.split()) > 1: print("Error: A Term must be only a single word") else: try: data = _get_soup_object( "https://www.thesaurus.com/browse/{0}".format(word)) section = data.find('section', {'class': 'antonyms-container'}) spans = section.findAll('span') antonyms = [span.text for span in spans[:5]] if formatted: return {word: antonyms} return antonyms except: print("{0} has no Antonyms in the API".format(word))
def googlemeaning(term, formatted=True): try: html = _get_soup_object("http://www.google.co.in/search?q=define:%3A%20{0}".format( term)) body = html.find( "table", {"style": "font-size:14px;width:100%"}) wordType = body.find( "div", {"style": "color:#666;padding:5px 0"}).getText() meaning = body.find("li").getText() formated = "{0} : {1} \n{2}\n".format( term.capitalize(), wordType, meaning) if not formatted: return meaning return formated except Exception as e: return None
def antonym(word, formatted=False): if len(word.split()) > 1: print("Error: A Term must be only a single word") else: try: data = _get_soup_object("http://www.thesaurus.com/browse/{0}".format(word)) terms = data.select("section.antonyms")[0].findAll("li") if len(terms) > 5: terms = terms[:5:] li = [] for t in terms: li.append(t.select("span.text")[0].getText()) if formatted: return {word: li} return li except: print("{0} has no Antonyms in the API".format(word))
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( "http://www.thesaurus.com/browse/{0}".format(term), "lxml") terms = data.select("div#filters-0")[0].findAll("li") if len(terms) > 5: terms = terms[:5:] li = [] for t in terms: li.append(t.select("span.text")[0].getText()) if formatted: return {term: li} return li except: print("{0} has no Synonyms in the API".format(term))
def googlemeaning(term, formatted=True): if len(term.split()) > 1: print("Error: A Term must be only a single word") else: try: html = _get_soup_object("http://www.google.co.in/search?q=define:%3A%20{0}".format( term)) body = html.find( "table", {"style": "font-size:14px;width:100%"}) wordType = body.find( "div", {"style": "color:#666;padding:5px 0"}).getText() meaning = body.find("li").getText() formated = "{0} : {1} \n{2}\n".format( term.capitalize(), wordType, meaning) if not formatted: return meaning return formated except Exception as e: print("Error: The Word given is not a valid English Word")
def meaning(term, disable_errors=False): 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: return None