added some dictionaries

This commit is contained in:
Yann Esposito (Yogsototh) 2018-09-02 23:58:33 +02:00
parent e8c973fc97
commit d0cb946ba4
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
7 changed files with 375715 additions and 12 deletions

370099
dictionaries/english.txt Normal file

File diff suppressed because it is too large Load diff

5163
dictionaries/first-names.txt Normal file

File diff suppressed because it is too large Load diff

173
dictionaries/generic.txt Normal file
View file

@ -0,0 +1,173 @@
ab initio
a cappella
à deux
ad hoc
ad infinitum
ad interim
ad nauseam
a fortiori
agent provocateur
à huis clos
al dente
alfresco
amour propre
annus mirabilis
a posteriori
a priori
au courant
au fait
au fond
au naturel
beau geste
beau idéal
beau monde
beaux arts
bête noire
belles-lettres
billet-doux
blitzkrieg
bona fide
bon mot
bon vivant
brasserie
carpe diem
carte blanche
cause célèbre
caveat emptor
cest la guerre
chacun à son gout
chef-dœuvre
cherchez la femme
comme il faut
compos mentis
cognoscenti
cordon sanitaire
Cosa
coup de foudre
coup de grâce
coup de main
coup détat
cri de cœur
cui bono?
de facto
Dei gratia
déjà vu
de jure
de nos jours
Deo gratias
Deo volente
de profundis
de rigueur
dernier cri
de trop
deus ex machina
dolce far niente
dolce vita
doppelgänger
double entendre
dramatis personae
embarras de richesse
éminence grise
en famille
enfant terrible
en masse
en passant
entente cordiale
entre nous
esprit de corps
ex gratia
ex officio
fait accompli
faute de mieux
faux pas
femme fatale
fête champêtre
fin de siècle
force majeure
folie de grandeur
gîte
grande dame
haute couture
haute cuisine
haut monde
hors de combat
ideé fixe
in absentia
in camera
in extremis
in loco parentis
in medias res
in propria persona
in situ
inter alia
in toto
ipso facto
je ne sais quoi
jeu desprit
jeunesse dorée
joie de vivre
katzenjammer
laissez-faire
locum tenens
locus classicus
magnum opus
manqué
mea culpa
memento mori
ménage à trois
modus operandi
modus vivendi
mot juste
ne plus ultra
nil desperandum
noblesse oblige
nolens volens
non sequitur
nouveau riche
objet dart
on dit
papabile
par excellence
parti pris
per annum
per capita
per se
persona non grata
pièce de résistance
pied-à-terre
pis aller
plat du jour
plus ça change
pococurante
prima facie
primus inter pares
pro rata
proxime accessit
quid pro quo
raison dêtre
reductio ad absurdum
roman-à-clef
sangfroid
savoir faire
sine die
sine qua non
soi-disant
sotto voce
sub judice
sub rosa
sui generis
table dhôte
tant mieux
tant pis
terra firma
terra incognita
tête-à-tête
tour de force
tout de suite
unheimlich
verboten
via media
victor ludorum
vis-à-vis
vox populi
zeitgeist

192
dictionaries/literary.txt Normal file
View file

@ -0,0 +1,192 @@
abode
access
adieu
afar
apace
argosy
arrant
asunder
atrabilious
aurora
bard
barque
bedizen
beget
behold
beseech
bestrew
betake oneself
betide
betoken
blade
blithe
bosky
brand
brume
celerity
circumvallate
clarion
cleave to
cockcrow
coruscate
crapulent
crescent
darkling
deep
dell
dingle
divers
Dives
dolour
dome
dulcify
effulgent
eld
eminence
empyrean
ere
erne
espy
ether
evanescent
farewell
fervid
fidus Achates
finny
firmament
flaxen
fleer
flexuous
fulgent
fulguration
fuliginous
fulminate
furbelow
gird
glaive
gloaming
greensward
gyre
hark
horripilation
hymeneal
ichor
illude
imbrue
impuissant
incarnadine
ingrate
inhume
inly
ire
isle
knell
lachrymal
lacustrine
lambent
lave
lay
lea
lenity
lightsome
limn
lucent
madding
mage
main
malefic
manifold
marge
mead
mephitic
mere
moon
morrow
muliebrity
nescient
nigh
niveous
nocuous
noisome
nymph
orb
orgulous
pellucid
perchance
perfervid
perfidious
philippic
plangent
plash
plenteous
plumbless
poesy
prothalamium
puissant
pulchritude
purl
quidnunc
realm
refulgent
rend
repine
Rhadamanthine
roundelay
rubescent
rutilant
sans
scribe
sea-girt
sempiternal
serpent
shade
ship of the desert
shore
slay
slumber
star-crossed
steed
stilly
storied
strand
Stygian
summer
supernal
susurration
swain
sword
sylvan
tarry
temerarious
tenebrous
threescore
thrice
tidings
toilsome
tope
travail
troublous
tryst
unman
vestal
vesture
virescent
viridescent
visage
want
wax
wayfarer
wed
welkin
whited sepulchre
wind
without
wondrous
wont
wonted
wrathful
wreathe
yon
yore
youngling
zephyr

View file

@ -2,14 +2,14 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: fe995591c3b1ff6d0108ed452651b05548563501e80b5e6503529ccc952a8fd0
-- hash: c5f958a044b04a3b5795efc86fa4cd7fd5ef7fd9f515f9e483f366db6991f1ec
name: human-friendly-id-gen
version: 0.1.0.0
category: Test
stability: alpha (experimental)
homepage: https://github.com/yogsototh/human-friendly-id-gen#readme
bug-reports: https://github.com/yogsototh/human-friendly-id-gen/issues
homepage: https://gitlab.esy.fun/yogsototh/human-friendly-id-gen#readme
bug-reports: https://gitlab.esy.fun/yogsototh/human-friendly-id-gen/issues
author: Yann Esposito
maintainer: yann.esposito@gmail.com
copyright: © 2018 Yann Esposito
@ -20,13 +20,15 @@ cabal-version: >= 1.10
extra-source-files:
README.md
stack.yaml
source-repository head
type: git
location: https://github.com/yogsototh/human-friendly-id-gen
data-files:
dictionaries/english.txt
dictionaries/first-names.txt
dictionaries/generic.txt
dictionaries/literary.txt
library
exposed-modules:
IDGen.Dictionary
IDGen.Short
Lib
other-modules:
@ -40,6 +42,7 @@ library
, mwc-random
, primitive
, protolude
, text
, vector
default-language: Haskell2010

View file

@ -1,10 +1,11 @@
name: human-friendly-id-gen
version: '0.1.0.0'
category: Test
author: Yann Esposito
maintainer: yann.esposito@gmail.com
copyright: © 2018 Yann Esposito
homepage: https://gitlab.esy.fun/yogsototh/human-friendly-id-gen#readme
author: Yann Esposito
maintainer: yann.esposito@gmail.com
copyright: © 2018 Yann Esposito
homepage: https://gitlab.esy.fun/yogsototh/human-friendly-id-gen#readme
bug-reports: https://gitlab.esy.fun/yogsototh/human-friendly-id-gen/issues
license: ISC
extra-source-files:
- README.md
@ -24,12 +25,15 @@ ghc-options:
dependencies:
- base >=4.8 && <5
- protolude
data-files:
- dictionaries/*.txt
library:
source-dirs: src
dependencies:
- mwc-random
- vector
- primitive
- text
- vector
executables:
human-friendly-id-gen-exe:
main: Main.hs

69
src/IDGen/Dictionary.hs Normal file
View file

@ -0,0 +1,69 @@
{-|
module : IDGen.Dictionary
Description : Dictionary strategy to generate random human friendly ids
License : Public Domain
Maintainer : yann.esposito@gmail.com
Should generate readable words easy to pronounce so minimizing mistake
when talking about them.
Yet not the best for preventing collision.
-}
module IDGen.Dictionary
( idgen
, collisionProbability
)
where
import Protolude
import qualified System.Random.MWC as Random
import qualified Control.Monad.Primitive as Prim
import qualified Data.Vector as V
import qualified Data.Text as T
-- | Will generate readable short names The integer parameter determine the
-- length in number of syllabus of the name
idgen :: Int -> FilePath -> IO Text
idgen n dictName = do
allwords <- words dictName
Random.withSystemRandom $ \gen ->
T.intercalate "-" <$> replicateM n (genWord gen allwords)
-- | Approximate collision probability other n generated name with complexity
-- parameter equal to l
--
-- For example if you generate 1000 words randomly with complexity parameter 4
-- We estimate the probability of collision to 3.85%
--
-- This is a nice helper function to use when you want to estimate the optimal
-- length of your ids
--
-- @
-- > collisionProbability 1000 4
-- 3.8580246913580245e-2
--
-- > collisionProbability 10000 5
-- 6.430041152263374e-2
--
-- > collisionProbability 10000 6
-- 1.0716735253772291e-3
-- @
collisionProbability :: V.Vector Text -- ^ The dictionary
-> Double -- ^ nb of generated names
-> Double -- ^ length parameter used
-> Double
collisionProbability dict n l = min ((n**2) / (2 * (nbWords dict ** l))) 1
nbWords :: V.Vector Text -> Double
nbWords ws = fromIntegral $ V.length ws
genWord :: Random.Gen (Prim.PrimState IO) -> V.Vector Text -> IO Text
genWord gen allwords = do
(k :: Int) <- Random.uniformR (0, V.length allwords - 1) gen
return (allwords V.! k)
words :: FilePath -> IO (V.Vector Text)
words dictName = (V.fromList . T.lines) <$> readFile dictName