Exemplo n.º 1
0
func main() {
	// Set the API keys
	// Some functions require API keys. Refer to docs.
	// If API keys are not required, simple set empty strings as config:
	c := &vocabulary.Config{BigHugeLabsApiKey: BigHugeLabsApiKey, WordnikApiKey: WordnikApiKey}

	// Instantiate a Vocabulary object with your config
	v, err := vocabulary.New(c)
	if err != nil {
		log.Fatal(err)
	}

	// Create a new vocabulary.Word object, and collects all possible information.
	word, err := v.Word("vuvuzela")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("word.Word = %s \n", word.Word)
	fmt.Printf("word.Meanings = %s \n", word.Meanings)
	fmt.Printf("word.Synonyms = %s \n", word.Synonyms)
	fmt.Printf("word.Antonyms = %s \n", word.Antonyms)
	fmt.Printf("word.PartOfSpeech = %s \n", word.PartOfSpeech)
	fmt.Printf("word.UsageExample = %s \n", word.UsageExample)

	// Get just the synonyms
	// synonyms, err := v.Synonyms("area")
	// if err != nil {
	//   log.Fatal(err)
	// }
	// for _, s := range synonyms {
	//   fmt.Println(s)
	// }
	//

	// Get just the antonyms
	// ants, err := v.Antonyms("love")
	// if err != nil {
	//   log.Fatal(err)
	// }
	// for _, a := range ants {
	//   fmt.Println(a)
	// }

	// Get just the part of speech
	// pos, err := v.PartOfSpeech("love")
	// if err != nil {
	//   log.Fatal(err)
	// }
	// for _, a := range pos {
	//   fmt.Println(a)
	// }

	// Can also use:
	//  v.UsageExample(word)

}
Exemplo n.º 2
0
func TestAntonymsInvalidWord(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: e.BigHugeLabsApiKey, WordnikApiKey: ""}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := []string{}
	actual, _ := v.Antonyms("asfbhsdjfhdsj")
	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 3
0
func TestSynonyms(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: "", WordnikApiKey: ""}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := []string{"lepatata"}
	actual, _ := v.Synonyms("vuvuzela")
	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 4
0
func TestUsageExample(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: "", WordnikApiKey: ""}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := []string{"I went to the to of the hillock to look around."}
	actual, _ := v.UsageExample("hillock")
	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 5
0
func TestMeanings(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: "", WordnikApiKey: ""}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := []string{"A plastic blowing horn, typically 65 cm long, that produces a loud and monotone note."}
	actual, _ := v.Meanings("vuvuzela")
	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 6
0
func TestPartOfSpeechInvalidWord(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: "", WordnikApiKey: e.WordnikApiKey}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := []vocabulary.PartOfSpeech{}
	actual, _ := v.PartOfSpeech("asfbhsdjfhdsj")
	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 7
0
func TestPartOfSpeech(t *testing.T) {
	c := &vocabulary.Config{BigHugeLabsApiKey: "", WordnikApiKey: e.WordnikApiKey}
	v, err := vocabulary.New(c)
	if err != nil {
		t.Errorf("Test failed: %s", err)
	}

	expected := vocabulary.PartOfSpeech{"adverb", "With speed; in a rapid manner."}
	actual, _ := v.PartOfSpeech("rapidly")
	if !reflect.DeepEqual(expected, actual[0]) {
		t.Errorf("Test failed, expected: '%s', got:  '%s'", expected, actual)
	}
}
Exemplo n.º 8
0
func main() {
	// Set the API keys
	// Some functions require API keys. Refer to docs.
	// If API keys are not required, simple set empty strings as config:
	BigHugeLabsApiKey := ""
	WordnikApiKey := ""
	c := &vocabulary.Config{BigHugeLabsApiKey: BigHugeLabsApiKey, WordnikApiKey: WordnikApiKey}

	// Instantiate a Vocabulary object with your config
	v, err := vocabulary.New(c)
	if err != nil {
		log.Fatal(err)
	}

	// Create a new vocabulary.Word object, and collects all possible information.
	// word, err := v.Word("vuvuzela")
	// if err != nil {
	// 	log.Fatal(err)
	// }

	// fmt.Printf("word.Word = %s \n", word.Word)
	// fmt.Printf("word.Meanings = %s \n", word.Meanings)
	// fmt.Printf("word.Synonyms = %s \n", word.Synonyms)
	// fmt.Printf("word.Antonyms = %s \n", word.Antonyms)
	// fmt.Printf("word.PartOfSpeech = %s \n", word.PartOfSpeech)
	// fmt.Printf("word.UsageExample = %s \n", word.UsageExample)

	if len(os.Args) < 2 {
		fmt.Println("Provide word as argument")
		os.Exit(1)
	}

	fmt.Println("Word:", os.Args[1])

	// Get just the synonyms
	fmt.Println("\n\nSynonym:\n-------")
	synonyms, err := v.Synonyms(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	for _, s := range synonyms {
		fmt.Println(s)
	}

	fmt.Println("\n\nMeaning:\n-------")
	meanings, err := v.Meanings(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	for _, s := range meanings {
		fmt.Println(s)
	}

	fmt.Println("\n\nUsage Example:\n-------")
	usages, err := v.UsageExample(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	for _, s := range usages {
		fmt.Println(s)
	}

	// Get just the antonyms
	// ants, err := v.Antonyms("love")
	// if err != nil {
	//   log.Fatal(err)
	// }
	// for _, a := range ants {
	//   fmt.Println(a)
	// }

	// Get just the part of speech
	// pos, err := v.PartOfSpeech("love")
	// if err != nil {
	//   log.Fatal(err)
	// }
	// for _, a := range pos {
	//   fmt.Println(a)
	// }

	// Can also use:
	//  v.UsageExample(word)

}