I have the following program that plots the number of trigram appearances across a corpus of textual information between 1964 and 1989 (apologies for the messy code):
Manipulate[
viewerCount1 = {};
SetDirectory["/users/ME/desktop/DB/Put/"];
filenames = FileNames["*trigrams-put.txt"];
Do[
input = Get[file];
Clear[trigramHash];
(trigramHash[Sequence @@ #1] = #2) & @@@ input;
count = trigramHash[word1, word2, word3]; trigramHash[___] = 0;
AppendTo[viewerCount1, count];
, {file, filenames}];
DateListPlot[viewerCount1, {1964}, Joined -> True,
PlotLabel -> "Number of Trigram Appearances"], {{word1, "i",
"Word1:"}}, {{word2, "love", "Word2:"}}, {{word3, "you",
"Word3:"}}]
Right now, it looks like so:
What this is doing is initially seeing how frequent the phrase "i love you" is across files like this:
{{{"i", "don", "t"}, 102}, {{"i", "m", "gonna"}, 67},
{{"wa", "wa", "wa"}, 66}, {{"i", "can", "t"}, 66}, {{"i", "ll", "be"}, 66},
{{"i", "love", "you"}, 62}, {{"you", "don", "t"}, 55},
{{"la", "la", "la"}, 50}, {{"don", "t", "you"}, 49},
{{"don", "t", "know"}, 48}, {{"ain", "t", "that"}, 47},
The problem is that in this version you have to type word1 as "i"
, word2 as "love"
, and word3 as "you"
.
Would there be a way for Mathematica to detect "i love you"
in the Manipulate
box, and then return responses as if it was "i" "love" "you"
? So it could just be a phrase box, and it would split them in to three parts. (I have separate programs right now for unigrams, bigrams, trigrams, and quadgrams)
StringSplit
? $\endgroup$