Created
April 22, 2017 05:26
-
-
Save Trshant/564c381cefe336bb5c4f02effd4b8e7f 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
trigram_dict = {}; | |
str_arr.forEach( function(e,i){ | |
sent = e; | |
word_tokens = str.split(" "); | |
word_tokens.forEach( | |
function(e,i){ | |
if( i < 1 ){ return true; } | |
if( i == ( word_tokens.length - 1 ) ){ return true; } | |
// check if key (previous-word current-word) present | |
if( !trigram_dict[ word_tokens[i-1]+' '+e] ){ | |
trigram_dict[ word_tokens[i-1]+' '+e] = [] ; | |
} | |
//check if next-word available | |
if( typeof(word_tokens[i+1]) != "undefined" ){ | |
trigram_dict[word_tokens[i-1]+' '+e].push(word_tokens[i+1] ); | |
} | |
} | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment