Ejemplo n.º 1
0
func worker(classifier *b.Classifier, filename string) {
	file, err := os.Open(filename)
	defer file.Close()
	if err != nil {
		panic(err.Error())
	}

	reader := csv.NewReader(file)
	for {
		record, err := reader.Read()
		if err == io.EOF {
			break
		}

		count, err := strconv.ParseInt(record[2], 10, 64)
		if err != nil {
			panic(err.Error())
		}

		name := strings.ToLower(record[0])
		idx := 0
		for idx <= int(count) {
			c.Learn(classifier, name, record[1])
			idx++
		}

	}
	fmt.Println("done.")
}
Ejemplo n.º 2
0
func worker(classifier *b.Classifier, year int, done chan bool) {
	filename := fmt.Sprintf("names/yob%d.txt", year)
	file, _ := os.Open(filename)
	defer file.Close()

	reader := csv.NewReader(file)
	for {
		record, err := reader.Read()
		if err == io.EOF {
			break
		}

		count, _ := strconv.ParseInt(record[2], 10, 8)
		name := strings.ToLower(record[0])
		idx := 0
		for idx <= int(count) {
			c.Learn(classifier, name, record[1])
			idx++
		}
	}
	fmt.Println("finished parsing", filename)
	done <- true
}