Exemplo n.º 1
0
Arquivo: main.go Projeto: rosrad/grid
func main() {
	var list, outdir string
	var justfmt bool
	flag.StringVar(&list, "list", "", "file of the words")
	flag.StringVar(&outdir, "outdir", "", "the output of the mp3 place and new config file")
	flag.BoolVar(&justfmt, "justfmt", false, "just format the new configfile no audio file downloading")
	flag.Parse()
	list, _ = filepath.Abs(list)
	if len(outdir) <= 0 {
		outdir = filepath.Join(filepath.Dir(list), "words_audio")
	}
	os.RemoveAll(outdir)
	os.MkdirAll(outdir, os.ModeDir)
	lines, _ := util.ReadLines(list)
	out := filepath.Join(outdir, filepath.Base(list)+".new")
	fout, err := os.OpenFile(out, os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
	defer fout.Close()
	if err != nil {
		fmt.Println("create output file Error", err)
		return
	}

	for _, word := range lines {
		key, newline := parse_keyword(word)
		fout.WriteString(newline + "\r\n")
		if !justfmt {
			fetch_speech(key, outdir)
		}
	}
}
Exemplo n.º 2
0
func main() {
	var file string
	flag.StringVar(&file, "file", "", "file of the words")
	flag.Parse()
	fmt.Println(file)
	file, _ = filepath.Abs(file)
	outdir := filepath.Join(filepath.Dir(file), "hujiang")
	os.RemoveAll(outdir)
	os.MkdirAll(outdir, os.ModeDir)
	out := filepath.Join(outdir, filepath.Base(file)+".new")
	fout, err := os.OpenFile(out, os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
	defer fout.Close()
	if err != nil {
		fmt.Println("create output file Error", err)
		return
	}
	lines, err := util.ReadLines(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, line := range lines {
		res, suc := cuter(line)
		if suc {
			newline := res.word + res.ext + "-"
			newline += strings.Join(res.meanings, "<br/>")
			fout.WriteString(newline + "\r\n")
		}
	}
}
Exemplo n.º 3
0
func loadChunk(level, lesson, chunk string, lessPtr *Lesson) *Chunk {
	log.Printf("Loading chunk : %v / %v / %v...", level, lesson, chunk)

	lines := util.ReadLines(config.Conf.ContentsFolder + "/" + level + "/" + lesson + "/" + chunk)

	return parseChunk(lines, lessPtr)
}
Exemplo n.º 4
0
func parseEdict(filename string, c chan *DicEntry) {
	lines := util.ReadLines(filename)
	for _, line := range lines {
		e := parseEdictEntry(line)
		if e != nil {
			c <- e
		}
	}
	c <- nil
}
Exemplo n.º 5
0
Arquivo: em.go Projeto: rosrad/grid
func main() {

	var gs [2]Gauss
	gs[0].W = 0.5
	gs[0].W = 0.5
	gs[0].U = 1
	gs[1].U = 1
	gs[0].A = 1
	gs[1].A = 0
	lines, _ := util.ReadLines("D:/trainingdata/data2.csv")

	var sum_r1, sum_r2 float64
	var sum_u1, sum_u2 float64 //expection
	var sum_a1, sum_a2 float64 //variance
	for i := 0; i < 10; i++ {
		sum_r1 = 0
		sum_r2 = 0
		sum_u1 = 0
		sum_u2 = 0
		sum_a1 = 0
		sum_a2 = 0
		for _, content := range lines {
			fmt.Println(content)
			x, _ := strconv.ParseFloat(content, len(content))
			fmt.Println("X=", x)
			gs[0].X = x
			gs[1].X = x
			r1 := gs[0].W * Gaussian(gs[0]) / (gs[0].W*Gaussian(gs[0]) + gs[1].W*Gaussian(gs[1]))
			fmt.Println("r1=", r1)
			r2 := 1 - r1
			sum_r1 += r1
			sum_u1 += r1 * x
			sum_a1 += r1 * x * x
			sum_r2 += r2
			sum_u2 += r2 * x
			sum_a2 += r2 * x * x
		}
		fmt.Println(sum_r1, sum_r2)
		gs[0].U = sum_u1 / sum_r1
		gs[0].A = sum_a1 / sum_r1
		gs[0].W = sum_r1 / float64(len(lines))

		gs[1].U = sum_u2 / sum_r2
		gs[1].A = sum_a2 / sum_r2
		gs[1].W = sum_r2 / float64(len(lines))
	}
	for key, item := range gs {
		fmt.Printf("Gaussion%d W = %f        U = %f     A=%f/n", key, item.W, item.U, item.A)

	}

}
Exemplo n.º 6
0
func (t *extendedTemplate) load(file string) {
	if _, ok := t.files[file]; ok {
		return
	}
	t.files[file] = true

	lines := util.ReadLines(t.baseDir + "/" + file + ".html")
	current := "main"
	if _, ok := t.chunks["main"]; !ok {
		t.chunks["main"] = make([]string, 0)
	}

	for _, l := range lines {
		if len(l) > 7 && l[0:7] == "~~LOAD " {
			t.load(l[7:])
		} else if len(l) > 9 && l[0:9] == "~~DEFINE " {
			current = l[9:]
			t.chunks[current] = make([]string, 0)
		} else {
			t.chunks[current] = append(t.chunks[current], l)
		}
	}
}