words

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

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 known system words
    wordMap, err := words.NewWordMap(nil)
    if err != nil {
        panic(err)
    }

    fmt.Println(wordMap)

    // Get a []string of all known system words
    wordList, err := words.NewWordList(nil)
    if err != nil {
        panic(err)
    }

    fmt.Println(wordList)
}
  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)
}

Documentation

Overview

Package words provides a way to read system word lists

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidWord

func IsValidWord(word string, options *IsValidWordOptions) (bool, error)

IsValidWord takes a word and comparison options and tells you if given word is a valid word according to the local word lists. It returns the validness of the word and any errors encountered.

func NewWordList

func NewWordList(options *NewWordListOptions) ([]string, error)

NewWordList reads the systems word list(s) and returns them. It returns the sorted list of unique system words and any errors encountered.

func NewWordMap

func NewWordMap(options *NewWordMapOptions) (map[string]struct{}, error)

NewWordMap reads the systems word list(s) and returns them. It returns the map of system words and any errors encountered.

Types

type IsValidWordOptions

type IsValidWordOptions struct {

	// IgnoreCase tells the library if it should deduplicate words that are
	// are eqivalent with respect to case ("Hello" == "hello").
	IgnoreCase bool `default:"false"`

	// IgnoreDiacritics tells the library if it should deduplicate words that are
	// are eqivalent with respect to diacritics ("Aö" == "Ao").
	IgnoreDiacritics bool `default:"false"`

	// Language specifies the language of the system and it's word lists.
	Language language.Tag `default:"language.English"`
	// contains filtered or unexported fields
}

IsValidWordOptions defines the parameters of the IsValidWord function.

type NewWordListOptions

type NewWordListOptions struct {

	// IgnoreSort defines if the function should sort the list or merge the files of
	// words in the way the happen to appear.
	IgnoreSort bool `default:"false"`
	// contains filtered or unexported fields
}

NewWordListOptions configures the way the word list and maps should be contructed.

type NewWordMapOptions

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

NewWordMapOptions configures the way the word list and maps should be contructed.

Jump to

Keyboard shortcuts

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