This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Summary: Randomly create original names from themed source data.

Author: Sandy Goh (C) June 2015

Code License: MIT Expat. See LICENSE.txt file.

User Documentation

>>> from moppyname import Generator
>>> ng = Generator()
>>> for _ in range(5):
>>>     print(ng.generate())
Maemi
Coechlica
Karllisha
Betonne
Zarise

Advanced Usage

You can use your own data files:

>>> from moppyname import Generator
>>> with open ('source.txt', 'r') as fp:
>>>     ng = Generator().set_max_len(20).load_source_data(fp)

Or supply the data as a string:

>>> IK_ELFDAR = "Aesha Alyssa Caelyth Cytyss Dahlia "
Edrea Falcir Feen Gaelyr Hellith Lorimir Lothwyn Metyll "
"Miir Renyll Sacyl Sillith Tanyr Tathur Velwhin Veryth "
"Ystith".split()
>>> ng.load_source_data(IK_ELFDAR)
>>> for _ in range(5):
>>>     print(ng.generate())
Venyth, Renysa, Edrith, Alireerir, Sinyth

Filters

Default filters will prevent (a) duplication of an input string, and (b) duplication of an English dictionary word. This behaviour is customisable.

Function API

set_max_len(v)

Sets the maximum name length to v (default 20).

load_source_data(fn)

Loads the file represented. fn is a file object or a list of strings and will introspect to determine this. A list of string should be [“Alice”, “Bob”, “Carol”] etc. A file should be the same format, with one entry per line. If using a list, the list will be copied. The list will be lower-cased as the generator works in lower case, and then applies capitalize().

load_exclude_list(fn)

Sets the exclusion list (banned output list). Parameters are the same as for the source data list. By default, it is the an English dictionary.

add_filter(fn)

Adds the function fn as a filter function, used to reject matching names. See below to write a filter.

drop_filter(fn) -- deprecated, use `remove_filter`
remove_filer(fn)

Removes the filter function fn. Fails silently.

list_filters()

List the currently loaded filters (function name as a string).

Supplied Filter functions (all on by default)

All are in the package namespace

>>> generator.drop_filter(moppyname.drop_no_vowel)

List of filters

drop_triple_letter -- Remove name with consecutive triple letters.

drop_no_vowel -- Removes name with no vowel (a, e, i, o, u).

drop_in_source -- Removes name if present in source data.

drop_in_exclude -- Remove name if in ban list.

Obviously one can filter the results manually, but I felt putting some filters into the generator would make for cleaner code for the user.

Writing a filter

def drop_begin_with_d(self, item):
    # Rejects names starting with 'd'. Return True if drop.
    return item.lower().startswith("d"):

my_generator.add_filter(drop_begin_with_d)

The generator works in lower case and then title cases the result after filters are applied.

Developer Documentation

How it Works

  • It’s a Markov Chain.
  • The source file is read to determine a list of the letters that can start a name. One is picked at random.
  • We examine the letter pairings in the source data, and pick a letter pair that begins with the last of the name. Repeat until the name is of the desired length and we pick a letter pair that can end a name.
  • The random distribution will match the distribution of the source file.
  • Apostrophe names (Ik’thrarion) work, as do non-ASCII characters.

Example

source data: ["Sophie", "Sadie", "Marina"]
  • The name will be 0.67 chance 6-letters and 0.33 chance 5 letters. It might overrun due to random.
  • There is 0.67 to begin with S, otherwise 0.33 M.
  • After an S, there will be an A or O with equal probability.
  • After an I, there will be an E or N, with E being 2x as likely.
  • A name can end once it’s reached the chosen length and it currently ends in ‘IE’ or ‘NA’.

The default source file is ~200 EN UK female first names.

It will work with about 20 or so but because it’s random, this will depend on the data.

The default ban list is an EN UK dictionary.

On Error

It’ll abort and raise MoppyNameError exception. If this happens, the input data or filters need tuning. There’s no termination check for a user-supplied filter function.

TODO List

TODO Research output quality.

  • Why I don’t like the names generated? Bad data? Bad algorithm? I suspect all name generators suck, but we don’t notice if we set them to generate fantasy names.

TODO Add support for mixed case names e.g. “MacCleod”.

TODO Run Levenshtein distance on output to reject minor changes?

  • People can probably do this themselves. There’s a good package for this (python-Levenshtein).

TODO Python 2 support.

  • Should be just import print statement, and fix accented characters.
Release History

Release History

1.1.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
moppyname-1.1.0.tar.gz (211.0 kB) Copy SHA256 Checksum SHA256 Source Oct 12, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting