wordShuffler

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

wordShuffler

engine for shuffling / scrambling words. Could be education purpose or gamification usage

dictionary matching feature

a dictionary of english worlds sourced from https://github.com/dwyl/english-words.

Documentation

Index

Constants

View Source
const DefaultDictionaryCacheSize = 20
View Source
const DefaultDictionaryLocation = "words_alpha.txt"

default dictionary path

View Source
const EnvVariableDictLocation = "MATCHER_DICT_LOCATION"

default environment variable name => "MATCHER_DICT_LOCATION"

View Source
const KeyLangFrom = "key_lang_from"
View Source
const KeyLangTo = "key_lang_to"
View Source
const LookupOperationType = "lookup_operation_type"

Variables

This section is empty.

Functions

func GetArrayFromJsonByPath

func GetArrayFromJsonByPath(data []byte, path string) ([]*gabs.Container, error)

func IsWordValid

func IsWordValid(word string) bool

handy method to check if the given word is valid (not just space)

func ReadFileContent

func ReadFileContent(file string) (string, error)

read the contents of a given file

func RunHttpRequest

func RunHttpRequest(url string, optional ...map[string]interface{}) ([]byte, error)

run an http request based on the given url, an optional map object could be supplied for optional parameters

func SeekFileLocation

func SeekFileLocation(location string, envVariableName string) (string, error)

method to check if the targeted file exists or not and return the 1st matched path which could be the path given or the value under the env-var

Types

type AdvanceSuffleRule

type AdvanceSuffleRule interface {
	// shuffle the given sequence and return a list of possible "words"
	Shuffle(sequence string, optionalArgs ...map[string]interface{}) ([]string, error)
}

type CambridgeRule

type CambridgeRule struct{}

rule based on the Cambridge research

func (*CambridgeRule) Shuffle

func (r *CambridgeRule) Shuffle(oldText string) (string, error)

type DLGlosbe

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

func NewGlosbeEngine

func NewGlosbeEngine() *DLGlosbe

func (*DLGlosbe) Lookup

func (d *DLGlosbe) Lookup(word string, optionalParams map[string]interface{}) ([]DictionaryLookupResult, error)

func (*DLGlosbe) Source

func (d *DLGlosbe) Source() string

type DLPearson

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

func NewPearsonEngine

func NewPearsonEngine() *DLPearson

func (*DLPearson) Lookup

func (d *DLPearson) Lookup(word string, optionalParams map[string]interface{}) ([]DictionaryLookupResult, error)

func (*DLPearson) Source

func (d *DLPearson) Source() string

type DictionaryLookup

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

func NewDictionaryLookup

func NewDictionaryLookup(cacheSize ...int) *DictionaryLookup

create a new instance of DictionaryLookup with an optional cache size; if the cache size is not given, the default size of "20" is used

func (*DictionaryLookup) Lookup

func (d *DictionaryLookup) Lookup(word string, optionalParams map[string]interface{}) ([]DictionaryLookupResult, error)

type DictionaryLookupEngine

type DictionaryLookupEngine interface {
	// returns an arbitrary string to describe the lookup engine (e.g. webster dictionary api)
	Source() string
	// do the lookup for the given "word", wraps the results into
	// an array of DictionaryLookupResult
	Lookup(word string, optionalParams map[string]interface{}) ([]DictionaryLookupResult, error)
}

interface for a dictionary lookup engine / approach

type DictionaryLookupResult

type DictionaryLookupResult struct {
	Text     string
	Language string
}

func NewDictionaryLookupResult

func NewDictionaryLookupResult(text, lang string) DictionaryLookupResult

return a new instance of the lookup result

type DictionaryMatcher

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

Matcher implementation based on the Matcher interface involves efficient indexing of the chunk of dictionary entries (e.g. lazy loading of dictionary sections based word prefix match)

func NewDictionaryMatcher

func NewDictionaryMatcher(location ...string) DictionaryMatcher

create a new instance of DictionaryMatcher

func (*DictionaryMatcher) MatchWord

func (d *DictionaryMatcher) MatchWord(word string) (bool, error)

type GramSequencer

type GramSequencer struct {
	// the sequence involved for "word" formation and matching later on
	Sequence string
	// contains filtered or unexported fields
}

func NewGramSequencer

func NewGramSequencer(sequence string, minSeqSize, maxSeqSize int,
	matcherRule MatcherRule, shuffleRule AdvanceSuffleRule) GramSequencer

method to create an instance of GramSequencer

func NewGramSequencerSimple

func NewGramSequencerSimple(sequence string) GramSequencer

method to create an instance of GramSequencer

func (*GramSequencer) GenerateValidSequences

func (g *GramSequencer) GenerateValidSequences() error

method to generate "valid" sequences created from the given sequence. Valid or not depends on the implementation of the Matcher

func (*GramSequencer) GetValidSequences

func (g *GramSequencer) GetValidSequences() []string

simple getter

type MatcherRule

type MatcherRule interface {
	// method to match the given word against a "source"; could be a dictionary.
	MatchWord(word string) (bool, error)
}

interface encapsulating matching rules with a "source" (e.g. dictionary)

type SequenceShufflerRule

type SequenceShufflerRule struct {
	// the minimum size of the "words" to be created from the given sequence.
	// Theoretically it should be at least "2"
	MinGramSize int
	// optional size threshold for the sequence generation (remember the
	// longer is the sequence, the more computation is required)
	MaxGramSize int
	// contains filtered or unexported fields
}

func NewSequenceShufflerRule

func NewSequenceShufflerRule(minSize, maxSize int, sequence string) SequenceShufflerRule

create a new instance of SequenceShufflerRule

func (*SequenceShufflerRule) Shuffle

func (s *SequenceShufflerRule) Shuffle(sequence string, optionalArgs ...map[string]interface{}) ([]string, error)

implementation of the ShuffleRule; however the returned string value is not meaningful in here. Instead should invoke "GetValidSequences" method

type ShuffleRule

type ShuffleRule interface {
	// shuffle the given / old text based on its unique rules
	Shuffle(oldText string) (string, error)
}

interface encapsulating shuffling rules

type Shuffler

type Shuffler struct {
	// location of the file containing the text (could be empty value "")
	Location string
	// Shuffle Rule
	Rule ShuffleRule
	// contains filtered or unexported fields
}

func NewShuffler

func NewShuffler(location string, shuffleRule ...ShuffleRule) Shuffler

func (*Shuffler) GetShuffleGrams

func (s *Shuffler) GetShuffleGrams() []string

return the shuffled / new grams

func (*Shuffler) GetShuffleText

func (s *Shuffler) GetShuffleText() string

return the shuffled / new text

func (*Shuffler) ShuffleText

func (s *Shuffler) ShuffleText(oldText ...string) (string, error)

shuffle the text. If no text is provided, will try to extract the text from the file location WHICH might also be empty ""; if that is the case, an error would be thrown

Jump to

Keyboard shortcuts

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