From 90f53d2098a8bbbb5bd7f66ce4a63d8bbeb292c0 Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Mon, 15 Apr 2013 18:33:14 -0500 Subject: [PATCH] Move files --- .gitignore | 1 - cmd/ledger/classify.go | 25 +++++++++++++++++++++++++ ledger.go => cmd/ledger/ledger.go | 0 main.go => cmd/ledger/main.go | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 cmd/ledger/classify.go rename ledger.go => cmd/ledger/ledger.go (100%) rename main.go => cmd/ledger/main.go (95%) diff --git a/.gitignore b/.gitignore index 055417d9..44a1b5c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ *.dat *.exe -ledger diff --git a/cmd/ledger/classify.go b/cmd/ledger/classify.go new file mode 100644 index 00000000..f4941c30 --- /dev/null +++ b/cmd/ledger/classify.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "strings" + + "github.com/jbrukh/bayesian" +) + +func classifyPayee(generalLedger []*Transaction, balances []*Account, payee string) { + classes := make([]bayesian.Class, len(balances)) + for i, bal := range balances { + classes[i] = bayesian.Class(bal.Name) + } + classifier := bayesian.NewClassifier(classes...) + for _, tran := range generalLedger { + payeeWords := strings.Split(tran.Payee, " ") + for _, accChange := range tran.AccountChanges { + classifier.Learn(payeeWords, bayesian.Class(accChange.Name)) + } + } + inputPayeeWords := strings.Split(payee, " ") + _, likely, _ := classifier.LogScores(inputPayeeWords) + fmt.Println(classifier.Classes[likely]) +} diff --git a/ledger.go b/cmd/ledger/ledger.go similarity index 100% rename from ledger.go rename to cmd/ledger/ledger.go diff --git a/main.go b/cmd/ledger/main.go similarity index 95% rename from main.go rename to cmd/ledger/main.go index 533c7d10..db10f2e8 100644 --- a/main.go +++ b/cmd/ledger/main.go @@ -71,5 +71,7 @@ func main() { printLedger(os.Stdout, generalLedger, columnWidth) case "register", "reg": printRegister(generalLedger, containsFilterArray, columnWidth) + case "classify": + classifyPayee(generalLedger, getBalances(generalLedger, []string{}), args[1]) } }