hpdeifel / hledger-iadd

A terminal UI as drop-in replacement for hledger add.
BSD 3-Clause "New" or "Revised" License
77 stars 8 forks source link

Suggest accounts using bayesian inference #35

Open ggazzi opened 5 years ago

ggazzi commented 5 years ago

The current mechanism for suggesting accounts is sometimes a bit too rigid, since it requires exact matches of the description. Instead, multiple suggestions could be obtained with naive bayesian inference, and displayed in the context.

In terms of the UI, the following could be done: when the user was asked for an account and the input field is empty, a list of inferred accounts is displayed on the context. When a default account exists, it is always displayed as the first item, ensuring compatibility with previous behaviour. As soon as the user types something, the list of inferred accounts is replaced with the usual search results, so we don't constrain their choices.

I have been using this input scheme for a few weeks and found it quite useful. Nevertheless, suddenly replacing suggested accounts with search results might be confusing... Maybe it could be done better.

The suggested accounts are obtained by naive bayesian inference, which uses tokens extracted from the description, comments and existing postings to infer potential accounts. Description and comments are tokenized into textual, numeric and degraded dates, which was based heavily on https://tomszilagyi.github.io/payment-matching/.

I have a prototype of this, which I would gladly adapt/refine/add tests if there is any interest on merging it.

hpdeifel commented 5 years ago

Sorry for the late reply. I currently don't have the time to take a deeper look, but I'm definitely interested.

I need to play with it to say anything about the potential UI/UX, but the core concept sounds very nice. Maybe it would even be worth splitting out into a small library, so that other entry UIs could also benefit from it?