public JsonResult StartModeling(string filePath) { var fileName = this.Request.Query.ElementAt(0).Key; ConcurrentDictionary <string, Dictionary <string, int> > tweetList = new ConcurrentDictionary <string, Dictionary <string, int> >(); AhoCorasick.Trie trie = new AhoCorasick.Trie(); List <string> hashtags = new List <string>() { "alwaystrump", "babesfortrump", "bikers4trump", "bikersfortrump", "blacks4trump", "buildthatwall", "buildthewall", "cafortrump", "democrats4trump", "donuldtrumpforpresident", "feelthetrump", "femineamerica4trump", "gays4trump", "gaysfortrump", "gotrump", "heswithus", "imwithhim", "imwithyou", "latinos4trump", "latinosfortrump", "maga", "makeamericagreat", "makeamericagreatagain", "makeamericasafeagain", "makeamericaworkagain", "onlytrump", "presienttrump", "rednationrising", "trump16", "trump2016", "trumpcares", "trumpforpresident", "trumpiswithyou", "trumppence2016", "trumpstrong", "trumptrain", "veteransfortrump", "vets4trump", "votegop", "votetrump", "votetrump2016", "votetrumppence2016", "woman4trump", "women4trump", "womenfortrump", "antitrump", "anyonebuttrump", "boycotttrump", "chickentrump", "clowntrain", "crookeddonald", "crookeddrumpf", "crookedtrump", "crybabytrump", "defeattrump", "dirtydonald", "donthecon", "drumpf", "dumbdonald", "dumpthetrump", "dumptrump", "freethedelegates", "lgbthatestrumpparty", "loserdonald", "losertrump", "lovetrumpshate", "lovetrumpshates", "lyindonald", "lyingdonald", "lyingtrump", "lyintrump", "makedonalddrumpfagain", "nevergop", "nevertrump", "nevertrumppence", "nodonaldtrump", "notrump", "notrumpanytime", "poordonald", "racisttrump", "releasethereturns", "releaseyourtaxes", "ripgop", "showusyourtaxes", "sleazydonald", "stoptrump", "stupidtrump", "traitortrump", "treasonoustrump", "trump20never", "trumplies", "trumpliesmatter", "trumpsopoor", "trumpthefraud", "trumptrainwreck", "trumptreason", "unfittrump", "weakdonald", "wherertrumpstaxes", "wheresyourtaxes", "whinylittlebitch", "womentrumpdonald", "bernwithher", "bluewave2016", "clintonkaine2016", "estoyconella", "herstory", "heswithher", "hillafornia", "hillary2016", "hillaryforamerica", "hillaryforpr", "hillaryforpresident", "hillarysopresidential", "hillarysoqualified", "hillarystrong", "hillstorm2016", "hillyes", "hrc2016", "hrcisournominee", "iamwithher", "imwither", "imwithher", "imwithher2016", "imwhithhillary", "imwiththem", "itrusther", "itrusthillary", "madamepresident", "madampresident", "momsdemandhillary", "ohhillyes", "readyforhillary", "republicans4hillary", "republicansforhillary", "sheswithus", "standwithmadampotus", "strongertogether", "uniteblue", "vote4hillary", "voteblue", "voteblue2016", "votehillary", "welovehillary", "yeswekaine", "clintoncorruption", "clintoncrime", "clintoncrimefamily", "clintoncrimefoundation", "corrupthillary", "criminalhillary", "crookedclinton", "crookedclintons", "crookedhilary", "crookedhiliary", "crookedhillary", "crookedhillaryclinton", "deletehillary", "dropouthillary", "fbimwithher", "handcuffhillary", "heartlesshillary", "hillary2jail", "hillary4jail", "hillary4prison", "hillary4prison2016", "hillaryforprison", "hillaryforprison2016", "hillaryliedpeopledied", "hillarylies", "hillaryliesmatter", "hillarylosttome", "hillaryrottenclinton", "hillarysolympics", "hillno", "hypocritehillary", "imnotwithher", "indicthillary", "iwillneverstandwithher", "killary", "lockherup", "lyingcrookedhillary", "lyinghillary", "lyinhillary", "moretrustedthanhillary", "neverclinton", "nevereverhillary", "neverhillary", "neverhilllary", "nohillary2016", "nomoreclintons", "notwithher", "ohhillno", "releasethetranscripts", "riskyhillary", "shelies", "sickhillary", "stophillary", "stophillary2016", "theclintoncontamination", "wehatehillary", "whatmakeshillaryshortcircuit" }; hashtags = hashtags.ConvertAll(d => d.ToLower()); for (int i = 0; i < hashtags.Count; i++) { trie.Add(hashtags[i], (i).ToString()); } // build search tree trie.Build(); Parallel.ForEach(System.IO.File.ReadLines(fileName), new ParallelOptions { MaxDegreeOfParallelism = 32 }, (line, _, lineNumber) => { try { var tweet = JsonConvert.DeserializeObject <_Tweet>(line); var a = Proximity.Match(trie, hashtags, tweet.Text.ToLower()); if (a.Count != 0) { Dictionary <string, List <string> > tags = new Dictionary <string, List <string> >() { { "Pro-Trump", new List <string>() { "trump", "clinton", "alwaystrump", "babesfortrump", "bikers4trump", "bikersfortrump", "blacks4trump", "buildthatwall", "buildthewall", "cafortrump", "democrats4trump", "donuldtrumpforpresident", "feelthetrump", "femineamerica4trump", "gays4trump", "gaysfortrump", "gotrump", "heswithus", "imwithhim", "imwithyou", "latinos4trump", "latinosfortrump", "maga", "makeamericagreat", "makeamericagreatagain", "makeamericasafeagain", "makeamericaworkagain", "onlytrump", "presienttrump", "rednationrising", "trump16", "trump2016", "trumpcares", "trumpforpresident", "trumpiswithyou", "trumppence2016", "trumpstrong", "trumptrain", "veteransfortrump", "vets4trump", "votegop", "votetrump", "votetrump2016", "votetrumppence2016", "woman4trump", "women4trump", "womenfortrump" } }, { "Anti-Trump", new List <string>() { "antitrump", "anyonebuttrump", "boycotttrump", "chickentrump", "clowntrain", "crookeddonald", "crookeddrumpf", "crookedtrump", "crybabytrump", "defeattrump", "dirtydonald", "donthecon", "drumpf", "dumbdonald", "dumpthetrump", "dumptrump", "freethedelegates", "lgbthatestrumpparty", "loserdonald", "losertrump", "lovetrumpshate", "lovetrumpshates", "lyindonald", "lyingdonald", "lyingtrump", "lyintrump", "makedonalddrumpfagain", "nevergop", "nevertrump", "nevertrumppence", "nodonaldtrump", "notrump", "notrumpanytime", "poordonald", "racisttrump", "releasethereturns", "releaseyourtaxes", "ripgop", "showusyourtaxes", "sleazydonald", "stoptrump", "stupidtrump", "traitortrump", "treasonoustrump", "trump20never", "trumplies", "trumpliesmatter", "trumpsopoor", "trumpthefraud", "trumptrainwreck", "trumptreason", "unfittrump", "weakdonald", "wherertrumpstaxes", "wheresyourtaxes", "whinylittlebitch", "womentrumpdonald" } }, { "Pro-Clinton", new List <string>() { "bernwithher", "bluewave2016", "clintonkaine2016", "estoyconella", "herstory", "heswithher", "hillafornia", "hillary2016", "hillaryforamerica", "hillaryforpr", "hillaryforpresident", "hillarysopresidential", "hillarysoqualified", "hillarystrong", "hillstorm2016", "hillyes", "hrc2016", "hrcisournominee", "iamwithher", "imwither", "imwithher", "imwithher2016", "imwhithhillary", "imwiththem", "itrusther", "itrusthillary", "madamepresident", "madampresident", "momsdemandhillary", "ohhillyes", "readyforhillary", "republicans4hillary", "republicansforhillary", "sheswithus", "standwithmadampotus", "strongertogether", "uniteblue", "vote4hillary", "voteblue", "voteblue2016", "votehillary", "welovehillary", "yeswekaine", } }, { "Anti-Clinton", new List <string>() { "clintoncorruption", "clintoncrime", "clintoncrimefamily", "clintoncrimefoundation", "corrupthillary", "criminalhillary", "crookedclinton", "crookedclintons", "crookedhilary", "crookedhiliary", "crookedhillary", "crookedhillaryclinton", "deletehillary", "dropouthillary", "fbimwithher", "handcuffhillary", "heartlesshillary", "hillary2jail", "hillary4jail", "hillary4prison", "hillary4prison2016", "hillaryforprison", "hillaryforprison2016", "hillaryliedpeopledied", "hillarylies", "hillaryliesmatter", "hillarylosttome", "hillaryrottenclinton", "hillarysolympics", "hillno", "hypocritehillary", "imnotwithher", "indicthillary", "iwillneverstandwithher", "killary", "lockherup", "lyingcrookedhillary", "lyinghillary", "lyinhillary", "moretrustedthanhillary", "neverclinton", "nevereverhillary", "neverhillary", "neverhilllary", "nohillary2016", "nomoreclintons", "notwithher", "ohhillno", "releasethetranscripts", "riskyhillary", "shelies", "sickhillary", "stophillary", "stophillary2016", "theclintoncontamination", "wehatehillary", "whatmakeshillaryshortcircuit" } } }; Dictionary <string, int> similarity = new Dictionary <string, int>(); foreach (KeyValuePair <string, List <string> > pair in tags) { similarity.Add(pair.Key, 0); } int total = 0; foreach (string word in a) { foreach (KeyValuePair <string, List <string> > category in tags) { if (category.Value.Contains(word)) { similarity[category.Key]++; total++; } } } Dictionary <string, int> similarityPercentage = new Dictionary <string, int>(); foreach (KeyValuePair <string, int> key in similarity) { similarityPercentage.Add(key.Key, (int)(((double)key.Value / total) * 100)); } if (a.Count > 1) { Console.WriteLine(); } tweetList.TryAdd(tweet.TimestampMs, similarityPercentage); } } catch (Exception e) { Console.WriteLine("Error "); } }); using (StreamWriter sw = new StreamWriter(Path.GetDirectoryName(fileName) + "/SIMILARITY_" + Path.GetFileNameWithoutExtension(fileName) + ".txt")) { sw.WriteLine(JsonConvert.SerializeObject(tweetList)); } Console.WriteLine("Finished Vader " + DateTime.Now); return(new JsonResult(new { success = true, responseText = "Finished Modeling." })); }