Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
treatmesubj committed Mar 30, 2023
1 parent 8d9bce5 commit 738e7c4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Thesaurus Rex
Thesaurus tool that fetches a word's homonyms, synonyms, and antonyms from [Thesaurus.com](https://www.thesaurus.com/). It's also a dictionary tool that fetches definitions from [Webster](https://www.merriam-webster.com/)
Thesaurus tool that fetches a word's homonyms, synonyms, and antonyms from [Thesaurus.com](https://www.thesaurus.com/). It's also a dictionary tool that fetches definitions from [Webster](https://www.merriam-webster.com/). It fetches etymology information from [etymonline](https://www.etymonline.com/).

### Installation
- from [PyPI](https://pypi.org/project/thesr): `pip install thesr`
Expand All @@ -8,13 +8,13 @@ Thesaurus tool that fetches a word's homonyms, synonyms, and antonyms from [Thes
### Usage

```
python -m thesr.thesr [-h] [--word WORD] [--define | --antonyms | --verbose]
python -m thesr.thesr [-h] [--word WORD] [--define] [--etymology] [--antonyms] [--verbose]
```
Common English phrases such as `toungue-and-cheek` or `dime-a-dozen` can be defined and return synonyms as well if Webster and Thesaurus.com have entries for them.
Common English phrases & idioms such as `toungue-and-cheek` or `dime-a-dozen` sometimes work as well

```
john@spectre:~
$ python -m thesr.thesr --word purport --verbose
$ python -m thesr.thesr -w purport -v
_____ _
|_ _| |
Expand All @@ -26,8 +26,10 @@ $ python -m thesr.thesr --word purport --verbose
[purport!]
---Synonyms-------------------------------------------------------------------
{ noun: meaning, implication } ==> ['acceptation', 'aim', 'bearing', 'burden', 'connotation', 'core', 'design', 'drift', 'gist', 'heart']
{ verb: assert, mean } ==> ['imply', 'pose as', 'pretend', 'profess', 'allege', 'betoken', 'claim', 'convey', 'declare', 'denote']
{ noun: meaning, implication } == ['acceptation', 'aim', 'bearing', 'burden', 'connotation', 'core', 'design',
'drift', 'gist', 'heart']
{ verb: assert, mean } == ['imply', 'pose as', 'pretend', 'profess', 'allege', 'betoken', 'claim', 'convey',
'declare', 'denote']
--------------------------------------------------------------------------------
---Definitions-------------------------------------------------------------------
Expand All @@ -38,8 +40,19 @@ $ python -m thesr.thesr --word purport --verbose
{ noun: substance, gist }
--------------------------------------------------------------------------------
---Etymology-------------------------------------------------------------------
purport (n.)
early 15c., "meaning, tenor, the surface or expressed meaning of a document, etc.; that which is conveyed or
expressed," from Anglo-French purport (late 13c.), Old French porport "contents, tenor," back-formation from
purporter "to contain, convey, carry; intend," from pur- (from Latin pro- "forth;" see pur-) + Old French porter "tocarry," from Latin portare "to carry" (from PIE root *per- (2) "to lead, pass over"). Meaning "that which is to be done or effected" is from 1650s.
purport (v.)
1520s, "indicate, express, set forth, convey to the mind as the meaning or thing intended," from the noun in Englishand from Anglo-French purporter (c. 1300), from Old French purporter "to contain, convey, carry; intend," from pur- (from Latin pro- "forth;" see pur-) + Old French porter "to carry," from Latin portare "to carry" (from PIE root
*per- (2) "to lead, pass over"). Related: Purported; purporting.
--------------------------------------------------------------------------------
---Antonyms-------------------------------------------------------------------
{ noun: meaning, implication } =/=> ['exterior', 'exteriority', 'insignificance', 'meaninglessness', 'outside', 'surface']
{ verb: assert, mean } =/=> ['conceal', 'deny', 'disclaim', 'hide']
{ noun: meaning, implication } =/= ['exterior', 'exteriority', 'insignificance', 'meaninglessness', 'outside',
'surface']
{ verb: assert, mean } =/= ['conceal', 'deny', 'disclaim', 'hide']
--------------------------------------------------------------------------------
```
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

setup(
name="thesr",
version="0.0.2",
version="0.0.3",
license="gpl-3.0",
author="John Hupperts",
author_email="[email protected]",
description="thesaurus (and also dictionary)",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/treatmesubj/Thesaurus_Rex",
download_url="https://github.com/treatmesubj/Thesaurus_Rex/archive/refs/tags/v0.0.2.tar.gz",
download_url="https://github.com/treatmesubj/Thesaurus_Rex/archive/refs/tags/v0.0.3.tar.gz",
packages=["thesr"],
package_dir={"Thesaurus_Rex": "thesr"},
project_urls={
Expand Down
50 changes: 41 additions & 9 deletions thesr/thesr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ def get_syns_ants(word):
return homonyms


def get_etymology(word):
soup = BeautifulSoup(requests.get(f"https://www.etymonline.com/word/{word}").text, 'html.parser')
class_elems = soup.select("div[class^='word'] [class^='word__name']")
etym_elems = soup.select("div[class^='word'] [class^='word__def']")
zipped_elems = zip(class_elems, etym_elems)
homonyms = []
for class_elem, etym_elem in zipped_elems:
if 'href' not in class_elem.attrs.keys():
etym_text = ""
for etym_p_elem in etym_elem.select('p'):
etym_text += f"{etym_p_elem.text}\n"
homonyms.append({
'etym_desc': etym_text.rstrip('\n'),
'word_class': class_elem.text
})
return homonyms


class Word:
def __init__(self, word, console):
self.spelling = word
Expand All @@ -77,7 +95,7 @@ def show_syns(self):
print(f"---Synonyms{'-'*67}")
if getattr(self, "thesr_homonyms", None):
for homonym in self.thesr_homonyms:
console.print(f"[magenta]{{ {homonym['word_class']}: {homonym['definition']} }}[/magenta] [green]==>[/green] [green]{homonym['synonyms'][:10]}[/green]")
console.print(f"[magenta]{{ {homonym['word_class']}: {homonym['definition']} }}[/magenta] [green]==[/green] [green]{homonym['synonyms'][:10]}[/green]")
else:
print("Sorry, no synonyms found")
print('-'*80, '\n')
Expand All @@ -86,7 +104,7 @@ def show_ants(self):
print(f"---Antonyms{'-'*67}")
if getattr(self, "thesr_homonyms", None):
for homonym in self.thesr_homonyms:
console.print(f"[magenta]{{ {homonym['word_class']}: {homonym['definition']} }}[/magenta] [red]=/=>[/red] [red]{homonym['antonyms'][:10]}[/red]")
console.print(f"[magenta]{{ {homonym['word_class']}: {homonym['definition']} }}[/magenta] [red]=/=[/red] [red]{homonym['antonyms'][:10]}[/red]")
else:
print("Sorry, no antonyms found")
print('-'*80, '\n')
Expand All @@ -101,11 +119,23 @@ def show_defs(self):
else:
print(f"Is {self.spelling} a word?")
candidates = SpellChecker().candidates(self.spelling)
candidates.discard(self.spelling)
if candidates:
candidates.discard(self.spelling)
print(f"Did you mean {candidates}?")
print('-'*80, '\n')

def show_etymology(self):
print(f"---Etymology{'-'*67}")
if not getattr(self, 'etymology', None):
self.etymology = get_etymology(self.spelling)
if getattr(self, 'etymology', None):
for homonym in self.etymology:
console.print(f"[magenta]{homonym['word_class']}[/magenta]")
console.print(f"[white]{homonym['etym_desc']}[/white]")
else:
print("Sorry, no etymology found")
print('-'*80, '\n')


if __name__ == "__main__":
print(
Expand All @@ -122,21 +152,23 @@ def show_defs(self):

parser = argparse.ArgumentParser()
parser.add_argument("--word", "-w", action="store")
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--define", "-d", action="store_true")
group.add_argument("--antonyms", "-a", action="store_true")
group.add_argument("--verbose", "-v", action="store_true")
parser.add_argument("--define", "-d", action="store_true")
parser.add_argument("--etymology", "-e", action="store_true")
parser.add_argument("--antonyms", "-a", action="store_true")
parser.add_argument("--verbose", "-v", action="store_true")
args = parser.parse_args()

if args.word:
thesr_word = Word(args.word, console)
else:
thesr_word= Word(get_random_word(), console)
thesr_word = Word(get_random_word(), console)

thesr_word.show_syns()

if args.define or args.verbose or not args.word:
if args.define or args.verbose:
thesr_word.show_defs()
if args.etymology or args.verbose:
thesr_word.show_etymology()
if args.antonyms or args.verbose:
thesr_word.show_ants()

0 comments on commit 738e7c4

Please sign in to comment.