Created
November 1, 2012 19:29
-
-
Save imphasing/3995874 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
// Make a preliminary n-gram to n-gram map to translate with | |
function make_translate_map() | |
{ | |
$four_grams = array( | |
"ouve" => "a", | |
"them" => "dem", | |
"then" => "den", | |
"done" => "dun", | |
"dont" => "dnt", | |
"know" => "no", | |
"youn" => "yun", | |
"nish" => "nsh", | |
"this" => "dis", | |
"ther" => "der", | |
"ight" => "ite", | |
"some" => "sum" | |
); | |
$tri_grams = array( | |
"wha" => "wu", | |
"are" => "r", | |
"thi" => "ti", | |
"coo" => "koo", | |
"sai" => "se", | |
"see" => "c", | |
"the" => "da", | |
"and" => "nd", | |
"nor" => "nr", | |
"can" => "cn", | |
"one" => "1", | |
"two" => "2", | |
"ans" => "ns", | |
"you" => "u", | |
"ork" => "rk", | |
"too" => "2" | |
); | |
$bi_grams = array( | |
"th" => "d", | |
"re" => "r" | |
); | |
$post_fixes = array( | |
"ady" => "athy", | |
"dars" => "thers", | |
"oder" => "other", | |
"ader" => "ather", | |
"rvi" => "revi", | |
"rtrn" => "retrn", | |
"drou" => "thru", | |
"gre" => "gree", | |
"wuzh" => "wash", | |
"rsta" => "rest", | |
"eld" => "elth", | |
"ald" => "alth", | |
"ifd" => "ifth" | |
); | |
return array_merge($four_grams, $tri_grams, $bi_grams, $post_fixes); | |
} | |
// Accepts an n-gram map, and applies randomizations to it | |
function randomize_map($translate_map) | |
{ | |
$like_random = array("lyk", "lyke", "liek", "lik","like"); | |
$ur_random = array("yr", "ur", "yur", "your"); | |
$was_random = array("wuz", "woz", "was", "waz"); | |
$the_random = array("tha", "da", "teh"); | |
$ould_random = array("ud", "ood", "od"); | |
$ery_random = array("ery", "ry"); | |
$wid_random = array("wid", "wit"); | |
$people_random = array("ppl", "peppl", "peoppl", "people"); | |
$ention_random = array("ention", "enshun"); | |
$ine_random = array("yn", "yne", "ein"); | |
$ude_random = array("ude", "ewd"); | |
$for_random = array("for", "4"); | |
$fuck_random = array("fuck", "fck", "fuk", "fucc"); | |
$translate_map['like'] = $like_random[array_rand($like_random)]; | |
$translate_map['ur'] = $ur_random[array_rand($ur_random)]; | |
$translate_map['was'] = $was_random[array_rand($was_random)]; | |
$translate_map['da'] = $the_random[array_rand($the_random)]; | |
$translate_map['ould'] = $ould_random[array_rand($ould_random)]; | |
$translate_map['ery'] = $ery_random[array_rand($ery_random)]; | |
$translate_map['wid'] = $wid_random[array_rand($wid_random)]; | |
$translate_map['people'] = $people_random[array_rand($people_random)]; | |
$translate_map['ention'] = $ention_random[array_rand($ention_random)]; | |
$translate_map['ine'] = $ine_random[array_rand($ine_random)]; | |
$translate_map['ude'] = $ude_random[array_rand($ude_random)]; | |
$translate_map['for'] = $for_random[array_rand($for_random)]; | |
$translate_map['fuck'] = $fuck_random[array_rand($fuck_random)]; | |
return $translate_map; | |
} | |
// Translate a string from "normal" to "OMGWTF MORON" | |
function translate($original_string) | |
{ | |
$original_string = strtolower($original_string); | |
$original_string = preg_replace('/[,;\._\'\/]+/', '', $original_string); | |
$words = split("[ ]+", $original_string); | |
$translate_map = make_translate_map(); | |
$translated_words = array(); | |
foreach ($words as $value) | |
{ | |
foreach (randomize_map($translate_map) as $orig => $mod) | |
{ | |
$value = str_replace($orig, $mod, $value); | |
} | |
$translated_words[] = $value; | |
} | |
return join(' ', $translated_words); | |
} | |
$translated = ""; | |
if (isset($_POST['submit'])) { | |
$translated = translate($_POST['original']); | |
} | |
?> | |
<html> | |
<head> | |
<title>Insta-moron</title> | |
</head> | |
<body> | |
<h2>Moron Translation:</h2> | |
<br /> | |
<form action="translate.php" method="POST"> | |
Original:<br /> | |
<textarea cols="50" rows="10" name="original"><?php echo isset($_POST['original']) ? $_POST['original'] : ''; ?></textarea> | |
<br /><br /> | |
Translated:<br /> | |
<textarea cols="50" rows="10" name="translated"><?php echo $translated ?></textarea> | |
<br /><br /> | |
<input type="submit" value="Translate" name="submit" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment