11-07-2013

posted Nov 6, 2013, 8:20 PM by Samuel Konstantinovich   [ updated Nov 7, 2013, 6:29 AM ]
Do Now:
DN1 Evaluate:
a. (length '((1)(2)(3)))
b. (length '(()()()))
c. (length '((1 2) 3))
d. (length '((1 2 3)))
e. (length '((1 2 (3))))
f. (length '((1 2 3) 4))

DN2 Write an expression using a sequence of car/cdr to extract 
the value 3 from each of the following 3 lists:
g. (define super '(1 2 3))
h. (define fighting '((1 2 (3 4)(5 6))))
i. (define robot '( (1 (2 (3) 4)))) 


GOAL: Making your own random sentence generator

Sentence Generator: 
-We will ignore case for sentences for now.
-In order to do this you need the random function in Pretty Big/Swindle. NOT R5RS!
-You should have the most awesome sentence generator in class when we come back from the weekend. Be prepared to run it a few times to show me your awesome sentences. 

You need to be able to write a basic sentence generator first, after that works you can make it more elaborate/poetic/creative:

Noun1 <negate> verb1 Noun2, noun2 verb noun2.
Like:
Guns don't kill people, people kill people. 
OR
Toasters don't toast toast. Toast toast toast. 

Think for a second:
What are the basic parts of a sentence? 
What is the simplest sentence you can make?



We would ideally start with a simple sentence like:
noun verb
kitty plays
toast runs
tea steams

;1. Add your random words lists. They should be in the format:
;(define nouns '( kitty toast tea) )
;(define verbs '( runs plays steams) ) 

;2. Add your code for getNth, and getRandomTopLevelElement.
;rename getRandomTopLevelElement -> getOne
;YOU SHOULD HAVE getNth before continuing 
;YOU SHOULD HAVE getOne before continuing  

;3a. We want to be able to append 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)
;getVerb gives you a single random verb as a list:  
;(getVerb) -> (runs)
;(getVerb) -> (steams)
;YOU SHOULD HAVE getNoun and getVerb before continuing 

;3b. 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)

;Here is the simple sentence generating function:

(define (sentence)  (append (getNoun) (getVerb) )) 

;Every time you run it you should get randomized results depending on your list of words.

;(sentence) -> ( kitty runs )

;(sentence) -> ( kitty plays )
;(sentence) -> ( toast steams )

;If you finished up to this point, you can try to make better sentences by replacing getNoun and getVerb with new functions. We can replace a noun with a noun phrase, and replace a verb with a verb phrase. You can experiment on your own to do so. Try using adjectives and adverbs.

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 at the end of class or on Monday. 
1. Noun Phrases: (include 'the' when appropriate)
"the dog"            noun
"the happy dog"  adjective+ noun
"Michael"            proper noun (no 'the')
"the slow frustrated person" adjective+ adjective+ noun

2: Your generator should not always give the same type of sentence:
Sometimes noun verb
Sometimes adjective noun verb
Somtimes adjective adjective noun verb
etc.

You can choose different configurations using random as follows:
(cond
  ( (= 0 (random 3)  SENTENCETYPE1 )
  ( (= 0 (random 2)  SENTENCETYPE2 )
  ( else                     SENTENCETYPE3 )
)

3. AdjectiveBlock: (0 or more adjectives to use in your noun Phrases)
Notice you can have any number of adjectives connected! 
So define a function AdjectiveBlock that returns . 

4. AdverbVerbBlock:   (0 or more adverbs + verb) 
quickly runs
silently sleeps
slowly silently creeps

5. Proper nouns can be one option in your noun phrase list:
Thor smashes
Tony Stark quickly shoots
The Hulk gleefully plays (notice 'the hulk' is a proper noun, the 'the' is attached to the name...)
The slow Thor sits 

Some verbs require another noun.
Joe runs. //This is fine by itself

Joe takes ... something

6. Make a 2nd list of verbs that requires a 2nd noun/nounphrase. You can either:
-Choose an intransitive verb like we just did before (the normal verb list)
-Choose a transitive verb then choose a noun phrase:
Thor pokes Loki  ;transitive verb + proper noun
The dog bites the little chair. ;transitive verb + noun phrase


____

Do Now Solutions:
a. 3
b.3
c. 2
d. 1
e. 1
f. 2
g. (caddr super)
h. (caaddr (car fighting))
i. (caadar(cdar robot))

Functions you should have written:

(define (getNth L n)
  (if (= n 0) (car L) (getNth (cdr L) (- n 1))))

(define (getOne L)
  (getNth L (random (length L))))











(define (getNoun) (list (getOne nouns)))

(define (getVerb) (list (getOne verbs)))
Comments