Skip to content

Commit

Permalink
Move files
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Apr 15, 2013
1 parent 5a91880 commit 90f53d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*.dat
*.exe
ledger
25 changes: 25 additions & 0 deletions cmd/ledger/classify.go
Original file line number Diff line number Diff line change
@@ -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])
}
File renamed without changes.
2 changes: 2 additions & 0 deletions main.go → cmd/ledger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 90f53d2

Please sign in to comment.