I am running into the following seemingly simple problem. I have this code:
testphrase="i love you";
input=ToLowerCase[StringSplit[testphrase, Whitespace]]
It outputs, input={i,love,you}
However, I want to use input elsewhere in my program as "i","love","you"
. So the behaviour I am looking for is as such:
input={"i","love","you"}
I know if I paste input, the quotation marks show up around it. I know the issue resides somewhere in ShowStringCharacters
, as I've read that documentation, but I'm getting mixed up in the different behaviour between pasting it, manually inputting it, and calling on it in Mathematica. My program will only work if the output is formatted in three words with quotation marks, and won't work if the quotation marks aren't there.
--- edited to add ---
The solution below looks like it should work, but I am still getting odd behaviour. Here is my whole code.
The follow example outputs to count the number 111, as it should.
trigrams={{{"i", "don", "t"}, 211}, {{"i", "can", "t"},
186}, {{"you", "don", "t"}, 175}, {{"don", "t", "know"},
137}, {{"oh", "oh", "oh"}, 111}};
Clear[trigramHash];
(trigramHash[Sequence @@ #1] = #2) & @@@ trigrams;
count = trigramHash["oh","oh","oh"]; trigramHash[___] = 0;
Yet this still outputs zero.
test = InputForm[ToLowerCase[StringSplit["oh oh oh", Whitespace]]];
trigrams = {{{"i", "don", "t"}, 211}, {{"i", "can", "t"},
186}, {{"you", "don", "t"}, 175}, {{"don", "t", "know"},
137}, {{"oh", "oh", "oh"}, 111}};
Clear[trigramHash];
(trigramHash[Sequence @@ #1] = #2) & @@@ trigrams;
count = trigramHash[test]; trigramHash[___] = 0;
Even though, on the face of it, test should work - it is outputting as "oh","oh","oh".
InputForm
around? $\endgroup$ – Leonid Shifrin May 15 '12 at 13:57