A golang library to interface with system dictionaries and word lists.
Right now the system has only been tested with MacOS, though according to The Unix word dictionary this library should also function on other unix systems.
There are 2 main functionalities in this library:
- Parsing and loading the system's word lists into memory
package main
import (
"fmt"
"github.com/kavfixnel/words"
)
func main() {
// Get a map[string]struct{} object of all words known by the system
wordMap, err := words.NewWordMap(nil)
if err != nil {
panic(err)
}
fmt.Println(len(wordMap))
// Get a []string of all known system words by the system
wordList, err := words.NewWordList(nil)
if err != nil {
panic(err)
}
fmt.Println(len(wordList))
}
~/examples/words ❯ go run main.go
235976
235976
- Check if words are valid and known by the system
package main
import (
"fmt"
"github.com/kavfixnel/words"
)
func main() {
mysteryWord := "abracadabra"
isValid, err := words.IsValidWord(mysteryWord, nil)
if err != nil {
panic(err)
}
modifier := ""
if !isValid {
modifier = " not"
}
fmt.Printf("%s is%s a valid word\n", mysteryWord, modifier)
// Ability to check variations of words
mysteryWord = "ÄbraCADabra"
isValid, err = words.IsValidWord(mysteryWord, &words.IsValidWordOptions{
IgnoreCase: true,
IgnoreDiacritics: true,
})
if err != nil {
panic(err)
}
modifier = ""
if !isValid {
modifier = " not"
}
fmt.Printf("%s is%s a valid word\n", mysteryWord, modifier)
}
~/examples/words ❯ go run main.go
abracadabra is a valid word
ÄbraCADabra is a valid word