~whereswaldon/ledger

428e2d4155402ad1e93f95fd4f5630f581923dff — Ian Bishop 1 year, 7 months ago 9cdfd1a
Improve baysian matching for import (#38)

* Improve baysian matching of accounts
1 files changed, 13 insertions(+), 4 deletions(-)

M ledger/cmd/import.go
M ledger/cmd/import.go => ledger/cmd/import.go +13 -4
@@ 70,8 70,20 @@ var importCmd = &cobra.Command{
		classifier := bayesian.NewClassifier(classes...)
		for _, tran := range generalLedger {
			payeeWords := strings.Fields(tran.Payee)
			// learn accounts names (except matchingAccount) for transactions where matchingAccount is present
			learnName := false
			for _, accChange := range tran.AccountChanges {
				classifier.Learn(payeeWords, bayesian.Class(accChange.Name))
				if accChange.Name == matchingAccount {
					learnName = true
					break
				}
			}
			if learnName {
				for _, accChange := range tran.AccountChanges {
					if accChange.Name != matchingAccount {
						classifier.Learn(payeeWords, bayesian.Class(accChange.Name))
					}
				}
			}
		}



@@ 117,9 129,6 @@ var importCmd = &cobra.Command{
						if j == 0 {
							matchScore = score
						}
						if string(classifier.Classes[j]) == csvAccount.Name {
							continue
						}
						if score > matchScore {
							matchScore = score
							matchIdx = j