source

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 7 Imported by: 7

Documentation

Overview

Package source defines interfaces to be implemented by dictionary sources and common structures and operations for those implementations to use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualFoldPlain added in v0.2.0

func EqualFoldPlain(s, t string) bool

EqualFoldPlain reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding AFTER first having each string normalized.

func RemoveDiacritics added in v0.2.0

func RemoveDiacritics(text string) string

RemoveDiacritics takes a text and returns the same text with any diacritics removed. If there's an issue with cleaning the string, the original text is returned unchanged.

func ValidateDictionaryResults added in v0.2.0

func ValidateDictionaryResults(word string, results DictionaryResults) error

ValidateDictionaryResults validates the results of a define operation and returns an error if they're invalid

func ValidateHTTPResponse

func ValidateHTTPResponse(httpResponse *http.Response, validContentTypes []string, validStatusCodes []int) error

ValidateHTTPResponse validates an HTTP response and returns an error if the response is invalid

func ValidateSearchResults added in v0.3.0

func ValidateSearchResults(word string, results SearchResults) error

ValidateSearchResults validates the results of a search operation and returns an error if they're invalid

Types

type AttributedText added in v0.3.0

type AttributedText struct {
	Text string

	Attribution
}

AttributedText defines the structure of a general text with attribution

func (AttributedText) String added in v0.3.0

func (t AttributedText) String() string

String satisfies fmt.Stringer and dictates the string format of the value

type Attribution added in v0.3.0

type Attribution struct {
	Author string
	Source string
}

Attribution defines the structure of a general attribution of a data piece

type AuthenticationError

type AuthenticationError struct{}

AuthenticationError represents an error caused by an authentication problem

func (*AuthenticationError) Error

func (e *AuthenticationError) Error() string

type DictionaryEntry

type DictionaryEntry struct {
	Entry

	Senses      []Sense
	Etymologies []string // Origins of the word

	Pronunciations
	ThesaurusValues
}

DictionaryEntry defines the structure of a dictionary entry of a word

type DictionaryResult added in v0.2.0

type DictionaryResult struct {
	Language string
	Word     string
	Entries  []DictionaryEntry
}

DictionaryResult defines the structure of a dictionary word result in a specific language

type DictionaryResults added in v0.3.0

type DictionaryResults []DictionaryResult

DictionaryResults defines the structure of a list of dictionary word results

func ValidateAndReturnDictionaryResults added in v0.2.0

func ValidateAndReturnDictionaryResults(word string, results DictionaryResults) (DictionaryResults, error)

ValidateAndReturnDictionaryResults validates the results of a define operation and returns the results and a nil error if valid. If invalid, it'll return nil results and an error.

func (DictionaryResults) IsSortedForPrimaryResult added in v0.3.0

func (r DictionaryResults) IsSortedForPrimaryResult(word string) bool

IsSortedForPrimaryResult takes a word and returns true if the first result is a direct match.

func (*DictionaryResults) SortForPrimaryResult added in v0.3.0

func (r *DictionaryResults) SortForPrimaryResult(word string)

SortForPrimaryResult takes a word and attempts to find any direct match within the results. If any match is found, it moves that result to the first position of the results (while retaining the other results).

type EmptyResultError

type EmptyResultError struct {
	Word string
}

EmptyResultError represents an error caused by an empty result

func (*EmptyResultError) Error

func (e *EmptyResultError) Error() string

type Entry

type Entry struct {
	Word            string
	LexicalCategory string
}

Entry defines the structure of an entry of a specific word

type InvalidResponseError

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

InvalidResponseError represents an error caused by an invalid response

func (*InvalidResponseError) Error

func (e *InvalidResponseError) Error() string

type Pronunciation added in v0.3.0

type Pronunciation string

Pronunciation defines the structure of a pronunciation of a word

func (Pronunciation) String added in v0.3.0

func (p Pronunciation) String() string

String satisfies fmt.Stringer and dictates the string format of the value

type Pronunciations added in v0.3.0

type Pronunciations []Pronunciation

Pronunciations defines the structure of a collection of pronunciations

func (Pronunciations) String added in v0.3.0

func (p Pronunciations) String() string

String satisfies fmt.Stringer and dictates the string format of the value

type SearchResult added in v0.3.0

type SearchResult string

SearchResult defines the structure of a word search result

type SearchResults added in v0.3.0

type SearchResults []SearchResult

SearchResults defines the structure of a list of word search results

func ValidateAndReturnSearchResults added in v0.3.0

func ValidateAndReturnSearchResults(word string, results SearchResults) (SearchResults, error)

ValidateAndReturnSearchResults validates the results of a search operation and returns the results and a nil error if valid. If invalid, it'll return nil results and an error.

type Searcher added in v0.3.0

type Searcher interface {
	// Search takes a word string and returns a list of found words, and an
	// error if any occurred.
	Search(word string, limit uint) (SearchResults, error)
}

Searcher defines an interface for a source that supports search capabilities

type Sense

type Sense struct {
	Definitions []string
	Categories  []string
	Examples    []AttributedText
	Notes       []string

	ThesaurusValues

	SubSenses []Sense
}

Sense defines the structure of a particular meaning of a word

type Source

type Source interface {
	// Name returns the printable, human-readable name of the source.
	Name() string

	// Define takes a word string and returns a list of dictionary results, and
	// an error if any occurred.
	Define(word string) (DictionaryResults, error)
}

Source defines an interface for interacting with different dictionaries

type ThesaurusValues added in v0.2.0

type ThesaurusValues struct {
	Synonyms []string // Words with similar meaning
	Antonyms []string // Words with the opposite meaning
}

ThesaurusValues defines the structure of the thesaurus values of a word

Directories

Path Synopsis
Package freedictionaryapi provides a dictionary source via the "Free Dictionary API"
Package freedictionaryapi provides a dictionary source via the "Free Dictionary API"
Package oxford provides a dictionary source via the Oxford Dictionaries API
Package oxford provides a dictionary source via the Oxford Dictionaries API
Package webster provides a dictionary source via the Webster Dictionaries API
Package webster provides a dictionary source via the Webster Dictionaries API

Jump to

Keyboard shortcuts

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