Presentation is loading. Please wait.

Presentation is loading. Please wait.

CONTROL 2 DAY 14 - 9/26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.

Similar presentations


Presentation on theme: "CONTROL 2 DAY 14 - 9/26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University."— Presentation transcript:

1 CONTROL 2 DAY 14 - 9/26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

2 Course organization 26-Sept-2014NLP, Prof. Howard, Tulane University 2  http://www.tulane.edu/~howard/LING3820/ http://www.tulane.edu/~howard/LING3820/  The syllabus is under construction.  http://www.tulane.edu/~howard/CompCultEN/ http://www.tulane.edu/~howard/CompCultEN/  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

3 re.findall(pattern, source, re.UNICODE) ord() and unichar() Review of Unicode 26-Sept-2014 3 NLP, Prof. Howard, Tulane University

4 object in string or list object not in string or list Review of control 26-Sept-2014 4 NLP, Prof. Howard, Tulane University

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

6 6.1. How to check the truth of a statement 26-Sept-2014 6 NLP, Prof. Howard, Tulane University

7 6.1.3. How to check the properties of a string 1. >>> S = 'CoNfUsIoN' 2. >>> S.isalpha() 3. >>> S.isdigit() 4. >>> S.isalnum() 5. >>> S.isspace() 6. >>> S.islower() 7. >>> S.isupper() 8. >>> S.istitle() 9. >>> S.startswith('CoN') 10. >>> S.endswith('IoN') 26-Sept-2014NLP, Prof. Howard, Tulane University 7

8 6.1.5. How to compare magnitude with ==, !=,, >= 1. >>> dessert = 'watermelon' 2. >>> fruit = ['apple', 'cherry', 'mango', 'pear', 'watermelon'] 3. >>> len(dessert) == len(dessert) 4. >>> len(dessert) != len(fruit) 5. >>> len(fruit) < len(dessert) 6. >>> len(fruit) <= len(dessert) 7. >>> len(dessert) > len(fruit) 8. >>> len(dessert) >= len(fruit) 9. >>> len(fruit) < len(S) < len(dessert) == 10 26-Sept-2014NLP, Prof. Howard, Tulane University 8

9 6.1.6. How to check identity and type with is and isinstance() 1. >>> dessert is dessert 2. >>> dessert is not fruit 3. >>> dessert is str 4. >>> isinstance(dessert, str) 5. >>> isinstance(fruit, list) 6. >>> isinstance(1, int) 7. >>> isinstance(1.0, float) 8. >>> isinstance(1, float) 9. >>> isinstance(dessert, list) 10. >>> not isinstance(dessert, list) 26-Sept-2014NLP, Prof. Howard, Tulane University 9

10 and, or 1. >>> S.isalpha() and S.startswith('CoN') 2. >>> not S.isdigit() and not S.startswith('oN') 3. >>> S.isalpha() or S.isdigit() 4. >>> S.isupper() or S.islower() 26-Sept-2014NLP, Prof. Howard, Tulane University 10

11 6.2. How to make action contingent on a condition with if 26-Sept-2014 11 NLP, Prof. Howard, Tulane University

12 if statements 1. >>> if 'N' in S: 2.... print 'yes' 3.... 4. yes  'N' in S is the trigger or condition and print 'yes' is the action that are coordinated by if. 26-Sept-2014NLP, Prof. Howard, Tulane University 12

13 The condition must evaluate to true  The condition must evaluate to true, whether it is positive or negative; if the condition evaluates to false, the trigger fails and no action is taken. 1. >>> if 'n' in S: 2.... print 'yes' 3.... 4. >>> 5. >>> if 'n' not in S: 6.... print 'no' 7.... 8. no 9. >>> if 'N' not in S: 10.... print 'no' 11.... 12. >>> 26-Sept-2014NLP, Prof. Howard, Tulane University 13

14 The general syntax for if is 1. >>> if True: 2.... do something 3.... 26-Sept-2014NLP, Prof. Howard, Tulane University 14

15 More examples 1. >>> if S.isalpha(): 2.... print 'yes' 3.... 4. yes 5. >>> if S.endswith('IoN'): 6.... print 'yes' 7.... 8. yes 9. >>> if not S.endswith('CoN'): 10.... print 'yes' 11.... 12. yes 26-Sept-2014NLP, Prof. Howard, Tulane University 15

16 More examples  >>> if re.search(r'N', S): ... print 'yes' ...  yes  >>> if re.search(r'IoN$', S): ... print 'yes' ...  yes  >>> if not re.search(r'CoN$', S): ... print 'yes' ...  yes  >>> if len('CoN') < len(S): ... print 'yes' ...  yes 26-Sept-2014NLP, Prof. Howard, Tulane University 16

17 More examples  >>> if isinstance(S, str): ... print 'yes' ...  yes  >>> if S.isalpha() or S.isdigit(): ... print 'yes' ...  yes 26-Sept-2014NLP, Prof. Howard, Tulane University 17

18 Note to self  This is 20m too short. 26-Sept-2014NLP, Prof. Howard, Tulane University 18

19 Q4 take home More on control Next time 26-Sept-2014NLP, Prof. Howard, Tulane University 19


Download ppt "CONTROL 2 DAY 14 - 9/26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University."

Similar presentations


Ads by Google