2018-04-10 Sentences! HW

posted Apr 10, 2018, 6:25 AM by Konstantinovich Samuel   [ updated Apr 11, 2018, 8:00 AM ]
QUIZ THURSDAY (recursion 2nd attempt!)

HW DUE FRIDAY:
-In class, you will run it a few times to show me your awesome sentences. 
-You will have to show me which parts you completed
-For full credit, you need to complete section III
-You must have 2 sets of words (regular + one themed set) This demonstrates you didn't use global variables. 
So you will call it 2 different ways:
improvedSentence(nouns,        properNouns,        verbs, 
                 transitiveVerbs,       adjectives,       adverbs)
improvedSentence(nounsThemed , properNounsThemed , verbsThemed
                 transitiveVerbsThemed, adjectivesThemed, adverbsThemed)

Your Theme can be any number of things:
SciFi
Horror
Harry Potter
MyLittlePony
School
etc.

Your proper nouns can be even more categories if you like...
AvengerNames
PonyNames
StrangeNames
etc.


SECTION 0 (PRE LAB)
Think:
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

BETTER: add 'the' to the sentence: 
the toast runs

1. Add random words lists. They should be in the format:
nouns =  ['kitty', 'toast', 'tea']
verbs =  ['runs', 'plays', 'steams'] 

2. Write a function to get a random element from a list
def getOne( words ):
   ???

YOU SHOULD HAVE getOne before continuing  
Hint: you need to use random numbers to do this
import random
then:
random.randint(ab)

Return a random integer N such that a <= N <= b


3. If you do that then it is trivial to make a simple sentence that chooses a verb and a noun and adds them with spaces!

"the " +getOne(nouns) + " " + getOne(verbs) 


Here is the simple sentence() function:

sentence(nouns,verbs) returns  'the kitty runs'

sentence(nouns,verbs) returns 'the kitty plays'
sentence(nouns,verbs) returns 'the toast steams'

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


If you finished up to this point, you can try to make better sentences by replacing getOne(nouns) and getOne(verbs) 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. 
Your generator should not always give the same type of sentence:
Sometimes noun verb
Sometimes adjective noun verb
Somtimes adjective adjective noun verb
etc. 

All of these can be distilled down to two parts: a noun phrase and a verb phrase
the dog walks
Jack Sparrow clumsily stumbles
the slow pedestrian obliviously drives
(In the next two notice a verb phrase can include a noun phrase inside of it! see part 6 on transitive verbs)
the cat eats the mouse 
the tiny dancer holds Tony Danza


SECTION I (BASICS)
Start with this:
def sentenceImproved(nouns,adjectives,verbs,adverbs):
  return makeNounPhrase(nouns,adjectives) + " "+makeVerbPhrase(verbs,adverbs) 

Remember:
You can pass in other parameters to each function if you need to. (properNoun, transitiveVerb, etc)
makeVerbPhrase might need nouns and adjectives too when you have transitive verbs.
You can create more categories of words.

-You can ignore capitalization.
-You need the random function in more than just your getOne() function.
-You should have the most awesome sentence generator in class on Friday. 


HOW TO MAKE DIFFERENT STYLE RESULTS RANDOMLY
1. We can choose between different options randomly by using  a series of random in the cond statement as  follows:
x = random.randint(0,2)
if x == 0:
  return   THING1
if x == 1:
  return   THING2  
if x == 2:
  return   THING3  
...any number of options just change your random number range



Section II. Make better nouns
def makeNounPhrase(nouns,adjectives):
  ???


HOW TO MODIFY NOUNS
2. AdjectiveBlock: (0 or more adjectives to use in your noun Phrases)
Notice you can have any number of adjectives connected! 
Since you can have 0 or more you can always include an ajective block on normal nouns in your noun phrase.
You can define a function AdjectiveBlock that uses either a loop or recursion to return a random number of adjectives. 
e.g.
AdjectiveBlock(adjectives) -> "slow tall"
AdjectiveBlock(adjectives) -> "fast silly furry"
AdjectiveBlock(adjectives) -> "fishy"
AdjectiveBlock(adjectives) -> ""

Proper Nouns
3. Proper nouns can be one option in your noun phrase list: 
-Do not place a 'the' in front of these! 
-Do not place adjectives here either!
(You would need a separate list of proper nouns, and a function that gets one for you)
Loki defies the world wrestling federation.
Dave walks.
Thor smashes
Tony Stark quickly shoots
The Hulk gleefully plays (notice 'the hulk' is a proper noun, the 'the' is attached to the name...)
 

Section III. Make better verbs
def makeVerbPhrase(verbs,adverbs):
  ???

remember: makeVerbPhrase might need nouns and adjectives too when you have transitive verbs so you can modify it :
def makeVerbPhrase(verbs,adverbs,nouns,adjectives):
  ???


4. AdverbVerbBlock(verbs,adverbs) :   (0 or more adverbs + verb, just like adjectives!) 
it could return:
"quickly runs"
"sleeps"
"slowly silently creeps"
"silently efficiently screams"
"jumps slowly"


5. Some verbs require another noun to tell what is recieving an action. These are called transitive verbs. 

"Joe runs"  is just noun verb

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

Make a 2nd list of transitiveVerbs that requires a 2nd noun/nounphrase. You can randomly select:
-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


Section IV. Make it awesome!

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.

You can add other kinds of phrases, negations, and any language features that you would like to.
You can also try including "and" "or" "but" etc. This would make your sentenceImproved need a few more options...

def sentenceImproved(nouns,adjectives,verbs,adverbs):
  if ???
       return makeNounPhrase(nouns,adjectives) + " "+makeVerbPhrase(verbs,adverbs) #basic structure
  if ???
       #return a different kind of sentence
  etc...

nouns = ['advice', 'airplane', 'alcohol', 'alien', 'aluminum', 'ambigram', 'ambulance', 'ant', 'apple', 'aquarium', 'astrophysicist', 'athlete', 'avocado', 'ball', 'banana', 'barnacle', 'baseball', 'battleship', 'bear', 'bed', 'binder', 'bird', 'blueberry', 'bluejay', 'books', 'bookshelf', 'bowl', 'brouhaha', 'building', 'burger', 'bus', 'butterbeer', 'cadet', 'calendar', 'calculator', 'calculus', 'calculus', 'camera', 'candle', 'candy', 'canine', 'car', 'carnival', 'carpet', 'carrot', 'cat', 'cat', 'cheek', 'cheetah', 'chemistry', 'chicken', 'chocolate', 'chopsticks', 'chrome', 'clout', 'clown', 'comma', 'computer', 'concrete', 'congressman', 'conniption', 'consanguinity', 'conundrum', 'cornucopia', 'couch', 'cow', 'cracker', 'crown', 'cryptocurrency', 'customer', 'death', 'defibrillator', 'deodorant', 'dilemma', 'dinosaur', 'discord', 'disease', 'dog', 'dolphin', 'doorknob', 'dragon', 'duck', 'dust', 'bunny', 'dynasty', 'ease', 'eigenvector', 'elderberries', 'elephant', 'elevator', 'engineer', 'ennui', 'epidemiologist', 'exhibition', 'eyeball', 'fairy', 'fern', 'flower', 'flower', 'flute', 'food', 'foot', 'fox', 'fuddy-duddy', 'gazebo', 'gazelle', 'geodesic', 'giant', 'giraffe', 'girth', 'grades', 'grandma', 'half-and-half', 'hallway', 'headache', 'headsets', 'health', 'heirloom', 'helicopter', 'home', 'hunger', 'iamb', 'ice', 'island', 'isopropyl-alcohol', 'jelly', 'kerfuffle', 'king', 'lab', 'ladder', 'letter', 'macrology', 'loophole', 'lotion', 'love', 'machine', 'magician', 'mars', 'mirage', 'mirror', 'mouse', 'muffin', 'muggle', 'mullet', 'normie', 'nose', 'notebook', 'novel', 'oreos', 'organ', 'ostrich', 'palace', 'panda', 'paper', 'park', 'pear', 'pedigree', 'pencil', 'penguin', 'peregrine', 'falcon', 'person', 'person', 'pillow', 'pillow', 'pineapple', 'pirate', 'plant', 'podcast', 'poetry', 'poster', 'potato', 'projector', 'puppy', 'quail', 'question', 'rack', 'rice', 'river', 'rock', 'sacrifice', 'saddle', 'saiyan', 'sculpture', 'sharpener', 'shibboleth', 'sloth', 'snail', 'spaghetti', 'student', 'subway', 'summit', 'sun', 'sushi', 'table', 'tardis', 'thunder', 'tiger', 'time', 'toddler', 'tomato', 'tongue', 'train', 'treaty', 'tree', 'turtle', 'vapor', 'violet', 'vision', 'wolverine', 'word', 'xebec', 'zither', 'zombie'] 

#YOU NEED TO BREAK UP THE LIST OF VERBS - some are transitive, some require prepositions afterwards, and some are normal. 
verbs = ['accumulates', 'adheres', 'affirms', 'aggregates', 'aids', 'amalgamates', 'assumes', 'attacks', 'bakes', 'baking', 'beckons', 'beholds', 'bellows', 'bolsters', 'breathes', 'breathes', 'browses', 'bulldozes', 'calls', 'calls', 'carries', 'catapults', 'catches', 'cheats', 'chops', 'chucks', 'cleans', 'clips', 'codes', 'constructs', 'creates', 'cries', 'cries', 'crush', 'crying', 'crystallizes', 'cuts', 'dabs', 'dance', 'dances', 'dances', 'dances', 'dashes', 'deceives', 'degusts', 'demands', 'deplores', 'destroys', 'deters', 'dies', 'dies', 'dodges', 'does', 'dozes', 'drink', 'drinks', 'drops', 'eat', 'eating', 'eats', 'eats', 'embark', 'enters', 'escapes', 'executes', 'exemplifies', 'falls', 'falls', 'fears', 'feeds', 'finishes', 'flails', 'flicks', 'flies', 'flies', 'floats', 'flushes', 'flying', 'flys', 'folds', 'follows', 'fosters', 'frolics', 'gallops', 'gathers', 'gives', 'goes', 'golfs', 'hacks', 'hates', 'hits', 'hits', 'holds', 'illuminates', 'inhales', 'interferes', 'invents', 'irritates', 'jettisons', 'jogs', 'jumps', 'kneels', 'kraal', 'leaps', 'licks', 'listens', 'lists', 'lives', 'lounging', 'mars', 'materializes', 'meanders', 'mines', 'mitigates', 'motivates', 'mourns', 'moves', 'naps', 'obtains', 'passes', 'perambulates', 'peruses', 'placates', 'plays', 'plays', 'plunges', 'ponders', 'pours', 'promises', 'pulls', 'push', 'racewalks', 'radiates', 'raids', 'reading', 'reclines', 'recycles', 'reduces', 'reuses', 'rotates', 'ruminates', 'runs', 'runs', 'rustles', 'saunters', 'scares', 'scaring', 'screams', 'screams', 'searches', 'shouts', 'sings', 'sinking', 'skedaddles', 'skips', 'slaps', 'slaps', 'sleep', 'sleeps', 'sleeps', 'slumbers', 'slurps', 'smells', 'smile', 'smiling', 'smirks', 'snorkels', 'soaks', 'speaks', 'splats', 'sprints', 'squanders', 'submits', 'survives', 'swim', 'swims', 'swims', 'tantalizes', 'taste', 'tenses', 'thinks', 'thinks', 'throws', 'throws', 'tries', 'tries', 'trudges', 'tumbles', 'types', 'vomits', 'votes', 'waddles', 'walks', 'want', 'whispers', 'win', 'works', 'writes', 'yeets', 'zip-lines'] 

adjectives = ['abominable', 'admirable', 'aggressive', 'alarming', 'amazing', 'ambiguous', 'angry', 'annoying', 'annoying', 'antibiotic', 'antidisestablishmentarian', 'arrogant', 'authentic', 'bald', 'barbarous', 'bawdy', 'beautiful', 'beautiful', 'bereft', 'bereft', 'big', 'big', 'bilious', 'bludgeoned', 'blue', 'boring', 'brackish', 'brash', 'brave', 'bright', 'broken', 'brown', 'calamitous', 'calm', 'chaotic', 'charismatic', 'cheerful', 'chunky', 'cloudy', 'colorful', 'comely', 'confused', 'confuzzle', 'cool', 'cordial', 'coriacious', 'corrosive', 'coy', 'crazy', 'creepy', 'crimson', 'crispy', 'cruel', 'cumbersome', 'dangerous', 'dank', 'dead', 'dead', 'deafening', 'delicious', 'delightful', 'deplorable', 'depressed', 'difficult', 'diffident', 'dim', 'diminutive', 'diplomatic', 'discombobulated', 'disgusting', 'distorted', 'dizzy', 'draconian', 'dreamy', 'drumpf', 'dumb', 'dummy', 'eager', 'ecstatic', 'egregious', 'evanescent', 'excited', 'exhilarating', 'exquisite', 'extra', 'extravagant', 'exuberant', 'exuberant', 'fast', 'fast', 'fire-breathing', 'firm', 'first', 'flaccid', 'flimsy', 'flippant', 'fluffy', 'fluffy', 'forlorn', 'fragile', 'free', 'fresh', 'frustrating', 'funny', 'gargantuan', 'giant', 'glib', 'gothic', 'grandiose', 'green', 'happy', 'hard', 'hedonistic', 'heroic', 'hostile', 'hot', 'huge', 'huge', 'impromptu', 'inexpensive', 'innocent', 'insensitive', 'interesting', 'interesting', 'invincible', 'jarring', 'jolly', 'kafkaesque', 'languid', 'late', 'lazy', 'long', 'loquacious', 'lucky', 'ludicrous', 'mammoth', 'maniacal', 'melodic', 'moist', 'mouthwatering', 'muscular', 'mystic', 'neutral', 'nice', 'non-offensive', 'normal', 'obsequious', 'obtuse', 'odd', 'Orwellian', 'pale', 'partitioned', 'petulant', 'possessive', 'practical', 'proactive', 'quadripartite', 'quick', 'random', 'rare', 'red', 'red', 'regretful', 'repulsive', 'resonant', 'reverent', 'romanized', 'rotten', 'rubiginous', 'rustic', 'sad', 'salty', 'satanic', 'scruffy', 'scrumptious', 'scrumptious', 'serendipitous', 'shiny', 'short', 'silent', 'sketchy', 'slow', 'slow', 'small', 'smart', 'soft', 'sore', 'sparkling', 'sparkly', 'spicy', 'squishy', 'stinky', 'strenuous', 'strong', 'stupendous', 'stupendous', 'successful', 'supercalifragilisticexpialidocious', 'surreal', 'surrounded', 'swanky', 'sweaty', 'swift', 'taboo', 'tacky', 'tall', 'tasty', 'tenacious', 'tiny', 'tired', 'unladen', 'upset', 'useful', 'vast', 'venomous', 'voracious', 'wet', 'wild', 'wonderful', 'zany', 'zealous', 'zoophagous'] 

adverbs = ['inadvertently', 'abnormally', 'above', 'abruptly', 'absentmindedly', 'across', 'afterwards', 'always', 'amazingly', 'angrily', 'anxiously', 'bashfully', 'beautifully', 'because', 'below', 'boldly', 'brilliant', 'brutally', 'cagily', 'calmly', 'carefully', 'cautiously', 'childishly', 'cleverly', 'coaxingly', 'continuously', 'cooly', 'courageously', 'cowardly', 'crazily', 'deadly', 'deliberately', 'desperately', 'diminishingly', 'dramatically', 'dreadfully', 'early', 'elegantly', 'endlessly', 'endlessly', 'enjoyably', 'enthusiastically', 'erroneously', 'esoterically', 'especially', 'eternally', 'everywhere', 'excruciatingly', 'expeditiously', 'flagrantly', 'frankly', 'frantically', 'frenetically', 'funnily', 'gently', 'genuinely', 'gingerly', 'grotesquely', 'haphazardly', 'happily', 'hastily', 'helplessly', 'hilariously', 'honestly', 'hurriedly', 'idyllically', 'immaculately', 'impatiently', 'impressively', 'incompetently', 'indubitably', 'inquisitively', 'instantly', 'interestingly', 'jauntily', 'jubilantly', 'justly', 'keenly', 'kindly', 'kindly', 'lasciviously', 'lastly', 'lazily', 'lazily', 'lifelessly', 'lightly', 'loftily', 'loudly', 'lovely', 'luckily', 'majestically', 'meaningfully', 'mysteriously', 'nervously', 'nervously', 'occasionally', 'onwards', 'optimistically', 'optimistically', 'painfully', 'pathetically', 'powerfully', 'precariously', 'presently', 'properly', 'quaintly', 'queasily', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quietly', 'randomly', 'rapidly', 'really', 'recklessly', 'regretfully', 'regularly', 'rhapsodically', 'roughly', 'sadly', 'salaciously', 'scarcely', 'secretively', 'sedately', 'selfishly', 'serendipitously', 'sheepishly', 'shortly', 'shrewdly', 'silently', 'silently', 'sloppily', 'slowly', 'slowly', 'slowly', 'slowly', 'slowly', 'slowly', 'sluggishly', 'slyly', 'smoothly', 'solemnly', 'sorrowfully', 'speedily', 'steadily', 'stealthily', 'strongly', 'studiously', 'stupidly', 'suddenly', 'surprisingly', 'sweetly', 'swiftly', 'swimmingly', 'terribly', 'terribly', 'there', 'thoroughly', 'tiredly', 'tomorrow', 'tremulously', 'trickily', 'triumphantly', 'truthfully', 'unbearably', 'underground', 'unenthusiastically', 'unfortunately', 'unpredictably', 'unquestionably', 'violently', 'wearily', 'wickedly', 'wildly', 'zealously']
Comments