Created
April 22, 2017 05:27
-
-
Save Trshant/79dc93d12d82cc5bac0c6d677354d4af 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
function create(trigram_dict ){ | |
new_string_arr = ["Yo","mama"]; | |
prevword=trigram_dict [ new_string_arr[new_string_arr.length-2]; | |
pprevword=new_string_arr[new_string_arr.length-1] ; | |
while( typeof( trigram_dict [prevword+' '+pprevword] ) != "undefined" ){ | |
candidate_words = trigram_dict [ prevword+' '+pprevword ] ; | |
//select word randomly out of all candidates | |
item = candidate_words[Math.floor( | |
Math.random() * candidate_words.length)]; | |
new_string_arr.push(item); | |
prevword=trigram_dict [ new_string_arr[new_string_arr.length-2]; | |
pprevword=new_string_arr[new_string_arr.length-1] ; | |
} | |
new_str = new_string_arr.join(" "); | |
//A brand new sentence | |
return new_str ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment