jmsv / ety-python

A Python module to discover the etymology of words
http://ety-python.rtfd.io
MIT License
144 stars 18 forks source link

Encapsulate Word #19

Closed alxwrd closed 6 years ago

alxwrd commented 6 years ago

hello! :wave:

The diff here is bigger than I thought. The main change here is I've moved the concept of origins and tree under the Word class. The underlying code hasn't changed much.

The origins and tree functions left in the package namespace act as wrappers to the Word class.

Hopefully, the commit's give a better idea of what's changed (versus the PR diff) as I tried to keep them in logical chunks.

I snuck in a fix for #8 at the end.

There is one failing test, but that's due to a function moving.

Examples

>>> import ety

>>> ety.origins("potato")
[Word(batata, language=tnq)]

>>> ety.origins("drink", recursive=True)
[Word(drync, language=ang), Word(drinken, language=enm), Word(drincan, language=ang)]

>>> word = ety.Word("cheese")
>>> word.lang_code
'eng'
>>> word.lang_name
'English'
>>> word.pretty
'cheese (English)'
>>> print(word)
cheese (English)
>>> word.origins
[Word(chese, language=enm)]

>>> ety.tree("aerodynamically")
<treelib.tree.Tree object at 0x7fc1b1cf2f60>

>>> print(ety.tree("aerodynamically"))
aerodynamically (English)
├── -ally (English)
└── aerodynamic (English)
    ├── aero- (English)
    │   └── ἀήρ (Ancient Greek (to 1453))
    └── dynamic (English)
        └── dynamique (French)
            └── δυναμικός (Ancient Greek (to 1453))
                └── δύναμις (Ancient Greek (to 1453))
                    └── δύναμαι (Ancient Greek (to 1453))
jmsv commented 6 years ago

@alxwrd Looks good 👍 although I'd like to get tests working before merging into master

jmsv commented 6 years ago

Nvm I'll just merge and then fix

alxwrd commented 6 years ago

I'm so sorry! Look at the mess I left the tests in :persevere:! I was only expecting test_lang to fail.

Thanks for cleaning up my mess :sweat_smile:

jmsv commented 6 years ago

@alxwrd dw about it :joy: thanks for the Python 2 fix (#23)