jmsv/ety-python

tree should check word exists

jmsv opened this issue · 2 comments

jmsv commented
$ ety asdfghjkl -t
asdfghjkl (English)

Always outputs '(English)', since it's the default language. The word should be looked up in the data and not displayed if missing

Just for reference: the command line appears to be fixed, and correctly displays:

$ python -m ety -t asfgds
No origins found for word: 'asfgds'

but the api still generates a Tree with one node.

>>> print(ety.tree("asfgds"))
asfgds (English)

Not sure what the correct return value should be if the word has no origins. Maybe None? Logically as .origins() returns an empty to list, I would say .tree() should return an empty tree. But, it's not possible to return an empty Tree as trying to print it throws an error:

>>> print(Tree())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/treelib/tree.py", line 120, in __str__
    self.__print_backend(func=write)
  File "/treelib/tree.py", line 170, in __print_backend
    line_type):
  File "/treelib/tree.py", line 199, in __get_iter
    raise NodeIDAbsentError("Node '%s' is not in the tree" % nid)
treelib.exceptions.NodeIDAbsentError: Node 'None' is not in the tree

Is it also a possibility with the planned changes from #24 that when a Word object is created, we could check to see if it's valid. But then what about leaf nodes.

jmsv commented

Hmm, None makes sense imo. I considered raising a ValueError but that seems like a worse idea

If we went with this behaviour, it might also make sense to also make origins return None, rather than an empty list