コード例 #1
0
ファイル: main.go プロジェクト: hagna/typefaster
/* Decode strokes this ought to run at some high rate in hz */
func (m *Mcs) keystates(keys []bool) bool {
	if keysup(keys) {
		// got a stroke
		if m.buf == 0xff {
			return false //quit
		}
		if m.buf != 0 {
			fmt.Printf("%x\n", m.buf)

			phon := decode(0x3f & m.buf)
			ebuf := typefaster.Encode(phon)
			m.cword = append(m.cword, ebuf)
			fmt.Println(ebuf)
			if isLast(m.buf) {
				we := strings.Join(m.cword, "")
				a, i := m.Tree.Lookup(m.Tree.Root(), we, 0)
				if a.Key != we {
					fmt.Printf("closest match to \"%s\" was \"%s\"\n", typefaster.Decode(we), typefaster.Decode(a.Key[:i]))
				}
				if len(a.Value) == 0 {
					fmt.Println("Here are all the spellings with a common prefix.")
					fmt.Println(a)
					//m.Tree.Print(os.Stdout, a, "")
				} else {
					m.serial.Write(append([]byte(a.Value[0]), 0x20))
					fmt.Println(a.Value)
				}

				m.cword = []string{}
			}

			m.buf = 0
			fmt.Println(phon)

		}
	} else {
		m.buf |= decodestate(keys)
		return true
	}
	return true
}
コード例 #2
0
ファイル: main.go プロジェクト: hagna/typefaster
func main() {
	flag.Parse()
	if *genfromiphod != "" {
		var tree *typefaster.DiskTree
		var err error
		if tree, err = typefaster.Maketree(*genfromiphod, *treename); err != nil {
			log.Println("problem loading iphod")
		}
		fmt.Println(tree)

		return
	}
	if *print {
		t := typefaster.NewDiskTree(*treename)
		t.Print(os.Stdout, t.Root(), "")
		return
	}
	if *lookup {
		tree := typefaster.NewDiskTree(*treename)
		for _, w := range flag.Args() {
			we := typefaster.Encode(w)
			a, i := tree.Lookup(tree.Root(), we, 0)
			if a.Key != we {
				fmt.Printf("closest match \"%s\"\n", typefaster.Decode(a.Key[:i]))
			}
			if len(a.Value) == 0 {
				fmt.Println("Here are all the spellings with a common prefix.")
				tree.Print(os.Stdout, a, "")
			} else {
				fmt.Println(a.Value)
			}
		}
		return
	}

	total := 0
	utotal := 0
	ucount := 0
	for _, fname := range flag.Args() {
		fh, err := os.Open(fname)
		if err != nil {
			fmt.Println(err)
		}
		defer fh.Close()
		scanner := bufio.NewScanner(fh)
		scanner.Split(bufio.ScanWords)
		for scanner.Scan() {
			w := scanner.Text()
			if res, ok := typefaster.IPHOD[w]; ok {
				if *verbose {
					fmt.Println(res.Phonemes)
				}
				total += res.Nphones
			} else {
				if *verbose {
					fmt.Printf("Unknown:%s\n", w)
				}
				utotal += len(w)
				ucount += 1
			}
		}
		if !*verbose {
			fmt.Printf("%d phonemes\n%d unknown words of total length %d\n", total, ucount, utotal)
		}
	}
}