Categorygithub.com/Zedran/neng
repositorypackage
0.15.4
Repository: https://github.com/zedran/neng.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

neng, Non-Extravagant Name Generator

Go Reference Go Report Card

Introduction

neng is a Golang package that can generate random English phrases from nouns, verbs, adverbs and adjectives according to user-specified pattern. It is powered by diverse collection of 41000 words compiled from WordNet Lexical Database. Inspired by Terraria's world name generator, neng is designed to be simple yet versatile name making tool for other projects.

Unsuitable for cryptographic applications.

Showcase

go run github.com/Zedran/neng/examples/phrase@latest

Sample use

Code

package main

import (
    "fmt"

    "github.com/Zedran/neng"
)

func main() {
    gen, _ := neng.DefaultGenerator()

    // <title case + noun> <Present Simple + verb> the <upper + adjective> <upper + noun>.
    phrase, _ := gen.Phrase("%tn %Nv the %ua %un.")

    // A single, transformed verb
    verb, _ := gen.Verb(neng.MOD_PAST_SIMPLE)

    // Transforming an arbitrary word
    word, _ := gen.Transform("involve", neng.WC_VERB, neng.MOD_GERUND|neng.MOD_CASE_TITLE)

    fmt.Printf("Phrase -> %s\nVerb   -> %s\nWord   -> %s\n", phrase, verb, word)
}

Output

Phrase -> Serenade perplexes the STRAY SUPERBUG.
Verb   -> shared
Word   -> Involving

Phrase pattern commands

neng's phrase generation syntax resembles C-style string format specifiers. The user provides a pattern consisting of commands, preceded by the escape character, to insert (and optionally transform) randomly generated words. A regular text can be mixed with command syntax.

Escape character: %

Insertion

SymbolWordClassDescription
%Inserts % sign
aWC_ADJECTIVEInserts a random adjective
mWC_ADVERBInserts a random adverb
nWC_NOUNInserts a random noun
vWC_VERBInserts a random verb

WordClass values are required by some of the Generator's methods to recognize parts of speech.

Transformation

Transformations can only be applied to compatible parts of speech.

Symbols are used to request transformations for words within a phrase. Constants of type Mod are designed to work with "single-word" methods.

SymbolCompatible withModDescription
2verbMOD_PAST_SIMPLEPast Simple (2nd form)
3verbMOD_PAST_PARTICIPLEPast Participle (3rd form)
NverbMOD_PRESENT_SIMPLEPresent Simple (now)
cadjective, adverbMOD_COMPARATIVEComparative (better)
fanyMOD_CASE_SENTENCESentence case (first letter)
gverbMOD_GERUNDGerund
iadjective, adverb, noun*MOD_INDEFIndefinite adjective (a, an)
_nounMOD_INDEF_SILENTSilent indefinite**
lanyMOD_CASE_LOWERlower case
pnoun, verb***MOD_PLURALPlural form
sadjective, adverbMOD_SUPERLATIVESuperlative (best)
tanyMOD_CASE_TITLETitle Case
uanyMOD_CASE_UPPERUPPER CASE

* MOD_INDEF is not compatible with MOD_PLURAL and MOD_SUPERLATIVE.

** MOD_INDEF_SILENT ensures that the noun is grammatically compatible with an indefinite article (not uncountable, not plural-only), but does not modify it in any way. It is useful in phrase patterns such as %ia %_n, where the indefinite article belongs to the noun, but it stands before the adjective describing the noun. If Generator.TransformWord method receives silent indefinite, it does nothing to the provided word, but it still returns an error in case of incompatibility.

*** MOD_PLURAL is only compatible with verbs when combined with MOD_PAST_SIMPLE or MOD_PRESENT_SIMPLE.

Mod values form two conceptual categories: grammar modifiers and case modifiers. Only one modifier from each category may be applied to any given word. If multiple modifiers of the same kind are specified, the one with the lowest value is applied. The above-mentioned verb transformations with MOD_PLURAL and MOD_INDEF are exceptions to this rule.

State of the vocabulary

Generator's default vocabulary consists of:

  • 23000 nouns
  • 10000 adjectives
  • 6000 verbs
  • 2000 adverbs

Original WordNet lists have been thoroughly vetted. I have strived to remove any words that are offensive, too specific (chemistry, medicine) or relate to topics that are considered sensitive, controversial or fear-inducing. However, I am not native English speaker and the database is quite large, so it is likely I have missed something. If you find any unsuitable words, I will be happy to hear from you.

If the embedded database does not meet your requirements, you can provide neng with your own word lists. To ensure the accuracy of transformations, I recommend that your custom vocabulary remains a subset of the embedded one.

Attributions

Refer to NOTICE.md.

License

This software is available under MIT License.