I'm not a programmer. I just wanted to have some fun, so I tried to
write a Mathematica version based on the Ruby version (the only one I
actually understood). I'm sure that this can be improved and written
in a nicer way, but here it goes: :-)
script = {
{__, u : "father" | "mother" | "brother" | "sister", ___} :> {"Tell
me about your " <> v <> "."},
{___, "am" | "i'm", u__} :> {"Why are you " <> v <> "?", "Have you
always been " <> v <> "?"},
{___, "i", u__} :> {"Why do you " <> v <> "?"},
{___, "you", ___} :> {"We're talking about you, not me", "Please
don't be so personal."},
{u___} :> {"That's very interesting. Do go on.", "Tell me more.",
"I'm not sure that I understand you fully.",
"Can you elaborate on that?",
"Why do you think that " <> v <> "?"}
};
script = script /. v :> processSegment[{u}];
stripPunct[s_String] :=
FixedPoint[
If[MatchQ[StringTake[#, -1], "!" | "?" | "." | ";" | " "],
StringDrop[#, -1], #] &,
s]
processSegment[s_] :=
StringJoin@[EMAIL PROTECTED]
s /. {"I" -> "you", "my" -> "your", "your" -> "my", "myself" ->
"yourself",
"you are" -> "I am", "you're" -> "I am", "you" -> "me"},
" "]
While[StringLength[str = InputString[]] > 0,
With[{ss = StringSplit@[EMAIL PROTECTED]
Print@[EMAIL PROTECTED]
ss /. List /@[EMAIL PROTECTED]
Select[script,
MatchQ[ss, First[#]] &] ]
]]
Note: It is recommended to run this from the command line instead of
the Front End, otherwise input will be read through an ugly popup
window.


|