Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Introduction to Python LING 5200 Computational Corpus Linguistics Martha Palmer.

Similar presentations


Presentation on theme: "1 Introduction to Python LING 5200 Computational Corpus Linguistics Martha Palmer."— Presentation transcript:

1 1 Introduction to Python LING 5200 Computational Corpus Linguistics Martha Palmer

2 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 2 What's a programming language? Structural elements Way of converting a text file to instructions for the machine

3 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 3 What's a programming language? lexicon syntax Vs. natural languages: no ambiguity

4 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 4 What does a program do? Take in data (input) Do something with it (processing) Produce output

5 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 5 What does a program do? Input  your regex  one or more files  switches For each line in each file, determine whether or not it matches your regex Tell you about it egrep '^[0-9]+\/' epw.cd

6 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 6 Producing output print "hello, world"

7 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 7 Producing output print "hello, world" verb

8 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 8 Producing output print "hello, world" noun (object)

9 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 9 Producing output #!/usr/local/bin/python print "hello, world"

10 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 10 Producing output Filename: helloWorld.py What do the file's permissions need to be?

11 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 11 Producing output babel>python helloWorld.py hello, worldbabel>

12 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 12 Producing output #!/usr/local/bin/python print "hello, world\n"; "escape" character

13 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 13 Producing output \t tab \n "newline"

14 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 14 Comments #1 use for comments: adding notes to yourself/other programmers # the purpose of this program # is to print "hello, world" to # the screen. # author: mpalmer@colorado.edu # 303-492-1300

15 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 15 Comments #!/usr/local/bin/perl # the purpose of this program # is to print "hello, world" to # the screen. # author:mpalmer@colorado.edu # 303-492-1300 # do the actual printing print "hello, world\n" "Commenting" your code

16 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 16 Comments Other use: causing Python to ignore a line # print "hello, world\n"; print "goodbye, cruel world\n"; "Commenting out" a line of code

17 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 17 Comments Own-line or end-of-line formats # print it print "hello, world\n" print "hello, world\n" # print it

18 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 18 Producing output I'd like to print something different every once in a while… $name = “Martha” print name

19 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 19 Variables Name Contents Location in memory

20 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 20 Variables Name ( name ) Contents ( Kinder ) Location in memory ( 13025 ) $name

21 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 21 Using + name = “Martha" print "hello, ” + name

22 LING 5200, 2006 BASED on Kevin Cohen’s LING 5200 22 Python for Linguists http://mime.colorado.edu/~bethard/Pytho n%20for%20Linguists/Python-1.pdf http://mime.colorado.edu/~bethard/Pytho n%20for%20Linguists/Python-1.pdf


Download ppt "1 Introduction to Python LING 5200 Computational Corpus Linguistics Martha Palmer."

Similar presentations


Ads by Google