Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your task is to implement a simple chatbot in Racket ). Here\'s a sample chat th

ID: 3818517 • Letter: Y

Question

Your task is to implement a simple chatbot in Racket).

Here's a sample chat that your program will carry out:

> (chat-with 'Name)

hi name

talk to me >>>how are you?
why do you ask?

talk to me >>>i am bored
i am bored too

talk to me >>>can you sing?
yes i can

talk to me >>>i like to sing too
good to know

talk to me >>>do you play the guitar?
no rula i do not play the guitar

talk to me >>>are you intelligent?
maybe

talk to me >>>what is the meaning of life?
what do you think?

talk to me >>>i think it is all about family and friends
tell me more about your friends name

talk to me >>>they are great
that's nice

talk to me >>>will you help me with my work?
no rula i will not help you with your work

talk to me >>>tell me a joke
you tell me a joke

talk to me >>>why are you doing this?
why not?

talk to me >>>do you understand me?
yes i do

talk to me >>>i need to go get my umbrella
why do you need to go get your umbrella?

talk to me >>>because it is raining
is that the real reason?

talk to me >>>you drive me crazy
can you elaborate on that?

talk to me >>>bye
bye rula
have a great day!

Your program will generate a response based on the following rules:

no i (do|can|will|would) not __change person___

yes i (do|can|will|would)

why do you ask?

how would an answer to that help you?

what do you think?

why do you ask?

i don't know

i have no idea

i have no clue

maybe

The user name will be identified when the main function is called: (chat-with 'user-name)

The special topics in rule 2 will include the following: family, friend(s), mom, dad, brother, sister, girlfriend, boyfriend, children, son, daughter, child, wife, husband, home, dog, cat, pet. If more than one special topic is found in the input, your program will pick one randomly and ask the user about it. For example, the response to:

talk to me >>>i think it is all about family and friends

can be either:
tell me more about your friends name

or:
tell me more about your family name

In rule 1 and rule 8, when the chatbot repeats part of the user's input, the pronouns must be changed as follows:

I becomes you

am becomes are

my becomes your

your becomes my

me becomes you

you becomes me

talk to me >>>will you help me with my work?
no rula i will not help you with your work

talk to me >>>i want to understand your algorithm
why do you want to understand my algorithm?

talk to me >>>i think i am done
why do you think you are done?

talk to me >>>i have to understand you
why do you have to understand me?

For rule 10, you will use a short list of verbs that includes: tell, give, say.

STARTER CODE:

;;; chat.rkt

;;; We'll use the random function implemented in Racket
;;; (random k) returns a random integer in the range 0 to k-1
(#%require (only racket/base random))

;;; some input and output helper functions

;;; prompt: prompt the user for input
;;; return the input as a list of symbols
(define (prompt)
(newline)
(display "talk to me >>>")
(read-line))

;;; read-line: read the user input till the eof character
;;; return the input as a list of symbols
(define (read-line)
(let ((next (read)))
(if (eof-object? next)
'()
(cons next (read-line)))))

;;; output: take a list such as '(how are you?) and display it
(define (output lst)
(newline)
(display (to-string lst))
(newline))

;;; to-string: convert a list such as '(how are you?)
;;; to the string "how are you?"
(define (to-string lst)   
(cond ((null? lst) "")
((eq? (length lst) 1) (symbol->string (car lst)))
(else (string-append (symbol->string (car lst))
" "
(to-string (cdr lst))))))


;;; main function
;;; usage: (chat-with 'your-name)

(define (chat-with name)
(output (list 'hi name))
(chat-loop name))

;;; chat loop
(define (chat-loop name)
(let ((input (prompt))) ; get the user input
(if (eqv? (car input) 'bye)
(begin
(output (list 'bye name))
(output (list 'have 'a 'great 'day!)))
(begin
   (reply input name)
(chat-loop name)))))


;;; your task is to fill in the code for the reply function
;;; to implement rules 1 through 11 with the required priority
;;; each non-trivial rule must be implemented in a separate function
;;; define any helper functions you need below
(define (reply input name)
(output (pick-random generic-response))) ; rule 11 has been implemented for you

;;; pick one random element from the list choices
(define (pick-random choices)
(list-ref choices (random (length choices))))

;;; generic responses for rule 11
(define generic-response '((that's nice)
(good to know)
(can you elaborate on that?)))

if the input is of the form: your program will generate a response (randomly chosen) 1 (do|can|will|would) you ________________?

no i (do|can|will|would) not __change person___

yes i (do|can|will|would)

2 _____(special topics)_______ tell me more about your (special topics)... 3 why __________? why not? 4 how __________?

why do you ask?

how would an answer to that help you?

5 what __________?

what do you think?

why do you ask?

6 _____________?

i don't know

i have no idea

i have no clue

maybe

7 ______because_______ is that the real reason? 8 i (need|think|have|want) ________ why do you (need|think|have|want) __change person_____? 9 i __________ (last word is not too) i __________ too 10 verb ________________ you verb ______________ 11 everything else good to know
that' s nice
can you elaborate on that?

Explanation / Answer

#lang racket
(require racket/gui/base
2htdp/picture
(just in mrlib/picture center render-picture))
;; The condition of our program is a number.
(characterize state 0)
;; On a clock tick, increase the state, and invigorate the canvas.
;; tick!: - > void
(characterize (tick!)
(set! state (add1 state))
(send THE-CANVAS invigorate))
;; When a canvas paints itself, utilize the accompanying:
;; paint: canvas% dc<%> - > void
(characterize (paint! a-canvas my-drawing-setting)
(characterize my-new-scene (content (arrangement "I see: ~a" state) 20 'dark))
;; Note: we constrain the canvas to be of a specific width and tallness here:
(send a-canvas min-customer width (picture width my-new-scene))
(send a-canvas min-customer stature (picture tallness my-new-scene))
(render-picture my-new-scene my-drawing-setting 0))
;; Here, we instate our graphical application. We make a window outline...
;; THE-FRAME: frame%
(characterize THE-FRAME (new (class frame%
(super-new)
;; When we close the edge, close down everything.
(characterize/enlarge (on-close)
(overseer shutdown-all (current-custodian))))
[label "Example"]))
;; and include a canvas into it.
;; THE-CANVAS: canvas%
(characterize THE-CANVAS (new (class canvas%
(super-new)
;; We characterize a key handler. We should have it so it
;; resets the counter on a key press
(characterize/abrogate (on-roast key-occasion)
(whenever (eq? (send key-occasion get-key-code) 'discharge)
(set! state 0)
(send THE-CANVAS refresh))))
[parent THE-FRAME]
[paint-callback paint!]))
;; We get the edge to appear on screen:
(send THE-FRAME demonstrate #t)
;; Finally, we set up a clock that will call tick! on consistently.
(characterize THE-TIMER (new timer%
[notify-callback tick!]
[interval 1000]))