Words - help with a word finder game, sketches a text-processing utility program

Shell-style text processing in Go

I saw a word game where the puzzle gives you six letters. By means of a clever user interface, you construct words from 3 or more of the letters. You use the words to fill in a cross-word puzzle style, cross-linked arrangement of words.

Wordscapes

I wrote a program to help find those words.

Design

I've written backtracking solutions to Knight's Tour N Queens and Sudoku by having a goroutine run a recursive function. When recursion terminates with a solution, the goroutine writes the solution to a channel. The main goroutine reads solutions and possibly eliminates duplicates.

I followed that pattern for this problem. I wrote a program that generated subsets of the letters of the solution words, and wrote them to a channel. Then I wrote a program that alphabetizes those letter subsets, and finds dictionary (/usr/share/dict/words) words that get spelled with a subset. It occurred to me to change those programs to functions that accept a Golang "in" channel and an "out" channel, run the functions in goroutines, and have the main program deduplicate solution words before output. I experienced a bug, and ended up writing a "tee" function that wrote words from its input channel to stdout before writing those words to its output channel. At that point, I had a pattern to follow, so I re-wrote all the functions to have "in" and "out" channels. func main() creates channels of string to link functions, then runs the functions each in their own goroutine.

I ended up with package processing

package processing

package processing // import "words/processing"

func CreateDictionary() map[string]bool
func MatchingDictionary() map[string][]string

func Deduplicate(in, out chan string)
func DictionaryCheck(in, out chan string)
func DictionaryMatches(in, out chan string)
func Sort(in, out chan string)
func WordKey(word string) string
func WordSubsets(word string, out chan string)

func Tee(in, out1, out2 chan string)
func TeeOut(in chan string)

This package makes a very easy main function:

func main() {
    ch1 := make(chan string, 10)
    ch2 := make(chan string, 10)
    ch3 := make(chan string, 10)
    ch4 := make(chan string, 10)

    go processing.WordSubsets(os.Args[1], ch1) // generate subsets of characters
    go processing.DictionaryMatches(ch1, ch2)  // dictionary words from subsets
    go processing.Deduplicate(ch2, ch3)        // remove duplicate dictionary words
    go processing.Sort(ch3, ch4)               // sort dictionary words alphabetically

    processing.TeeOut(ch4)
}

package processing isn't at all complete. It only hints at a useful set of functions.

A useful package would name an interface for the functions:

type Filter interface {
	Run(in, out chan string, arguments ...interface{})
}

At this point, I can't tell if naming "source" and "sink" interfaces would help. I wrote such functions, processing.WordSubsets and processing.TeeOut.

The obvious functions missing from the package are named file inputs and outputs, and regular expression matching. Other Unix shell commands suggest further functionality: tr, uniq, and counters like wc.

Once you've got a well-designed text-processing package, the next step is an interpreter that reads and parses interactive input, creates channels as necessary, and strings together goroutines running functions. This sounds rather like a text-processing shell, along the lines of jq, which handles JSON, not plain text, or GNU datamash.

Tenatively, the command language would look a lot like traditional Unix shell "pipelines". It looks like if you don't remember the past, you are doomed to repeat it.

Owner
Bruce Ediger
I like to write programs. I like to explore problems. I write all of my programs to run under Linux.
Bruce Ediger
Similar Resources

Parse placeholder and wildcard text commands

allot allot is a small Golang library to match and parse commands with pre-defined strings. For example use allot to define a list of commands your CL

Nov 24, 2022

Guess the natural language of a text in Go

guesslanguage This is a Go version of python guess-language. guesslanguage provides a simple way to detect the natural language of unicode string and

Dec 26, 2022

omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023

Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

Dec 19, 2022

Extract urls from text

xurls Extract urls from text using regular expressions. Requires Go 1.13 or later. import "mvdan.cc/xurls/v2" func main() { rxRelaxed := xurls.Relax

Jan 7, 2023

Change the color of console text.

go-colortext package This is a package to change the color of the text and background in the console, working both under Windows and other systems. Un

Oct 26, 2022

Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Mar 15, 2022

Package sanitize provides functions for sanitizing text in golang strings.

sanitize Package sanitize provides functions to sanitize html and paths with go (golang). FUNCTIONS sanitize.Accents(s string) string Accents replaces

Dec 5, 2022

Small and fast FTS (full text search)

Microfts A small full text indexing and search tool focusing on speed and space. Initial tests seem to indicate that the database takes about twice as

Jul 30, 2022
:book: A Golang library for text processing, including tokenization, part-of-speech tagging, and named-entity extraction.

prose prose is a natural language processing library (English only, at the moment) in pure Go. It supports tokenization, segmentation, part-of-speech

Jan 4, 2023
Parse line as shell words

go-shellwords Parse line as shell words. Usage args, err := shellwords.Parse("./foo --bar=baz") // args should be ["./foo", "--bar=baz"] envs, args, e

Dec 23, 2022
Similar to Anki but uses the actual frequency of words
Similar to Anki but uses the actual frequency of words

wordGame A program that uses a frequency-annotated vocabulary list to learn as efficiently as possible. Usage go run wordGame.go -freqTableFname=itali

Sep 21, 2021
A UTF-8 and internationalisation testing utility for text rendering.

ɱéťàł "English, but metal" Metal is a tool that converts English text into a legible, Zalgo-like character swap for the purposes of testing localisati

Jan 1, 2023
Convert Microsoft Word Document to Markdown
Convert Microsoft Word Document to Markdown

docx2md Convert Microsoft Word Document to Markdown Usage $ docx2md NewDocument.docx Installation $ go get github.com/mattn/docx2md Supported Styles

Jan 4, 2023
A targeted word list generation tool
A targeted word list generation tool

dirtywords Inspired by gau, dirtywords builds targeted wordlists for a given domain using "dirty" knowledge from AlienVault's Open Threat Exchange, th

Dec 3, 2022
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)

Go View File 在线体验地址 http://39.97.98.75:8082/view/upload (不会经常更新,保留最基本的预览功能。服务器配置较低,如果出现链接超时请等待几秒刷新重试,或者换Chrome) 目前已经完成 docker部署 (不用为运行环境烦恼) Wor

Dec 26, 2022
Tools to help with Japanese sentence mining

Tools to help with Japanese sentence mining

Oct 25, 2022
This service will help you detect any waste of resources in your AWS account

Frugal-Hero This service will help you detect any waste of resources in your AWS account. The policy is: if it is not useful, delete it! Requirements

Jan 31, 2022
A general purpose application and library for aligning text.

align A general purpose application that aligns text The focus of this application is to provide a fast, efficient, and useful tool for aligning text.

Sep 27, 2022