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

Use tree object #27

Closed alxwrd closed 6 years ago

alxwrd commented 6 years ago

This changes Word.tree() so it returns the treelib.Tree object.

I also added using the data keyword argument for create_node as mentioned here: http://treelib.readthedocs.io/en/latest/examples.html#advanced-usage

>>> aero_tree = ety.tree("aerodynamically")
>>> aero_tree
<treelib.tree.Tree object at 0x7f5cd5c9dfd0>
>>> print(aero_tree)
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))

>>> aero_tree.show(data_property="language")
English
├── English
└── English
    ├── English
    │   └── Ancient Greek (to 1453)
    └── English
        └── French
            └── Ancient Greek (to 1453)
                └── Ancient Greek (to 1453)
                    └── Ancient Greek (to 1453)

>>> aero_tree.show(data_property="word")
aerodynamically
├── -ally
└── aerodynamic
    ├── aero-
    │   └── ἀήρ
    └── dynamic
        └── dynamique
            └── δυναμικός
                └── δύναμις
                    └── δύναμαι
jmsv commented 6 years ago

I didn't know you could do that 😲 looks cool