DOC PREVIEW
Villanova CSC 9010 - Natural Language Processing

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSC 9010: Natural Language ProcessingThis presentation taken partly from: Introduction to Python IWhat is Python?Why Python?Learning PythonPython TutorialsInstalling PythonIDLE Development EnvironmentLook at a sample of code…Slide 10Enough to Understand the CodeBasic DatatypesWhitespaceCommentsSlide 15Python and TypesNaming RulesAccessing Non-existent NameMultiple AssignmentString OperationsPrinting with PythonHands OnAssignment 1, due Jan 27Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt CSC 9010: Natural Language ProcessingPython IntroBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt This presentation taken partly from:Introduction to Python ICSE-391: Artificial IntelligenceUniversity of PennsylvaniaMatt HuenerfauthJanuary 2004Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt What is Python?•A programming language with strong similarities to PERL, but with powerful typing and object oriented features. –Commonly used for producing HTML content on websites. Great for text files.–Useful built-in types (lists, dictionaries).–Clean syntax, powerful extensions.Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Why Python?•Natural Language ToolKit•Ease of use; interpreter•AI Processing: Symbolic–Python’s built-in datatypes for strings, lists, and more. –Java or C++ require the use of special classes for this.•AI Processing: Statistical–Python has strong numeric processing capabilities: matrix operations, etc.–Suitable for probability and machine learning code.Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Learning Python•Unfortunately, we won’t have time to cover all of Python in class; so, we’re just going to go over ome highlights. –You’ll need to learn more on your own. –Homework 0 asks you to install Python or get comfortable using it here in the lab. It also asks you to read some online Python tutorials.–Later homeworks will include Python programming exercises to help you practice.–We will fairly rapidly move to using the Natural Language ToolKit.Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Python TutorialsThings to read through•“Dive into Python” (Chapters 2 to 4)http://diveintopython.org/ •Python 101 – Beginning Pythonhttp://www.rexx.com/~dkuhlman/python_101/python_101.html Things to refer to•The Official Python Tutorialhttp://www.python.org/doc/current/tut/tut.html •The Python Quick Reference http://rgruet.free.fr/PQR2.3.htmlBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Installing Python•Python is installed on the PCs in 156.•Python for Win/Mac/Unix/Linux is available from www.python.org. –Generally an easy install.–On macs, already part of OS X.–For NLTK you need Python 2.3 or higher.•GUI development environment: IDLE.Credits:http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.htmlBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt IDLE Development Environment•Shell for interactive evaluation.•Text editor with color-coding and smart indenting for creating python files.•Menu commands for changing system settings and running files. •We will use IDLE in class.Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Look at a sample of code… x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print yBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Look at a sample of code… x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print yBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Enough to Understand the Code•Assignment uses = and comparison uses ==.•For numbers +-*/% are as expected.–Special use of + for string concatenation.–Special use of % for string formatting.•Logical operators are words (and, or, not) not symbols (&&, ||, !).•The basic printing command is “print.”•First assignment to a variable will create it.–Variable types don’t need to be declared.–Python figures out the variable types on its own.Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Basic Datatypes•Integers (default for numbers)z = 5 / 2 # Answer is 2, integer division.•Floatsx = 3.456•StringsCan use “” or ‘’ to specify. “abc” ‘abc’ (Same thing.)Unmatched ones can occur within the string. “matt’s”Use triple double-quotes for multi-line strings or strings than contain both ‘ and “ inside of them: “““a‘b“c”””Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Whitespace•Whitespace is meaningful in Python: especially indentation and placement of newlines. –Use a newline to end a line of code. (Not a semicolon like in C++ or Java.)(Use \ when must go to next line prematurely.)–No braces { } to mark blocks of code in Python… Use consistent indentation instead. The first line with a new indentation is considered outside of the block.–Often a colon appears at the start of a new block. (We’ll see this later for function and class definitions.)Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Comments•Start comments with # – the rest of line is ignored.•Can include a “documentation string” as the first line of any new function or class that you define.•The development environment, debugger, and other tools use it: it’s good style to include one.def my_function(x, y): “““This is the docstring. This function does blah blah blah.”””# The code would go here...Based on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Look at a sample of code… x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print yBased on presentation from www.cis.upenn.edu/~cse391/cse391_2004/PythonIntro1.ppt Python and TypesPython determines the data types in a program


View Full Document

Villanova CSC 9010 - Natural Language Processing

Documents in this Course
Lecture 2

Lecture 2

48 pages

Lecture 2

Lecture 2

46 pages

Load more
Download Natural Language Processing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Natural Language Processing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Natural Language Processing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?