CONNOR DOT
RECIPES online
The Art of Distributed Computing
Second Edition
var (
totalGrams []int
sortedGrams [][]ngrams.Gram
)
func check(err error) {
if err != nil {
log.Print(err)
os.Exit(1)
}
}
func refilter(this js.Value, args []js.Value) interface{} {
js.Global().Get("document").Call("getElementById", "results").Set("innerHTML", ngrams.Display(totalGrams, sortedGrams))
return nil
}
func parseInput(this js.Value, args []js.Value) interface{} {
inputText := js.Global().Get("document").Call("getElementById", "inputbox").Get("value").String()
totalGrams, sortedGrams = ngrams.Count(inputText)
js.Global().Get("document").Call("getElementById", "results").Set("innerHTML", ngrams.Display(totalGrams, sortedGrams))
return nil
}
func load(corpus string) {
// callback?
js.Global().Get("document").Call("getElementById", "results").Set("innerHTML", ngrams.Display(totalGrams, sortedGrams))
}
func initCedict(this js.Value, args []js.Value) interface{} {
start := time.Now()
cu.AddEntries(args[0].String())
fmt.Println("Initializing CEDICT entries took ", time.Now().Sub(start))
return nil
}
func main() {
c := make(chan struct{}, 0)
start := time.Now()
js.Global().Set("initCedict", js.FuncOf(initCedict))
js.Global().Set("parseInput", js.FuncOf(parseInput))
js.Global().Set("refilter", js.FuncOf(refilter))
fmt.Println("Initializing wasm took ", time.Now().Sub(start))