Example #1
0
func Classify(w http.ResponseWriter, r *http.Request) {
	var task model.Task
	body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
	if err != nil {
		panic(err)
	}
	if err := r.Body.Close(); err != nil {
		panic(err)
	}
	if err := json.Unmarshal(body, &task); err != nil {
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		w.WriteHeader(422)
		if err := json.NewEncoder(w).Encode(err); err != nil {
			panic(err)
		}
	}

	model.InitStorage().SaveTask(&task)

	doc := objects.MakeDoc(task.Text)
	info := model.Info{len(doc.Tokens)}
	result := model.Result{
		Status: true, Error: "", Solution: "", Info: &info,
	}
	successJson(w, result)
}
Example #2
0
func termCount(set []string) (int, map[string]int) {
	counts := map[string]int{}
	var total int

	for _, sample := range set {
		doc := objects.MakeDoc(sample)
		docCounts := doc.CountTokens()

		for t, value := range docCounts {
			counts[t] += value
			total += value
		}
	}
	return total, counts
}