neng

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 7 Imported by: 0

README

neng, Non-Extravagant Name Generator

Go Reference Go Report Card

Introduction

neng is a Golang package that can generate random English names from nouns, verbs and adjectives according to user-specified pattern. It is powered by diverse collection of almost 29000 nouns, over 11000 adjectives and 6000 verbs 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.

If the embedded word database does not meet your requirements, you can provide neng with your own word lists.

Sample use

Code
package main

import (
    "fmt"

    "github.com/Zedran/neng"
)

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

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

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

    // Transforming an arbitrary word
    word, _ := gen.Transform("STASH", neng.MOD_GERUND, neng.MOD_CASE_LOWER)

    fmt.Printf("Phrase -> %s\nVerb   -> %s\nWord   -> %s\n", phrase, verb, word)
}
Output
Phrase -> share
Verb   -> Serenade perplexes a STRAY SUPERBUG
Word   -> stashing

Phrase pattern commands

Escape character: %

Insertion
Symbol Description
% Inserts % sign
a Inserts a random adjective
n Inserts a random noun
v Inserts a random verb
Transformation

Currently, no compatibility checks have been implemented. It is legal to transform any word with any modifier, it is also possible to assign more than one modifier of the same type to a word. Improper use of modifiers will therefore result in deformations.

Symbol Compatible with Package constant Description
2 verb MOD_PAST_SIMPLE Past Simple (2nd form)
3 verb MOD_PAST_PARTICIPLE Past Participle (3rd form)
N verb MOD_PRESENT_SIMPLE Present Simple (now)
g verb MOD_GERUND Gerund
l any MOD_CASE_LOWER lower case
p noun, verb MOD_PLURAL Plural form
t any MOD_CASE_TITLE Title Case
u any MOD_CASE_UPPER UPPER CASE

Symbols are used to specify transformation parameters for words within a phrase. Package constants are designed to work with "single-word" methods.

Some verbs may not be correctly transformed into their past forms and gerund. If your favourite verb is not modified as expected, feel free to open a new issue. Even a single incorrectly formed verb could reveal a pattern I have missed while analysing the word database.

Attributions

Refer to NOTICE.md.

License

This software is available under MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

Generates random phrases or words.

func DefaultGenerator added in v0.5.0

func DefaultGenerator() (*Generator, error)

Returns a new Generator with default word lists.

func NewGenerator

func NewGenerator(adj, noun, verb []string) (*Generator, error)

Initializes a new Generator with provided lists. Returns error if any of the lists is empty.

func (*Generator) Adjective

func (gen *Generator) Adjective(mods ...Mod) (string, error)

Generates a single random adjective and transforms it according to mods. Returns an error if an undefined Mod is received.

func (*Generator) Noun

func (gen *Generator) Noun(mods ...Mod) (string, error)

Generates a single random noun and transforms it according to mods. Returns an error if an undefined Mod is received.

func (*Generator) Phrase

func (gen *Generator) Phrase(pattern string) (string, error)

Generates a phrase given the pattern.

Syntax:

Insertion:
	%% - inserts '%' sign
	%a - inserts a random adjective
	%n - inserts a random noun
	%v - inserts a random verb

Transformation:
	%2 - transforms a verb into its Past Simple form (2nd form)
	%3 - transforms a verb into its Past Participle form (3rd form)
	%N - transforms a verb into its Present Simple form (now)
	%g - transforms a verb into gerund
	%p - transform a noun or a verb (Present Simple) into its plural form
	%l - transform a word to lower case
	%t - transform a word to Title Case
	%u - transform a word to UPPER CASE

Error is returned if:

  • provided pattern is empty
  • character other than the above is escaped with a '%' sign
  • a single '%' ends the pattern

Error is not returned if:

  • incompatible modifier is assigned to the word
  • duplicate modifier is assigned to the same word

Example phrase:

"%tn %2v a %ua %un" may produce "Serenade perplexed a STRAY SUPERBUG"

func (*Generator) Transform added in v0.2.0

func (gen *Generator) Transform(word string, mods ...Mod) (string, error)

Transforms a word according to specified mods. Not all mods are compatible with every part of speech. Compatibility is not checked. Returns an error if an undefined Mod is received.

func (*Generator) Verb added in v0.2.0

func (gen *Generator) Verb(mods ...Mod) (string, error)

Generates a single random verb and transforms it according to mods. Returns an error if an undefined Mod is received.

type Mod added in v0.2.0

type Mod uint8

Modification parameter for a generated word

const (
	// Transform a noun or a verb (Present Simple) into its plural form
	MOD_PLURAL Mod = iota

	// Add Past Simple suffix to a verb or substitute its irregular form
	MOD_PAST_SIMPLE

	// Add Past Simple suffix to a regular verb or substitute Past Participle form to an irregular one
	MOD_PAST_PARTICIPLE

	// Add Present Simple suffix to a verb (-s, -es)
	MOD_PRESENT_SIMPLE

	// Create gerund form of a verb (-ing)
	MOD_GERUND

	// Transform a word to lower case
	MOD_CASE_LOWER

	// Transform a word to Title Case
	MOD_CASE_TITLE

	// Transform a word to UPPER CASE
	MOD_CASE_UPPER
)

Jump to

Keyboard shortcuts

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