SCRIPTS & FUNCTIONS DAY 18 - 10/06/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.

Slides:



Advertisements
Similar presentations
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Lab III – Linux at UMBC.
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Conditional Execution
Format Basics in Word Word for Windows Tom Wolsey Walden University.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
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.
Automating Tasks With Macros
Creating a Users Table The users table contains a list of your site’s authorized users, logins, and passwords.
UNICODE & CONTROL DAY /24/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Java Programming, 3e Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Introduction to VB.NET Tonga Institute of Higher Education.
Python Programming Fundamentals
How to Download and Install a Sharp Print Driver on a Mac.
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.
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
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.
Python Basic Syntax. Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello,
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
UNICODE DAY /22/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COMPUTATION WITH STRINGS 2 DAY 2 - 8/29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
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.
Conditional Execution Chapter 3 Python for Informatics: Exploring Information
REGULAR EXPRESSIONS 3 DAY 8 - 9/12/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
1 Microsoft Management Console Tool to create customized administration tools Customized tools known as MMC consoles, or simply consoles.
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.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
Make a dice challenge! This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Copy the code below in.
An Introduction to Programming with Alice Playing an Alice World.
NLTK & Python Day 8 LING Computational Linguistics Harry Howard Tulane University.
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.
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Python Lesson 12 Mr. Kalmes.
Flat text Day 6 - 9/12/16 LING 3820 & 6820 Natural Language Processing
Computation with strings 2 Day 3 - 9/02/16
Python Lesson 12 Mr. Kalmes.
Flat text 2 Day 7 - 9/14/16 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
If, else, elif.
Computation with strings 3 Day 4 - 9/07/16
Frozen Graphics Lesson 3.
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
Teaching London Computing
Control 3 Day /05/16 LING 3820 & 6820 Natural Language Processing
NLP 2 Day /07/16 LING 3820 & 6820 Natural Language Processing
Regular expressions 3 Day /26/16
Computation with strings 4 Day 5 - 9/09/16
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Presentation transcript:

SCRIPTS & FUNCTIONS DAY /06/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Course organization 06-Oct-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 06-Oct NLP, Prof. Howard, Tulane University

Open Spyder 06-Oct NLP, Prof. Howard, Tulane University

Scripts 06-Oct NLP, Prof. Howard, Tulane University

Introduction  By now, you are probably tired of making a tiny error in a long conditional expression and having to rewrite the whole thing.  It would be much easier to write it once, correct it, and then have Python run it as many times as you like.  This is ‘batch’, rather than ‘interactive’ mode, and your code will be saved as a script. 06-Oct-2014NLP, Prof. Howard, Tulane University 6

Scripts in Spyder  It is here that the graphical interface of Spyder shows its superiority.  Under the File menu, choose New file…, which opens a window for a blank Python file.  Or nearly blank, since Spyder fills in the top few lines with a header, such as: 1. """ 2. Created on Mon Jun 3 19:55: Harry Howard 5. """ 06-Oct-2014NLP, Prof. Howard, Tulane University 7

Type this into your blank script beneath the comment in quotes greeting = 'Yo!' caseList = [] for char in greeting: if char.islower(): caseList.append('yes') elif char.isupper(): caseList.append('no') else: caseList.append('whoops!') print caseList 06-Oct-2014NLP, Prof. Howard, Tulane University 8

Saving a script  Save your work by going to the File menu, choosing Save as… and giving the file the name “test”, keeping the.py suffix. 06-Oct-2014NLP, Prof. Howard, Tulane University 9

Create a folder for your scripts in your Documents folder 06-Oct-2014NLP, Prof. Howard, Tulane University 10 pyScripts

Running your script  Now that you have named and saved your script, go to the Run menu of Spyder and select Run.  The first time that you do this for a script, a dialog window will open like the one below that asks you to make some decisions.  You should set the working directory to the pyScripts folder that you just created in your Documents folder. 06-Oct-2014NLP, Prof. Howard, Tulane University 11

Defaults to run a script also in: Preferences > Run 06-Oct-2014NLP, Prof. Howard, Tulane University 12

Where are my files?  Where are your files? 06-Oct-2014NLP, Prof. Howard, Tulane University 13

The response  The console should print a response like the following to running the script:  >>> runfile('/Users/harryhow/Documents/pyScripts/ test.py', wdir=r'/Users/harryhow/Documents/pyScripts')  ['no', 'yes', 'whoops!']  >>> 06-Oct-2014NLP, Prof. Howard, Tulane University 14

Functions 06-Oct NLP, Prof. Howard, Tulane University

Turn your code into a function def caseChecker(word): caseList = [] for char in word: if char.islower(): caseList.append('yes') elif char.isupper(): caseList.append('no') else: caseList.append('whoops!') return caseList 06-Oct-2014NLP, Prof. Howard, Tulane University 16

In the console, import your function & use it 1. >>> from test import caseChecker 2. >>> caseChecker('Cool!!') 3. ['no', 'yes', 'yes', 'yes', 'whoops!', 'whoops!'] 06-Oct-2014NLP, Prof. Howard, Tulane University 17

Homework: turn your answer to today's quiz into a function, import it in the console & test it various lists Start with NLTK Next time 06-Oct-2014NLP, Prof. Howard, Tulane University 18