vocabulary

package module
v0.0.0-...-ca7289b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2015 License: MIT Imports: 5 Imported by: 2

README

Vocabulary

An English-language dictionary and thesaurus in a Go package by Karan Goel.

Build Status

Golang port of the Python counterpart.

For a given word, Vocabulary will give you:

  • Meaning
  • Synonyms
  • Antonyms
  • Part of speech: whether the word is a noun, interjection or an adverb et el
  • Usage example: a quick example on how to use the word in a sentence

Features

  • Written in idiomatic Go
  • No external dependencies
  • So easy, a five-year-old can use it
  • Works on Mac, Linux and Windows.

Installation

$ go get -u github.com/karan/vocabulary

Usage

Get API keys
  1. Big Huge Thesaurus
  • Required for Antonyms
  1. Wordnik
  • Required for PartOfSpeech

Calling vocabulary.Word() with any word as a string will return a vocabulary.Word type object that has all possible information about it.

Or if you just want selective information, you can call individual functions passing in a word (vocabulary.Meanings("hallucination")).

package main

// Simple example usage of
//  github.com/karan/vocabulary

import (
  "fmt"
  "log"

  "github.com/karan/vocabulary"
)

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)

}

Tests

Create examples/api_keys.go with your API keys:

package main

const (
  BigHugeLabsApiKey = "xxxx"
  WordnikApiKey     = "xxxx"
)

Then, to run the tests, use this command:

$ go test
PASS

Bugs

Please use the issue tracker to submit any bugs or feature requests.

License

MIT License © Karan Goel

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BigHugeLabsApiKey string // API key from BigHugeLabs
	WordnikApiKey     string // API key from Wordnik
}

Config represents the configuration settings.

type Error

type Error string

Error represents an error.

func (Error) Error

func (e Error) Error() string

Error implements the built-in error interface.

type Glosbe

type Glosbe struct {
	Result string            `json:"result"`
	Tuc    []json.RawMessage `json:"tuc"`
}

type GlosbeMeanings

type GlosbeMeanings struct {
	Things []GlosbeThing `json:"meanings"`
}

type GlosbePhrase

type GlosbePhrase struct {
	Thing GlosbeThing `json:"phrase"`
}

type GlosbeThing

type GlosbeThing struct {
	Text string `json:"text"`
}

type PartOfSpeech

type PartOfSpeech struct {
	POS          string `json:"partOfSpeech"` // The part of speech for the word
	ExampleUsage string `json:"text"`         // An example usage for the word in POS
}

Represents the part of speech of a word

type UrbanDictResp

type UrbanDictResp struct {
	Things []UrbanDictThing `json:"list"`
}

type UrbanDictThing

type UrbanDictThing struct {
	Example    string `json:"example"`
	ThumbsUp   int    `json:"thumbs_up"`
	ThumbsDown int    `json:"thumbs_down"`
}

type Vocabulary

type Vocabulary struct {
	// contains filtered or unexported fields
}

Vocabulary object represents an instance of vocabulary

func New

func New(c *Config) (Vocabulary, error)

New Instantiates a new instance of Vocabulary with the passed config.

func (Vocabulary) Antonyms

func (v Vocabulary) Antonyms(w string) ([]string, error)

Returns a list of strings representing the antonyms of the given word.

func (Vocabulary) Meanings

func (v Vocabulary) Meanings(w string) ([]string, error)

Returns a list of strings representing the meanings of the given word.

func (Vocabulary) PartOfSpeech

func (v Vocabulary) PartOfSpeech(w string) ([]PartOfSpeech, error)

Returns a list of PartOfSpeech structs representing the POS of the given word.

func (Vocabulary) Synonyms

func (v Vocabulary) Synonyms(w string) ([]string, error)

Returns a list of strings representing the synonyms of the given word.

func (Vocabulary) UsageExample

func (v Vocabulary) UsageExample(w string) ([]string, error)

Returns a list of strings representing usage examples of the given word.

func (Vocabulary) Word

func (v Vocabulary) Word(w string) (Word, error)

Creates a new Word object collecting as much information as possible. Requires having all API keys.

type Word

type Word struct {
	Word         string         // The original word in the query
	Meanings     []string       // A list of meanings for this word
	Synonyms     []string       // A list of synonyms for this word
	Antonyms     []string       // A list of antonyms for this word
	PartOfSpeech []PartOfSpeech // A list of part of speech for this word
	UsageExample []string       // A list of sentences showing usage example for the word
}

Represents a word with all its information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL