Exemplo n.º 1
0
func word2vec(word string, k int) string {
	args := make([]interface{}, 1)
	args[0] = word

	r, err := httpjsonrpc.Call(config.Word2VecServer, "expand", 0, args)
	if err != nil {
		log.Printf("verbose error info: %#v", err)
	}

	if _, ok := r["result"]; !ok {
		log.Println("Word2Vec: not getting any result")
		return ""
	}

	x, ok := r["result"].([]interface{})
	if !ok {
		log.Println("Word2Vec: cannot parse the result")
		return ""
	} else {
		strs := make([]string, len(x))
		for i, item := range x {
			strs[i] = item.(string)
		}
		if len(strs) > k {
			strs = strs[:k]
		}
		result := strings.Join(strs, " ")
		log.Printf("Word2Vec expanded '%s' to '%s'\n", word, result)
		return result
	}
}
Exemplo n.º 2
0
func GetHeadWord(question string) chan string {
	c := make(chan string, 1)

	go func() {
		args := make([]interface{}, 1)
		args[0] = []string{question}

		r, err := httpjsonrpc.Call(config.HeadWordServer, "extract_headchunks", 0, args)
		if err != nil {
			log.Printf("Unable to get headword for '%s'\n", question)
			c <- ""
			return
		}

		if _, ok := r["result"]; !ok {
			// We didn't receive a result
			log.Printf("Headword: HeadWord at '%s' question '%s' had no result from the server (%s, %T)\n", config.HeadWordServer, question, r, r)
			c <- ""
			return
		}

		x, ok := r["result"].([]interface{})
		if ok {
			str, ok := x[0].(string)
			if ok {
				c <- str
			} else {
				log.Printf("Headword: Not string (%s, %T)\n", x[0], x[0])
				// We didn't receive a string
				c <- ""
			}
		} else {
			log.Printf("Headword: Not array (%s, %T)\n", r["result"], r["result"])
			// we didn't recieve a result
			c <- ""
		}
	}()
	return c
}
Exemplo n.º 3
0
func wordnet(word string, k int) string {
	args := make([]interface{}, 1)
	args[0] = []string{word}

	r, err := httpjsonrpc.Call(config.HeadWordServer, "synonyms", 0, args)
	if err != nil {
		log.Printf("verbose error info: %#v", err)
	}

	if _, ok := r["result"]; !ok {
		log.Println("wordnet: not getting any result")
		return ""
	}

	x, ok := r["result"].([]interface{})
	if !ok {
		log.Println("wordnet: cannot parse the result")
		return ""
	}

	x0, ok := x[0].([]interface{})
	if !ok {
		log.Println("wordnet: cannot parse the result")
		return ""
	}

	strs := make([]string, len(x0))
	for i, item := range x0 {
		strs[i] = item.(string)
	}
	if len(strs) > k {
		strs = strs[:k]
	}

	result := strings.Join(strs, " ")
	log.Printf("wordnet expanded '%s' to '%s'\n", word, result)
	return result
}