Skip to content

Instantly share code, notes, and snippets.

func learn(classifier *bayesian.Classifier) {
classifier.Learn(businessFiles, Business)
classifier.Learn(techFiles, Tech)
}
func enumerateClasses() {
businessDirectory := enumerateDirectory(businessDirectoryLocation) // retrieves a list of all filenames stored in the directory.
for _, file := range businessDirectory {
fileContent := readFile(file) // returns the entire contents of the files as a string.
businessFiles = append(businessFiles, fileContent)
func enumerateDirectory(location string) []string {
var files []string
listing, err := ioutil.ReadDir(location)
if err != nil {
panic(err)
}
for _, l := range listing {
files = append(files, location+"/"+l.Name())
}
return files
@kmaher9
kmaher9 / levenshtein.go
Created August 24, 2018 18:21
this is the only file needed - it is a package implementation of the Levenshtein Distance algorithm, as used in string comparison.
package levenshtein
import (
"unicode/utf8"
)
func computeLevenshteinValue(a, b string) int {
f := make([]int, utf8.RuneCountInString(b)+1)
for j := range f {