Last active
May 1, 2018 17:29
-
-
Save colinvh/accb44b5c012e8c5c66f5d0d642e6952 to your computer and use it in GitHub Desktop.
Random symbolic identifiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import codecs | |
from collections import Counter | |
import random | |
import sys | |
sys.stdout = codecs.getwriter('utf8')(sys.stdout) | |
DIACRITICS = [ | |
'acute', | |
'grave', | |
'circumflex', | |
'caron', | |
'breve', | |
'brauve', | |
'trema', | |
'dot', | |
'macron', | |
'persipomene', | |
'ring', | |
'left hook', | |
'right hook', | |
] | |
MODIFIERS = [ | |
'line through', | |
'slash through', | |
'backslash through', | |
'dot inside', | |
] | |
CONTAINERS = [ | |
'oval', | |
'rectangle', | |
] | |
BRACKETS = [ | |
'parentheses', | |
'square brackets', | |
'angle brackets', | |
'inverse guillemots', | |
'curly braces' | |
] | |
DIGITS = '0123456789' | |
MINISCULES = u'aɑbcdeɛghƕꜧıȷklmnŋopqrsʃþuvwxyz' | |
ROT_REF_MN = u' xtx t t trt xxx ttttrtx t' | |
MAJISCULES = u'ABCDEƐFGHǶꜦIJKLMNŊOPQRSƩTÞUVWXYZ' | |
ROT_REF_MJ = u'r tttt x x rt x ttrtrrrxrt' | |
SIMPLE_SHAPES = u'■●' | |
COMPLEX_FILLS = u'□○─│┼●' | |
COMPLEX_SHAPES = u'▬▮◆▲▼◀▶◢◣◤◥⬟⬢⬣' | |
SIMPLE_FILLS = u'●' | |
def all_letters(): | |
for d in DIGITS: | |
yield d | |
yield d | |
yield d | |
yield d | |
for i, l in enumerate(MINISCULES): | |
yield l | |
yield l | |
yield l | |
if ROT_REF_MN[i] not in 'tx': | |
yield 'turned ' + l | |
if ROT_REF_MN[i] not in 'rx': | |
yield 'reversed ' + l | |
if ROT_REF_MN[i] == ' ': | |
yield 'turned and reversed ' + l | |
for i, l in enumerate(MAJISCULES): | |
yield l | |
yield l | |
if ROT_REF_MJ[i] not in 'tx': | |
yield 'turned ' + l | |
if ROT_REF_MJ[i] not in 'rx': | |
yield 'reversed ' + l | |
if ROT_REF_MJ[i] == ' ': | |
yield 'turned and reversed ' + l | |
ALL_LETTERS = list(all_letters()) | |
def all_shapes(): | |
for s in SIMPLE_SHAPES: | |
yield s | |
yield 'double ' + s | |
for f in COMPLEX_FILLS: | |
if f != s: | |
yield f + ' in ' + s | |
yield f + ' in double ' + s | |
for s in COMPLEX_SHAPES: | |
yield s | |
yield 'double ' + s | |
for f in SIMPLE_FILLS: | |
yield f + ' in ' + s | |
ALL_SHAPES = list(all_shapes()) | |
SIMPLE_WINGDINGS = ['.', '+', u'×', 'four-pointed star', 'tilted four-pointed star', | |
u'★', u'inverted ★', 'vertical asterisk', | |
'horizontal asterisk', u'✳'] | |
WINGDINGS = u'!%‰‱&?@/\¡§¶※‽=±÷∀∃∅∆∇∧∨∩∪≈≐<>≤≥⋈⌂⌘$¢£¤¥฿₠₡₢₣₤₥₦₧₨₩₪₫€☥☩☪☸✡☉☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓☇☈☄☁☼●☽◐○◑☾♠♥♦♣♩♪♬♭♮♯✓✗' | |
def all_wingdings(): | |
for w in WINGDINGS: | |
yield w | |
for w in SIMPLE_WINGDINGS: | |
if w == '.': | |
yield '.' | |
yield ':' | |
yield u'∴' | |
elif w == '+': | |
yield '+' | |
yield u'‡' | |
yield 'triple +' | |
else: | |
yield w | |
yield u'double ' + w | |
yield u'triple ' + w | |
ALL_WINGDINGS = list(all_wingdings()) | |
def code(): | |
result = letter() + ',\n' | |
w = random.choice(ALL_WINGDINGS) | |
result += w + u', and\n' | |
result += letter() + '\nin ' | |
wrapper = random.choice(CONTAINERS + BRACKETS) | |
double = random.random() >= .65 | |
if wrapper in CONTAINERS: | |
result += 'a ' | |
if double: | |
result += 'double ' + wrapper | |
else: | |
result += wrapper | |
return result | |
def letter(): | |
result = random.choice(ALL_LETTERS + ALL_SHAPES) | |
if result in DIGITS: | |
result += random.choice(DIGITS) | |
diacritics = [] | |
above, below = random.choice([[0, 0], [1, 0], [1, 0], [1, 1], [2, 0], [0, 1]]) | |
above = fill(above) | |
below = fill(below) | |
modifier = random.random() >= .85 | |
if modifier: | |
modifier = [random.choice(MODIFIERS)] | |
else: | |
modifier = [] | |
for d, n in Counter(above).iteritems(): | |
if n == 1: | |
diacritics.append(d) | |
elif n == 2: | |
diacritics.append('double ' + d) | |
elif n == 3: | |
diacritics.append('triple ' + d) | |
else: | |
diacritics.append(u'{} × {}'.format(n, d)) | |
for d, n in Counter(below).iteritems(): | |
if n == 1: | |
diacritics.append(d + ' below') | |
elif n == 2: | |
diacritics.append('double {} below'.format(d)) | |
elif n == 3: | |
diacritics.append('triple {} below'.format(d)) | |
else: | |
diacritics.append(u'{} × {} below'.format(n, d)) | |
for d, n in Counter(modifier).iteritems(): | |
if n == 1: | |
diacritics.append(d) | |
elif n == 2: | |
diacritics.append('double ' + d) | |
elif n == 3: | |
diacritics.append('triple ' + d) | |
else: | |
diacritics.append(u'{} × {}'.format(n, d)) | |
diacritics = describe(diacritics) | |
if diacritics: | |
diacritics = ' with ' + diacritics | |
result += diacritics | |
return result | |
def describe(_list): | |
if len(_list) == 0: | |
return '' | |
elif len(_list) == 1: | |
return _list[0] | |
elif len(_list) == 2: | |
return ' and '.join(_list) | |
else: | |
return ', '.join(_list[:-1]) + ', and ' + _list[-1] | |
def fill(qty): | |
return list(_fill(qty)) | |
def _fill(qty): | |
for _ in xrange(qty): | |
yield random.choice(DIACRITICS) | |
if __name__ == '__main__': | |
c = code() | |
#print repr(c) | |
print c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment