Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 408/508: Computational Techniques for Linguists

Similar presentations


Presentation on theme: "LING 408/508: Computational Techniques for Linguists"— Presentation transcript:

1 LING 408/508: Computational Techniques for Linguists
Lecture 22

2 Administrivia Homework 9 graded Python:
cgi-bin: bash scripting requires attention to detail (unfortunately finicky) that shell script "glue" could access any programming language, e.g. Python Python: from a command line calculator to the Natural Language Toolkit (nltk)

3 Homework 9 Example Use the cgi-bin methods to implement a BMI bash shell script on the webserver.

4 Homework 9 Example

5 Homework 9 Example

6 Next Programming Language
So far, in this course you've been exposed to: Binary language of the CPU: encoding of numbers and characters (unicode) Linux (Ubuntu under VirtualBox) command line: bash shell bash shell scripting: #!/bin/bash awk and regular expressions (regex) html/css Javascript + DOM Web client/server model Now we switch for the rest of the semester to a regular programming course: Python

7 Term Programming Project
It's time to think about the end of the semester … Propose a programming project half of your grade Send your proposal to me If I give up the go-ahead, you can start working on it …

8 Why Python? Installed by default on OSX
but you should install and use python3

9

10 Python on Ubuntu sudo apt install python3-pip

11 Python on Ubuntu

12 Python resources Many (free) online resources Through UA:
1.5hrs (18 Lessons) QuickStart! - Python uickStart!-Python-Tutorials.htm 8hrs (64 Lessons) Practical Python for Beginners Course thon.htm Pythonbook (based on Python 2.7): On course website: pythonbook.pdf

13 Python resources python.org

14 Python At the interpreter:

15 Python: Numbers pythonbook page 53 pythonbook page 54

16 Python: Numbers Python: Javascript: Number data types: int, float
Matters for things like division: / Javascript: everything is a floating point number

17 Python: Numbers import math math.pi complex numbers: import cmath

18 Python range(): produces a list (sequence) range(n) [0,1,..,n-1]
range(start,n) [start,start+1,..,n-1] range(start,n,step) [start,start+step,…,last] last=start+k*step < n range(n,stop,-step) counts down (pythonbook page 40)

19 Python How about to 2 decimal places?
use raw_input() instead of input() for strings eval(raw_input()))is equivalent to input()

20 Formatted Output Lots of ways: (Old way)
Notation comes originally from C : sprintf function

21 Formatted Output %<width>.<precision><type>
<type> = d, f, s <width> = minimum number of characters; right-justified by default, -width => left-justified 0 = as wide as needed <precision> = number of places after decimal point e.g. 02d two digits wide, pad with 0 if needed

22 Formatted Output Newer way:
formatting Use {} for each argument (can be numbered, e.g. {0}, {1},… or referenced by keyword {x}) {:width}

23 Python pythonbook page 60: see factorial.py
Python automatically converts to type long int from int (32 bit 2's complement), (page 64–65, section 3.5) explicit type coercion: float() int() long() complex(r,i) complex numbers complex(string)


Download ppt "LING 408/508: Computational Techniques for Linguists"

Similar presentations


Ads by Google