2015-11-13 HWSentenceGenerator

posted Nov 13, 2015, 4:58 AM by Samuel Konstantinovich   [ updated Nov 19, 2015, 9:49 PM ]
Do Now:
Think of the sentence with the structure:
Noun1 <negate> transitive_verb1 Noun2, noun2 transitive_verb noun2.
Like:
-Earthworms don't slap people, people slap people.
-Guns don't kill people, people kill people. 
OR
-Toasters don't toast toast. Toast toast toast. 

Think for a second: (write these down)
What are the basic parts of a sentence? 
What is the simplest sentence you can make?
What happens when you modify some of the words in a basic sentence? Does the structure stay the same? 
How can you group a more complex sentence into the required parts?



Sentence Generator: Weighted as a 18 points (like a quiz): 

due Monday Nov 23rd 8:00am HW server

You will have today in class, and next week Thurs/Friday in class, AND tons of time outside of class =)

Prerequisites:
p1a. We will ignore capitalization for now AND we will keep things in the present tense. 
p1b  It is not worth the effort to make past tense, as the sentences are identical and not more interesting.

p2. In order to do this you need the random function in Pretty Big/Swindle. NOT R5RS!

p3. You should have the most awesome sentence generator you can make.

p4. You should have your lists of words. They should be in the format:
(define nouns '( "kitty" "toast" "tea") )
(define verbs '( "runs" "plays" "steams") ) 
(define adjectives '( "quick" "tall" "happy") ) 

p5. You should have completed these functions:
(define getNth (lambda (L n)
    (if (= n 0) 
        (car L) 
        (getNth (cdr L) (- n 1)))))
;rename getRandomTopLevelElement -> getOne 
(define getOne (lambda (L)
  (getNth L (random (length L)))))

Part I - Basic Sentences (6 points)
You need to be able to write a basic sentence generator first, after that works you can make it more elaborate/poetic/creative.
If you submit the basic generator only, you will get 6/18 points on the assignment. 

Ia. - Putting it together into a sentence.
We want to be able to connect two words together, so we don't just want the word we want the word inside a list. This can be accomplished with the list command.  Lets make two functions using getOne and the lists you have made:

getNoun is a function that takes no parameters, that gives you a single random noun as a list:  
(getNoun) -> ("kitty")
(getNoun) -> ("toast")

;no parameters looks like this:
(define getNoun (lambda ()
   ????  )

getVerb gives you a single random verb as a list:  
(getVerb) -> ("runs")
(getVerb) -> ("steams")

getAdjective gives you a single random adjective as a list:  
(getAdjective) -> ("happy")
(getAdjective) -> ("happy")

If you do that then it is trivial to make a simple sentence that chooses a verb and a noun and adds them to the same list. This is because 
to join ("kitty") and ("runs")  we can just append:    (append '("kitty") '("runs") )  -> ("kitty" "runs")


I.b
We would ideally start with a simple sentence list like:
("noun" "verb")
("kitty" "plays")
("toast" "runs")
("tea" "steams")

I.c
BETTER: add 'the' to the sentence: 
("the" "toast" "runs")


(define sentence (lambda ()
   ????  )

;Every time you run it you should get randomized results depending on your list of words.
;(sentence) -> ( "the" "kitty" "runs" )
;(sentence) -> ( "the" "kitty" "plays" )
;(sentence) -> ( "the" "toast" "steams" )

I.d - Display your sentence!

Make a (displayList L) command that displays each element of a list on the same line, then runs the newline command: (attach a period to make it better)
(displayList (sentence))  
the kitty runs.
(displayList (sentence)) 
the kitty plays.
(displayList (sentence)) 
the toast steams.

hint: Recursion with an empty list as the base case, just do a newline when it is empty, otherwise... well you figure out the recursive part. 

The rest of the Parts : Make It better!!!

YOUR JOB IS TO MAKE IT BETTER: After your basic generator works, you should implement as many of these as you can. We can show off the best sentences on piazza! 
Your generator should not always give the same type of sentence:
Sometimes noun verb
Sometimes adjective noun verb
Somtimes adjective adjective noun verb
etc. 
HOW DO WE DO THIS CRAZY STUFF?!?!?!
HOW TO MAKE DIFFERENT STYLE RESULTS RANDOMLY
We can choose between different options randomly by using  a series of random in the cond statement as  follows:

Here is an example of having a .5 chance of getting "a" or "b" 
(cond
  ( (= 0 (random 2))  "a" )   ;replace "a" and "b" with a function or some code that makes a sentence
  ( else                     "b" )
)

Here is an example of having a .333 chance of getting "a" "b" or "c"
(cond
  ( (= 0 (random 3))  "a" )   ;replace "a" with a function or some code that makes a sentence
  ( (= 0 (random 2))  "b" )
  ( else                     "c" )
)

Counting down randoms in this pattern, will give an equal probability for each choice. You can modify the probabilities as you need.
(cond
  ( (= 0 (random 2))  (function1) ) ;.5 chance  
  ( (= 0 (random 2))  (function2) ) ;.5*.5 (.25 chance)
  ( else              (function3) ) ;else is whatever is left (.25 chance)
)
So:
.5 chance of function1 to trigger, 
.25 chance of function2 to trigger
.25 chance of function3 to trigger


Part II 
Try using adding adjectives and adverbs to your phrases as a starting point.  (Yes, you can add more word lists!)

II.Adjectives and Adverbs: (6 points)

Make a function (zeroOrMoreAdjectives) that gives you a list of adjectives, which could be empty or have many adjectives.

(You can have any number of adjectives connected if you do this recursively)

You will use this in your nounPhrase function later on.

Define a function zeroOrMoreAdjectives that uses the cond to return a random number of adjectives. 
e.g.
(zeroOrMoreAdjectives) -> ("slow" "tall")
(zeroOrMoreAdjectives) -> ("fast" "silly" "furry")
(zeroOrMoreAdjectives) -> ("fishy")
(zeroOrMoreAdjectives) -> ()


Do the same things with adverbs, Write (zeroOrMoreAdverbs) :
(zeroOrMoreAdverbs) -> ("quickly")
(zeroOrMoreAdverbs) ->()
(zeroOrMoreAdverbs) ->("slowly" "silently")
(zeroOrMoreAdverbs) ->("silently" "efficiently")

If you finished up to this point, you can try to make better sentences by replacing getNoun and getVerb with new functions.  

II.b - HOW TO MAKE NOUNS BETTER
-Replace your (getNoun) with a (getNounPhrase) function that takes no parameters. 

It could return:

zeroOrMoreAdjectives + noun

You could even relocate the word "the" to this part of your function.

("the" "dog")           zeroOrMoreAdjectives + noun
("the" "happy" "dog")  zeroOrMoreAdjectives + noun
("the" "quick" "lazy" "dog")  zeroOrMoreAdjectives + noun


II.c - HOW TO MAKE VERBS BETTER
-Replace a getVerb with a (getVerbPhrase) function that takes no parameters. 

Just like your nounPhrase function you can just make your verb phrase:

zeroOrMoreAdverbs + verb
("quickly" "walks")
("talks")
("slowly" "silently" "stalks")
etc.



Part III 
Make Verbs/Nouns EVEN BETTER!!! [4 points]

III.a HOW TO MAKE NOUNS BETTER

Some verbs require another noun.

Joe runs  //noun verb

Joe takes the ball  //noun verb noun2
This is because "take" is a transitive verb, it requires a target.


NOW! Make a 2nd list of transitiveVerbs

Now your getVerbPhrase can choose:

-Choose an intransitive verb like we just did before (the normal verb list)
zeroOrMoreAdverbs + InTransitive_verb

-Choose a transitive verb then choose a noun phrase:
zeroOrMoreAdverbs + Transitive_verb + nounPhrase

III.b HOW TO MAKE NOUNS BETTER

Noun Phrases can include - proper noun, 
(Michael)            proper noun (no 'the')  
(the quick lazy dog)  zeroOrMoreAdjectives + noun

Proper nouns can be one option in your noun phrase: 
(You would need a separate list of proper nouns, and a function that gets one for you)

("Dave" "walks")
("Thor" "smashes")
("Tony Stark" "quickly" "shoots") ;2 part proper noun
("The Hulk" "gleefully" "plays") - notice 'the hulk' is a proper noun, the 'the' is attached to the name...
("Loki" "defies" "the world wrestling federation") ; 2 proper nouns one with an attached the

Proper nouns do not automatically get "the"
Maybe you can relocate where you decide to attach the in your code so it doesn't do this.


IV - You can add other styles of sentences and other special categories. [4 points]
You must DOCUMENT part IV at the top of your program underneath the heading. (yes you need the heading)
 what your generator does beyond the requirements. (So I know what to look for)
 Tell me what functions you created/modified to do these things, (So I know where to look)
You must document this in your comments, and make sure that I know you spent time doing this. This is the open/creative part of the assignment. If you already got this far, that means you can do it!!! 
I encourage you to explore new options here, because in the past students have come up with really cool sentence structures!
-Negate statements
-Multiple clauses
-Be creative... and use google for sentence structure ideas. 


Comments