control 4 Day /01/14 LING 3820 & 6820 Natural Language Processing

Slides:



Advertisements
Similar presentations
7-Jun-14 Lists. Arrays and Lists Arrays are a fixed length and occupy sequential locations in memory This makes random access (for example, getting the.
Advertisements

Regular expressions Day 2
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
NLTK & Python Day 4 LING Computational Linguistics Harry Howard Tulane University.
Strings and regular expressions Day 10 LING Computational Linguistics Harry Howard Tulane University.
TEXT STATISTICS 1 DAY /20/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TEXT STATISTICS 7 DAY /05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
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.
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:
TEXT STATISTICS 5 DAY /29/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.
Structured programming 4 Day 34 LING Computational Linguistics Harry Howard Tulane University.
ON-LINE DOCUMENTS 3 DAY /17/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
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.
COMPUTATION WITH STRINGS 2 DAY 2 - 8/29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane 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”?
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
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.
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.
REGULAR EXPRESSIONS 2 DAY 7 - 9/10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
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.
TEXT STATISTICS 3 DAY /24/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane 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.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
 Type Called bool  Bool has only two possible values: True and False.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Lists 1 Day /17/14 LING 3820 & 6820 Natural Language Processing
LING 3820 & 6820 Natural Language Processing Harry Howard
Lists 2 Day /19/14 LING 3820 & 6820 Natural Language Processing
Flat text Day 6 - 9/12/16 LING 3820 & 6820 Natural Language Processing
ECS10 10/10
Computation with strings 2 Day 3 - 9/02/16
Announcements Project 4 due Wed., Nov 7
Flat text 2 Day 7 - 9/14/16 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Computation with strings 3 Day 4 - 9/07/16
Regular expressions 2 Day /23/16
LING 3820 & 6820 Natural Language Processing Harry Howard
LING 3820 & 6820 Natural Language Processing Harry Howard
Real Numbers COURSE 3 CHAPTER 4 1. yes 2. no 3. yes
Control 3 Day /05/16 LING 3820 & 6820 Natural Language Processing
NLP 2 Day /07/16 LING 3820 & 6820 Natural Language Processing
Patterns to KNOW.
Logical Operations In Matlab.
Regular expressions 3 Day /26/16
Introduction to Syntax ANTH 3590/7590 Harry Howard Tulane University
Variables, Lists, and Objects
The Data Element.
Computation with strings 4 Day 5 - 9/09/16
The Data Element.
2-3 Subtracting Integers Warm Up Problem of the Day
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Introduction to Computer Science
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

control 4 Day 16 - 10/01/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Course organization http://www.tulane.edu/~howard/LING3820/ The syllabus is under construction. http://www.tulane.edu/~howard/CompCultEN/ Chapter numbering 3.7. How to deal with non-English characters 4.5. How to create a pattern with Unicode characters 6. Control NLP, Prof. Howard, Tulane University 29-Sept-2014

Review of control NLP, Prof. Howard, Tulane University 29-Sept-2014

Conditional expressions >>> if True: ... do something ... ... elif True: ... else: NLP, Prof. Howard, Tulane University 29-Sept-2014

For loop & list conmprehension >>> for item in container: ... do something to item ... >>> newList = [] ... newList.append(item) >>> newList = [item for item in container] NLP, Prof. Howard, Tulane University 29-Sept-2014

Add a condition >>> newList = [] >>> for item in container: ... if condition: ... newList.append(item) ... >>> newList = [item for item in container if condition] NLP, Prof. Howard, Tulane University 29-Sept-2014

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

6.3.4. How to check a condition in a loop NLP, Prof. Howard, Tulane University 29-Sept-2014

Chained conditions in a loop >>> greeting = 'Yo!' >>> caseList = [] >>> for char in greeting: ... if char.islower(): ... caseList.append('yes') ... elif char.isupper(): ... caseList.append('no') ... else: ... caseList.append('whoops!') ... >>> caseList ['no', 'yes', 'whoops!'] NLP, Prof. Howard, Tulane University 29-Sept-2014

A chained conditional list comprehension However there is no list comprehension that is exactly analogous to a chained conditional, since elif is not allowed in them. A list comprehension only allows if -- else, so the elif has to be decomposed into else -- if. Here is what it looks like in a loop: NLP, Prof. Howard, Tulane University 29-Sept-2014

Example >>> caseList = [] >>> for char in greeting: ... if char.islower(): ... caseList.append('yes') ... else: ... if char.isupper(): ... caseList.append('no') ... else: ... caseList.append('whoops!') ... >>> caseList ['no', 'yes', 'whoops!'] >> caseList = ['yes' if char.islower() else 'no' if char.isupper() else 'whoops!' for char in greeting] NLP, Prof. Howard, Tulane University 29-Sept-2014

6.3.5. How to transform items within a loop The argument of append() takes any type that can be an element of a list, such as strings or integers, so it can hold the result of a method: >>> upperList = [] >>> for char in greeting: ... upperList.append(char.upper()) ... >>> upperList ['Y', 'O', '!'] >>> lenList = [] >>> for word in fruit: ... lenList.append(len(word)) >>> lenList [5, 6, 5, 4, 10] NLP, Prof. Howard, Tulane University 29-Sept-2014

>>> upperList = [char.upper() for char in greeting] A list comprehension can perform the same change by applying it to the first mention of the item: >>> upperList = [char.upper() for char in greeting] >>> upperList ['Y', 'O', '!'] >>> lenList = [len(word) for word in fruit] >>> lenList [5, 6, 5, 4, 10] NLP, Prof. Howard, Tulane University 29-Sept-2014

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