let input = "I remember my mother"

print! ("DOCTOR")

print! ("> ", input)

let sanitized = do input > trim > downcase

& ensuring we have spaces at the beginning and end
& this lets us match patterns as written below
let padded = join ([" ", sanitized, " "])

fn switch_persons {
 ("i") -> "you"
 ("you") -> "i"
 ("am") -> "are"
 ("me") -> "you"
 ("my") -> "your"
 (x) -> x
}

fn repersonalize (x) -> do x > 
    trim > 
    split (_, " ") > 
    map (switch_persons, _) > 
    join (_, " ")

fn one_of {
 (str as :string) -> str
 (strs as :list) -> random (strs)
}

let output = match padded with {
 "{x} hello {y}" -> "How do you do. Please state your problem"
 "{x} hi {y}" -> "How do you do. Please state your problem"
 "{x} computer {y}" -> [
   "Do computers worry you"
   "What do you think about machines"
   "Why do you mention computers"
   "What do you think machines have to do with your problem"
 ]
 "{x} name {y}" -> "I am not interested in names"
 "{x} sorry {y}" -> [
   "Please don't apologize"
   "Apologies are not necessary"
   "What feelings do you have when you apologize"
 ]
 "{x} i remember {y}" -> { 
   let switched = repersonalize (y)
   [
     "Do you often think of {switched}"
     "Does thinking of {switched} bring anything else to mind"
     "What else do you remember"
     "Why do you recall {switched} right now"
     "What in the present situation reminds you of {switched}"
     "What is the connection between me and {switched}"
   ]
  } 
 "{x} do you remember {y}" -> {
  let switched = repersonalize (y)
  [
    "Did you think I would forget {switched}"
    "Why do you think I should recall {switched} now"
    "What about {switched}"
    "You mentioned {switched}"
  ]
 }
 "{x} if {y}" -> {
  let switched = repersonalize (y)
  [
    "Do you reall think that its likely that {switched}"
    "Do you wish that {switched}"
    "What do you think about {switched}"
    "Really--if {switched}"
  ]
 }
 "{x} i dreamt {y}" -> {
  let switched = repersonalize (y)
  [
   "Really--{y}"
   "Have you ever fantasized {y} while you were awake"
   "Have you dreamt {y} before"
  ]
 }
 "{x} dream about {y}" -> {
  let switched = repersonalize (y)
  "How do you feel about {switched} in reality"
 }
 "{x} dream {y}" -> [
   "What does this dream suggest to you"
   "Do you dream often"
   "What persons appear in your dreams"
   "Don't you believe that dream has to do with your problem"
 ]
 "{x} my mother {y}" -> {
  let switched = repersonalize (y)
  [
   "Who else in your family {y}"
   "Tell me more about your family"
  ]
 }
 "{x} my father {y}" -> [
   "Your father"
   "Does he influence you strongly"
   "What else comes to mind when you think of your father"
 ]
 "{x} i want {y}" -> {
  let switched = repersonalize (y)
  [
   "What would it mean if you got {y}"
   "Why do you want {y}"
   "Suppose you got {y} soon"
  ]
 }
 "{x} i am glad {y}" -> {
  let switched = repersonalize (y)
  [
   "How have I helped you to be {y}"
   "What makes you happy just now"
   "Can you explain why you are suddenly {y}"
  ]
 }
 "{x} i am sad {y}" -> {
  let switched = repersonalize (y)
  [
   "I am sorry to hear you are depressed"
   "I'm sure it's not pleasant to be sad"
  ]
 }
 "{x} are like {y}" -> {
  let switched_x = repersonalize (x)
  let switched_y = repersonalize (y)
  "What resemblance to you see between {switched_x} and {switched_y}"
 }
  "{x} is like {y}" -> {
   let switched_x = repersonalize (x)
   let switched_y = repersonalize (y)
   [
    "In what way is it that {switched_x} is like {switched_y}"
    "What resemblance do you see"
    "Could there really be some connection"
    "How"
   ]
  }
 "{x} alike {y}" -> [
  "In what way"
  "What similarities are there"
 ]
 "{x} same {y}" -> "What other connections do you see"
 "{x} i was {y}" -> {
  let switched = repersonalize (y) 
  [
   "Were you really"
   "Perhaps I already knew you were {switched}"
   "Why do you tell me you were {switched} now"
  ]
 }
 "{x} was i {y}" -> {
  let switched = repersonalize (y)
  [
   "What if you were {switched}"
   "Do you think you were {switched}"
   "What wouuld it mean if you were {switched}"
  ]
 }
 "{x} i am {y}" -> {
  let switched = repersonalize (y)
  [
   "In what way are you {switched}"
   "Do you want to be {switched}"
  ]
 }
 "{x} am i {y}" -> {
  let switched = repersonalize (y)
  [
   "Do you believe you are {switched}"
   "Would you want to be {switched}"
   "You wish I would tell you you are {switched}"
   "What would it mean if you were {switched}"
  ] 
 }
 "{x} am {y}" -> [
  "Why do you say *AM*"
  "I don't understand that"
 ]
 "{x} are you {y}" -> {
  let switched = repersonalize (y)
  [
   "Why are you interested in whether I am {switched} or not"
   "Would you prefer if I weren't {switched}"
   "Perhaps I am {switched} in your fantasies"
  ]
 }
 "{x} you are {y}" -> {
  let switched = repersonalize (y)
  "What makes you think I am {y}"
 }
 "{x} because {y}" -> [
  "Is that the real reason"
  "What other reasons might there be"
  "Does that reason seem to explain anything else"
 ]
 "{x} were you {y}" -> {
  let switched = repersonalize (y)
  [
   "Perhaps I was {switched}"
   "What od you think"
   "What if I had been {switched}"
  ]
 }
 "{x} i can't {y}" -> {
  let switched = repersonalize (y)
  [
   "Maybe you could {switched} now"
   "What if you could {switched}"
  ]
 }
 "{x} i feel {y}" -> {
  let switched = repersonalize (y)
  "Do you often feel {switched}"
 }
 "{x} i felt {y}" -> "What other feelings do you have"
 "{x} i {y} you {z}" -> {
  let switched = repersonalize (y)
  "Perhaps in your fantasy we {switched} each other"
 }
 "{x} why don't you {y}" -> {
  let switched = repersonalize (y)
  [
   "Should you {y} yourself"
   "Do you believe I don't {y}"
   "Perhaps I will {y} in good time"
  ]
 }
 "{x} yes {y}" -> [
  "You seem quite positive"
  "You are sure"
  "I understand"
 ]
 "{x} no {y}" -> [
  "Why not"
  "You are being a bit negative"
  "Are you saying *NO* just to be negative"
 ]
 "{x} someone {y}" -> "Can you be more specific"
 "{x} everyone {y}" -> [
  "Surely not everyone"
  "Can you think of anyone in particular"
  "Who for example"
  "You are thinking of a special person"
 ]
 "{x} always {y}" -> [
  "Can you think of a specific example"
  "When"
  "What incident are you thinking of"
  "Really--always"
 ]
 "{x} what {y}" -> [
  "Why do you ask"
  "Does that question interest you"
  "What is it you really want to know"
  "What do you think"
  "What comes to your mind when you ask that"
 ]
 "{x} perhaps {y}" -> "You do not seem quite certain"
 "{x} are {y}" -> {
  let switched = repersonalize (y)
  [
   "Did you think they might not be {switched}"
   "Possibly they are {switched}"
  ]
 }
 _ -> [
   "Very interesting"
   "I am not sure I understand you fully"
   "What does that suggest to you"
   "Please continue"
   "Go on"
   "Do you feel strongly about discussing such things"
 ] 
}

print! (">>> ", do output > one_of > upcase)


