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

Extract tree into an EtyTree #34

Closed alxwrd closed 6 years ago

alxwrd commented 6 years ago

This extracts the tree logic out of Word and into its own class. I've based the class off treelib.Tree so it functions like a Tree object, but with the added bonus that we can control the __repr__.

It's also now valid to have an empty tree, so maybe closes #13?

>>> ety.tree("flower")
EtyTree(word='flower')

>>> print(ety.tree("flower"))
flower (English)
└── flour (Middle English (1100-1500))
    └── flur (Anglo-Norman)
        ├── flor (Latin)
        └── flor (Old French (842-ca. 1400))
            ├── florem (Latin)
            └── flos (Latin)

>>> ety.EtyTree("green")
EtyTree(word='green')

>>> print(ety.EtyTree("green"))
green (English)
└── grene (Middle English (1100-1500))
    └── grene (Old English (ca. 450-1100))

>>> ety.tree("dwiovwh")
EtyTree(word='dwiovwh')

>>> print(ety.tree("dwiovwh"))
jmsv commented 6 years ago

Looks awesome, although found a problem: this assumes the word param (if string) is English due to the Word object being initialised without a lang argument, and lang defaulting to 'eng'. There should be a parameter supporting other languages

I'm tempted to suggest that the word param should only be accepted as a Word object - this seems like a better structure and means we can reduce repeated code (checking for strings etc)

jmsv commented 6 years ago

Looks perfect :heart_eyes: