Skip to content

A golang library to interface with system dictionaries and word lists

License

Notifications You must be signed in to change notification settings

kavfixnel/words

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Words

A golang library to interface with system dictionaries and word lists.

Go Reference

Word of caution

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.

Usage

There are 2 main functionalities in this library:

  1. 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
  1. 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

About

A golang library to interface with system dictionaries and word lists

Resources

License

Stars

Watchers

Forks

Packages

No packages published