LING 388: Computers and Language

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Point of View EQ 1-When discussing a reading selection, what do we mean by point of view? ( ) (CCSS RL6)
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Working with Files CSC 161: The Art of Programming Prof. Henry Kautz 11/9/2009.
LING 408/508: Programming for Linguists Lecture 19 November 4 th.
Homework Reading Programming Assignments
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Module 6 Unit 2 The white rabbit was looking at its watch.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/30.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
 Life science: Cotton, Jacqueline. (2004). Polar Bears. Minneapolis, MN: Lerner.  Physical science: Simon, Seymour. (2010). Global Warming. New York:
Built-in Data Structures in Python An Introduction.
Fill the screen challenge! This is a starter activity and should take 3 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In interactive mode,
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
ITEC 320 Lecture 10 Examples. Review Strings –What types are there? –What are the differences? –What should you use where? Homework –Hardest part –Easiest.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
Dictionaries.   Review on for loops – nested for loops  Dictionaries (p.79 Learning Python)  Sys Module for system arguments  Reverse complementing.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Great First Lines Peggy Korman CNM. First lines of a novel. The first line sets the scene, the tone, sheds just enough light on the upcoming story to.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Textual Evidence: Implicit and Explicit Source:
2016 N5 Prelim Revision. HTML Absolute/Relative addressing in HTML.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
LING 408/508: Programming for Linguists Lecture 20 November 16 th.
Alice in Wonderland By Lewis Carroll. Down the Rabbit-Hole Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing.
Unit 2. Alice’s Adventures in Wonderland who what where Tip: Sometimes we can find the main idea of the passage from its title.
“Annabel,” said Jimmy, “give me that rose you are wearing, will you?” Hardly believing that she had heard him right, she unpinned the flower from her dress.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 9 For Loops.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Alice’s Adventures in Wonderland by Lewis Carroll Chapter 1 - Down the Rabbit Hole.
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
Alice in Wonderland Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped.
Introduction to python programming
CST 1101 Problem Solving Using Computers
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Python: Experiencing IDLE, writing simple programs
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Key Stage 1 National Curriculum Assessments
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
String Manipulation.
LING 388: Computers and Language
LING 388: Computers and Language
LING 388: Computers and Language
LING 388: Computers and Language
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
Learning Outcomes –Lesson 4
LING 388: Computers and Language
LING 388: Computers and Language
Teaching London Computing
Data Structures – 1D Lists
I210 review.
Text Analyzer BIS1523 – Lecture 14.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Text / Serial / Sequential Files
LING 408/508: Computational Techniques for Linguists
Homework Reading Programming Assignments Finish K&R Chapter 1
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
LING 388: Computers and Language
CS1110 Today: collections.
CSCI N207 Data Analysis Using Spreadsheet
CISC101 Reminders Assignment 2 due today.
Introduction to Computer Science
Chopin’s Nocturne.
Introduction to Python programming for KS3
Text / Serial / Sequential Files
Sample lecture slides.
LING 388: Computers and Language
Revision well-known 1. What's the story about? 2. What was she doing?
Presentation transcript:

LING 388: Computers and Language Lecture 7

Today's Topics Programming exercises (to be done in class) Homework

Python https://docs.python.org/3/tutorial/introduction.html We have covered: Numbers Strings (indexing, slices) Lists (stacks, queues – see deques) Sets Dictionaries Ranges

Exercise 1 Enter this (1st paragraph in "Alice's Adventures in Wonderland" by Lewis Carroll) into Python: paragraph1 = 'Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do. Once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice, "without pictures or conversations?"' len(paragraph1) counts what? What does paragraph1.split() do? Store the result of split into a variable paragraph2 len(paragraph2) counts what? Calculate the average number of characters per word

Exercise 2 Write a for loop to print each word on a separate line paragraph2 ['Alice', 'was', 'beginning', 'to', 'get', 'very', 'tired', 'of', 'sitting', 'by', 'her', 'sister', 'on', 'the', 'bank,', 'and', 'of', 'having', 'nothing', 'to', 'do.', 'Once', 'or', 'twice', 'she', 'had', 'peeped', 'into', 'the', 'book', 'her', 'sister', 'was', 'reading,', 'but', 'it', 'had', 'no', 'pictures', 'or', 'conversations', 'in', 'it,', '"and', 'what', 'is', 'the', 'use', 'of', 'a', 'book,"', 'thought', 'Alice,', '"without', 'pictures', 'or', 'conversations?"'] Write a for loop to print each word on a separate line Notice some words end in punctuation, e.g. bank, or do. or book," Notice some words begin in punctuation, e.g. "and or "without. Try the following: import re word = 'conversations?"' re.sub("[?\"'.]","",word) Write a for loop to print the each word of paragraph2 (with punctuation deleted) on a separate line

Exercise 2 Enter this: What does this kind of for loop do? [x.lower() for x in paragraph2] [re.sub("[?\"'.]","",x) for x in paragraph2] What does this kind of for loop do? (It's called a list comprehension.)

Exercise 2: Examples >>>[x.lower() for x in paragraph2] ['alice', 'was', 'beginning', 'to', 'get', 'very', 'tired', 'of', 'sitting', 'by', 'her', 'sister', 'on', 'the', 'bank,', 'and', 'of', 'having', 'nothing', 'to', 'do.', 'once', 'or', 'twice', 'she', 'had', 'peeped', 'into', 'the', 'book', 'her', 'sister', 'was', 'reading,', 'but', 'it', 'had', 'no', 'pictures', 'or', 'conversations', 'in', 'it,', '"and', 'what', 'is', 'the', 'use', 'of', 'a', 'book,"', 'thought', 'alice,', '"without', 'pictures', 'or', 'conversations?"'] >>>paragraph3 = [x.lower() for x in paragraph2] >>>paragraph3 >>>[re.sub("[,.?'\"]", "", x) for x in paragraph3] ['alice', 'was', 'beginning', 'to', 'get', 'very', 'tired', 'of', 'sitting', 'by', 'her', 'sister', 'on', 'the', 'bank', 'and', 'of', 'having', 'nothing', 'to', 'do', 'once', 'or', 'twice', 'she', 'had', 'peeped', 'into', 'the', 'book', 'her', 'sister', 'was', 'reading', 'but', 'it', 'had', 'no', 'pictures', 'or', 'conversations', 'in', 'it', 'and', 'what', 'is', 'the', 'use', 'of', 'a', 'book', 'thought', 'alice', 'without', 'pictures', 'or', 'conversations'] >>>[re.sub("[.,?'\"]", "",x.lower()) for x in paragraph2] >>>[re.sub("[.,?'\"]", "",x).lower() for x in paragraph2] >>>[re.sub("[.,?'\"]", "",x) for x.lower() in paragraph2] File "<stdin>", line 1 SyntaxError: can't assign to function call

Exercise 3 Enter this: from collections import Counter c = Counter() c['alice'] += 1 c['a'] += 1 c c.most_common() See also https://docs.python.org/3/library/collections.html#collections.Counter

Homework 4 Starting with: paragraph1 = 'Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do. Once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice, "without pictures or conversations?"' and using what you've learnt in Exercises 1–3, write Python code that builds a frequency table for words in paragraph1 Use the most_common() method to print your table Submit your python console (cut and paste or screen snapshot) showing your work

Homework 4 Submit to TA Patricia Lee by next Wednesday (by midnight) One PDF file only!