CONTROL 3 DAY 15 - 9/29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.

Slides:



Advertisements
Similar presentations
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Advertisements

Strings and regular expressions Day 10 LING Computational Linguistics Harry Howard Tulane University.
Chapter 2 Writing Simple Programs
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Python Control of Flow.
UNICODE & CONTROL DAY /24/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
NLTK & BASIC TEXT STATS DAY /08/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COMPUTATION WITH STRINGS 4 DAY 5 - 9/05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Lists and More About Strings CS303E: Elements of Computers and Programming.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
ON-LINE DOCUMENTS 3 DAY /17/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
UNICODE DAY /22/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Structured programming 3 Day 33 LING Computational Linguistics Harry Howard Tulane University.
Programming in Python Part III Dr. Fatma Cemile Serçe Atılım University
SCRIPTS & FUNCTIONS DAY /06/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TWITTER DAY /07/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TWITTER 2 DAY /10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
WEB TEXT DAY /14/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
REGULAR EXPRESSIONS 3 DAY 8 - 9/12/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
REGULAR EXPRESSIONS 4 DAY 9 - 9/15/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COMPUTATION WITH STRINGS 1 DAY 2 - 8/27/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
REGULAR EXPRESSIONS 2 DAY 7 - 9/10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
NLTK & Python Day 6 LING Computational Linguistics Harry Howard Tulane University.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
REGULAR EXPRESSIONS 1 DAY 6 - 9/08/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
ON-LINE DOCUMENTS DAY /13/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CONTROL 2 DAY /26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TWITTER 3 DAY /12/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Python Data Structures By Greg Felber. Lists An ordered group of items Does not need to be the same type – Could put numbers, strings or donkeys in the.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Chapter 2 Writing Simple Programs
String and Lists Dr. José M. Reyes Álamo.
Lists 1 Day /17/14 LING 3820 & 6820 Natural Language Processing
String Methods Programming Guides.
Lists 2 Day /19/14 LING 3820 & 6820 Natural Language Processing
Computation with strings 3 Day 4 - 9/07/16
CHAPTER 7 STRINGS.
Regular expressions 2 Day /23/16
control 4 Day /01/14 LING 3820 & 6820 Natural Language Processing
LING 3820 & 6820 Natural Language Processing Harry Howard
CS190/295 Programming in Python for Life Sciences: Lecture 6
Control 3 Day /05/16 LING 3820 & 6820 Natural Language Processing
NLP 2 Day /07/16 LING 3820 & 6820 Natural Language Processing
String and Lists Dr. José M. Reyes Álamo.
Lists in Python Outputting lists.
Regular expressions 3 Day /26/16
Variables, Lists, and Objects
The Data Element.
Topics Basic String Operations String Slicing
Introduction to Computer Science
Computation with strings 4 Day 5 - 9/09/16
Introduction to Computer Science
Topics Basic String Operations String Slicing
The Data Element.
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Topics Basic String Operations String Slicing
Introduction to Computer Science
Presentation transcript:

CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Course organization 29-Sept-2014NLP, Prof. Howard, Tulane University 2   The syllabus is under construction.   Chapter numbering  3.7. How to deal with non-English characters 3.7. How to deal with non-English characters  4.5. How to create a pattern with Unicode characters 4.5. How to create a pattern with Unicode characters  6. Control 6. Control

The quiz was the review. Review of control 29-Sept NLP, Prof. Howard, Tulane University

Open Spyder 29-Sept NLP, Prof. Howard, Tulane University

Chained conditionals 29-Sept NLP, Prof. Howard, Tulane University

Chained conditions  Imagine that you wanted to check whether a character is lowercase.  You would test for two conditions: whether it is lowercase or whether it is uppercase.  But there are a lot of leftovers which are neither one – the punctuation.  These three conditions are mutually exclusive, so they cannot be stated as three ifs. 29-Sept-2014NLP, Prof. Howard, Tulane University 6

A chained conditional expression 1. >>> char = 'Y' 2. >>> if char.islower(): print 'yes' elif char.isupper(): print 'no' else: print 'whoops!' no 29-Sept-2014NLP, Prof. Howard, Tulane University 7

In computer science, the programming construct for examining every item of a collection is called a loop. This could be every character in a string or every word in a list Iterating over the items of a collection with a loop 29-Sept NLP, Prof. Howard, Tulane University

How to examine every item with for  As a simple example, consider printing every letter of a word: 1. >>> greeting = 'Yo!' 2. >>> for char in greeting: print char Y 6. o 7. ! 29-Sept-2014NLP, Prof. Howard, Tulane University 9

Iteration over a list 1. >>> fruit = ['apple', 'cherry', 'mango', 'pear', 'watermelon'] 2. >>> for word in fruit: print word apple 6. cherry 7. mango 8. pear 9. watermelon 29-Sept-2014NLP, Prof. Howard, Tulane University 10

A trick for printing  To save space in your Python console, adding a comma after the variable to be printed puts the output on the same line: 1. >>> for char in greeting: print char, Y o ! 5. >>> for word in fruit: print word, apple cherry mango pear watermelon 29-Sept-2014NLP, Prof. Howard, Tulane University 11

How to make a list during a loop with append() 1. >>> charlist = [] 2. >>> for char in greeting: charlist.append(char) >>> charlist 6. ['Y', 'o', '!'] 29-Sept-2014NLP, Prof. Howard, Tulane University 12

Doing the same with a list, redundantly 1. >>> wordlist = [] 2. >>> for word in fruit: wordlist.append(word) >>> wordlist 6. ['apple', 'cherry', 'mango', 'pear', 'watermelon'] 29-Sept-2014NLP, Prof. Howard, Tulane University 13

How to pack a loop into a list with a list comprehension  Creating a list from a loop is such a frequent task that Python has a breathtakingly elegant idiom for accomplishing it, the list comprehension.  It consists of putting the whole for statement within square brackets, with the appending signaled by the brackets themselves. 29-Sept-2014NLP, Prof. Howard, Tulane University 14

List comprehension with string example 1. >>> charlist = [] 2. >>> for char in greeting: charlist.append(char) >>> charlist 6. ['Y', 'o', '!'] 7. >>> charlist = [char for char in greeting] 8. charlist 9. ['Y', 'o', '!'] 29-Sept-2014NLP, Prof. Howard, Tulane University 15

List comprehension with list example 1. >>> wordlist = [] 2. >>> for word in fruit: wordlist.append(word) >>> wordlist 6. ['apple', 'cherry', 'mango', 'pear', 'watermelon'] 7. >>> wordlist = [word for word in fruit] 8. >>> wordlist 9. ['apple', 'cherry', 'mango', 'pear', 'watermelon'] 29-Sept-2014NLP, Prof. Howard, Tulane University 16

The list comprehension in set theory  The format of the list comprehension is inspired on a similar expression in set theory:  {e | e ∈ F & P(e)}  This is read as “the set of e’s such that e is an element of F and P of e (e has the property P)”. 29-Sept-2014NLP, Prof. Howard, Tulane University 17

How to check a condition in a loop  The ultimate step in making a decision about a collection of items is to make membership in the output contingent on a condition: 1. >>> lowchar = [] 2. >>> for char in greeting: if char.islower(): lowchar.append(char) >>> lowchar 7. ['o'] 8. >>> lowchar = [char for char in greeting if char.islower()] 9. >>> lowchar 10. ['o'] 29-Sept-2014NLP, Prof. Howard, Tulane University 18

List example 1. >>> melonlist = [] 2. >>> for word in fruit: if word.endswith('melon'): melonlist.append(word) >>> melonlist 7. ['watermelon'] 8. >>> melonlist = [word for word in fruit if word.endswith('melon')] 9. ['watermelon'] 29-Sept-2014NLP, Prof. Howard, Tulane University 19

Chained conditions in a loop 1. >>> for char in greeting: if char.islower(): print 'yes' elif char.isupper(): print 'no' else: print 'whoops!'' no 10. yes 11. whoops! 29-Sept-2014NLP, Prof. Howard, Tulane University 20

Finish control Next time 29-Sept-2014NLP, Prof. Howard, Tulane University 21