SHARE
TWEET

Pronoun generator v2

a guest Sep 18th, 2019 237 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. $stems = [
  5.     'b' => 2,
  6.     'br' => 2,
  7.     'c' => 3,
  8.     'ch' => 4,
  9.     'cl' => 2,
  10.     'd' => 2,
  11.     'dr' => 1,
  12.     'f' => 2,
  13.     'g' => 1,
  14.     'gh' => 3,
  15.     'h' => 5,
  16.     'j' => 1,
  17.     'jh' => 1,
  18.     'k' => 2,
  19.     'kl' => 2,
  20.     'l' => 1,
  21.     'm' => 2,
  22.     'mn' => 1,
  23.     'n' => 2,
  24.     'ng' => 1,
  25.     'p' => 1,
  26.     'q' => 1,
  27.     'r' => 2,
  28.     's' => 4,
  29.     'sc' => 1,
  30.     'sh' => 3,
  31.     'sp' => 2,
  32.     'st' => 3,
  33.     't' => 4,
  34.     'th' => 4,
  35.     'w' => 1,
  36.     'wr' => 1,
  37.     'x' => 4,
  38.     'xh' => 1,
  39.     'y' => 2,
  40.     'z' => 5,
  41.     'zh' => 5,
  42. ];
  43.  
  44. $vowels = [
  45.     'a' => 3,
  46.     'ae' => 2,
  47.     'ai' => 2,
  48.     'ao' => 1,
  49.     'au' => 1,
  50.     'ay' => 1,
  51.     'e' => 4,
  52.     'ea' => 1,
  53.     'ei' => 1,
  54.     'eo' => 1,
  55.     'eu' => 2,
  56.     'ey' => 1,
  57.     'i' => 3,
  58.     'ia' => 1,
  59.     'ie' => 1,
  60.     'io' => 1,
  61.     'iu' => 1,
  62.     'o' => 3,
  63.     'oa' => 1,
  64.     'oe' => 1,
  65.     'oi' => 1,
  66.     'ou' => 2,
  67.     'oy' => 2,
  68.     'u' => 2,
  69.     'ua' => 1,
  70.     'ui' => 1,
  71.     'uo' => 1,
  72.     'y' => 2,
  73.     'ya' => 1,
  74.     'ye' => 1,
  75.     'yi' => 1,
  76.     'yo' => 1,
  77.     'yu' => 1,
  78. ];
  79.  
  80. $altVowelChance = 30;
  81. $stemVowelChance = 20;
  82.  
  83. $prefixes = [
  84.     '' => 100,
  85.     'b' => 8,
  86.     'd' => 10,
  87.     'g' => 10,
  88.     'k' => 10,
  89.     'm' => 6,
  90.     'n' => 6,
  91.     's' => 10,
  92.     't' => 10,
  93.     'z' => 10,
  94. ];
  95.  
  96. $subjectiveSuffixes = [
  97.     '' => 100,
  98.     'h' => 10,
  99.     'n' => 5,
  100.     'w' => 10,
  101.     'y' => 20,
  102. ];
  103.  
  104. $objectiveSuffixes = [
  105.     '' => 1,
  106.     'b' => 1,
  107.     'j' => 5,
  108.     'l' => 2,
  109.     'm' => 10,
  110.     'n' => 10,
  111.     'p' => 2,
  112.     'r' => 10,
  113.     't' => 2,
  114.     'v' => 1,
  115.     'w' => 1,
  116.     'x' => 1,
  117.     'z' => 2,
  118. ];
  119.  
  120. $possessiveSuffixes = [
  121.     'l' => 2,
  122.     'm' => 3,
  123.     'mn' => 2,
  124.     'n' => 3,
  125.     'r' => 10,
  126.     'rl' => 4,
  127.     's' => 10,
  128.     'sz' => 7,
  129.     'v' => 3,
  130.     'w' => 2,
  131.     'z' => 10,
  132. ];
  133.  
  134. $cull = [
  135.     'brj',
  136.     'chv',
  137.     'klw',
  138.     'qm',
  139.     'qn',
  140.     'uy',
  141.     'wyi',
  142.     'yay',
  143.     'yiy',
  144.     'yey',
  145.     'yoy',
  146.     'yuy',
  147.     'yw',
  148.     'yy',
  149.     'spm',
  150.     'spnm',
  151.     'ssz',
  152.     'sx',
  153.     'xj',
  154.     'zhp',
  155.     '/tj$/',
  156. ];
  157.  
  158. $map = [
  159.     'bc' => "b'c",
  160.     'bd' => "b'd",
  161.     'bn' => "b'n",
  162.     'bk' => "b'k",
  163.     'bq' => "b'q",
  164.     'bt' => "b't",
  165.     'bx' => "b'x",
  166.     'dk' => "d'k",
  167.     'dn' => "d'n",
  168.     'dq' => "d'q",
  169.     'dx' => "d'x",
  170.     'gb' => "g'b",
  171.     'gq' => "g'q",
  172.     'gs' => "g's",
  173.     'gx' => "g'x",
  174.     'gz' => "g'z",
  175.     'fm' => "f'm",
  176.     'fq' => "f'q",
  177.     'kc' => "k'c",
  178.     'kd' => "k'd",
  179.     'km' => "k'm",
  180.     'kq' => "k'q",
  181.     'kt' => "k't",
  182.     'kx' => "k'x",
  183.     'kz' => "k'z",
  184.     'mb' => "m'b",
  185.     'mk' => "m'k",
  186.     'mq' => "m'q",
  187.     'mz' => "m'z",
  188.     'nb' => "n'b",
  189.     'nk' => "n'k",
  190.     'nq' => "n'q",
  191.     'nx' => "n'x",
  192.     'nz' => "n'z",
  193.     'tb' => "t'b",
  194.     'tg' => "t'g",
  195.     'tq' => "t'q",
  196.     'jq' => "k'q",
  197.     'jz' => "k'z",
  198.     'xm' => "x'm",
  199.     'xn' => "x'n",
  200.     'zq' => "z'q",
  201.     'zx' => "z'x",
  202.     '/nr$/' => "n'r",
  203.     '/^tk/' => "t'k",
  204. ];
  205.  
  206. do {
  207.     $stem = r($stems);
  208.     $stemVowel = (rand(1, 100) <= $stemVowelChance) ? r($vowels) : null;
  209.     if ($stemVowel) {
  210.         $stem = $stemVowel . $stem;
  211.     }
  212.     $mainVowel = $stemVowel ? null : r($vowels);
  213.  
  214.     if ($stemVowel) {
  215.         $subjective = $stem;
  216.     } else {
  217.         $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
  218.         $subjective = $stem . $vowel;
  219.     }
  220.     $suffix = r($subjectiveSuffixes);
  221.     if ($suffix && !endsWith($subjective, $suffix)) {
  222.         $subjective .= $suffix;
  223.     }
  224.     if (strlen($stem) === 1) {
  225.         $prefix = r($prefixes);
  226.         if ($prefix && $prefix !== $stem) {
  227.             $subjective = $prefix . $subjective;
  228.         }
  229.     }
  230.  
  231.     if ($stemVowel) {
  232.         $objective = $stem;
  233.     } else {
  234.         $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
  235.         $objective = $stem . $vowel;
  236.     }
  237.     $suffix = r($objectiveSuffixes);
  238.     if ($suffix && !endsWith($objective, $suffix)) {
  239.         $objective .= $suffix;
  240.     }
  241.     if (strlen($stem) === 1) {
  242.         $prefix = r($prefixes);
  243.         if ($prefix && $prefix !== $stem) {
  244.             $objective = $prefix . $objective;
  245.         }
  246.     }
  247.  
  248.     if ($stemVowel) {
  249.         $possessive = $stem;
  250.     } else {
  251.         $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
  252.         $possessive = $stem . $vowel;
  253.     }
  254.     $suffix = r($possessiveSuffixes);
  255.     if ($suffix && !endsWith($possessive, $suffix)) {
  256.         $possessive .= $suffix;
  257.     }
  258.     if (strlen($stem) === 1) {
  259.         $prefix = r($prefixes);
  260.         if ($prefix && $prefix !== $stem) {
  261.             $possessive = $prefix . $possessive;
  262.         }
  263.     }
  264.  
  265.     m($subjective, $map);
  266.     m($objective, $map);
  267.     m($possessive, $map);
  268. } while(
  269.     $subjective === $possessive
  270.     || $objective === $possessive
  271.     || has($subjective, $cull)
  272.     || has($objective, $cull)
  273.     || has($possessive, $cull)
  274. );
  275.  
  276. $substantive = endsWith($possessive, 's') ? $possessive : $possessive . 's';
  277. $reflexive = endsWith($objective, 's') ? $objective . 'elf' : $objective . 'self';
  278.  
  279. echo "$subjective / $objective / $possessive / $substantive / $reflexive\n";
  280. echo "$subjective is here / look at $objective / with $possessive friend / that is $substantive / or by $reflexive\n";
  281.  
  282. function r(array $l) {
  283.     $total = 0;
  284.     foreach ($l as $w) {
  285.         $total += $w;
  286.     }
  287.     $s = rand(0, $total);
  288.     $p = 0;
  289.     foreach ($l as $v => $w) {
  290.         $p += $w;
  291.         if ($p >= $s) {
  292.             return $v;
  293.         }
  294.     }
  295.     throw new Exception('should be unreachable');
  296. }
  297.  
  298. function m(string &$s, array $m) {
  299.     foreach ($m as $f => $r)  {
  300.         if (strpos($f, '/') !== false) {
  301.             $s = preg_replace($f, $r, $s);
  302.         } else {
  303.             $s = str_replace($f, $r, $s);
  304.         }
  305.     }
  306. }
  307.  
  308. function endsWith(string $s, string $e) {
  309.     return substr($s, strlen($s) - strlen($e), strlen($e)) === $e;
  310. }
  311.  
  312. function has(string $s, array $l) {
  313.     foreach ($l as $m) {
  314.         if (strpos($m, '/') !== false) {
  315.             if (preg_match($m, $s)) {
  316.                 return true;
  317.             }
  318.         } else {
  319.             if (strpos($s, $m) !== false) {
  320.                 return true;
  321.             }
  322.         }
  323.     }
  324.     return false;
  325. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top