Computation with strings 2 Day 3 - 9/02/16

Slides:



Advertisements
Similar presentations
4.01 How Web Pages Work.
Advertisements

XP 1 Developing a Basic Web Site Tutorial 2: Web Site Structures & Links.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
XP Browser and Basics1. XP Browser and Basics2 Learn about Web browser software and Web pages The Web is a collection of files that reside.
CIS101 Introduction to Computing
Topics in this presentation: The Web and how it works Difference between Web pages and web sites Web browsers and Web servers HTML purpose and structure.
WWW and Internet The Internet Creation of the Web Languages for document description Active web pages.
Creating your website Using Plain HTML. What is HTML? ► Web pages are authored in HyperText Markup Language (HTML) ► Plain text is marked up with tags,
Basics Dayton Metro Library Place photo here August 10, 2015.
Syllabus outcomes Describes and applies problem-solving processes when creating solutions Designs, produces and evaluates appropriate solutions.
1 Chapter 2 & Chapter 4 §Browsers. 2 Terms §Software §Program §Application.
COMPUTATION WITH STRINGS 4 DAY 5 - 9/05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
ON-LINE DOCUMENTS 3 DAY /17/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Developing a Web Site. Web Site Navigational Structures A storyboard is a diagram of a Web site’s structure, showing all the pages in the site and indicating.
COMPUTATION WITH STRINGS 2 DAY 2 - 8/29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
SCRIPTS & FUNCTIONS DAY /06/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Using the Internet. (WWW) and the Internet The World Wide Web (WWW) is a small part of the Internet. The Internet relates to all the hardware and software.
TWITTER 2 DAY /10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
WEB TEXT DAY /14/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
XP 1 HTML Tutorial 2: Developing a Basic Web Site.
REGULAR EXPRESSIONS 3 DAY 8 - 9/12/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.
Chapter 4 Applets Cop Why Applets? WWW makes huge information available to anyone with web browser. Web server send web pages and images to your.
REGULAR EXPRESSIONS 1 DAY 6 - 9/08/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
The World Wide Web. What is the worldwide web? The content of the worldwide web is held on individual pages which are gathered together to form websites.
1 More About HTML Images and Links. 22 Objectives You will be able to Include images in your HTML page. Create links to other pages on your HTML page.
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.
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Introduction to HTML 4.0 Getting Started – Basic Terminology Teacher: Mr. Ho.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Web Page Design The Basics. The Web Page A document (file) created using the HTML scripting language. A document (file) created using the HTML scripting.
World Wide Web. The World Wide Web is a system of interlinked hypertext documents accessed via the Internet The World Wide Web is a system of interlinked.
Basic Internet Skills. What is the internet? A large group of computers connected to one another Its purpose is to send information back and forth to.
4.01 How Web Pages Work.
4.01 How Web Pages Work.
4.01 How Web Pages Work.
Lists 1 Day /17/14 LING 3820 & 6820 Natural Language Processing
Lists 2 Day /19/14 LING 3820 & 6820 Natural Language Processing
Flat text Day 6 - 9/12/16 LING 3820 & 6820 Natural Language Processing
Some bits on how it works
Some Common Terms The Internet is a network of computers spanning the globe. It is also called the World Wide Web. World Wide Web It is a collection of.
Introduction to Scripting
Flat text 2 Day 7 - 9/14/16 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Flat text 3 Day 8 - 9/16/16 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Web page a hypertext document connected to the World Wide Web.
Computation with strings 3 Day 4 - 9/07/16
Intro to PHP & Variables
Computation with strings 1 Day 2 - 8/31/16
Chapter 27 WWW and HTTP.
Regular expressions 2 Day /23/16
CNIT 131 HTML5 – Anchor/Link.
Basic Protocols 24-Nov-18.
control 4 Day /01/14 LING 3820 & 6820 Natural Language Processing
LING 3820 & 6820 Natural Language Processing Harry Howard
Control 3 Day /05/16 LING 3820 & 6820 Natural Language Processing
NLP 2 Day /07/16 LING 3820 & 6820 Natural Language Processing
Web DB Programming: PHP
Regular expressions 3 Day /26/16
CS1110 Today: collections.
Computation with strings 4 Day 5 - 9/09/16
Exploring Web Page Design
4.01 How Web Pages Work.
4.01 How Web Pages Work.
The Internet and Electronic mail
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Presentation transcript:

Computation with strings 2 Day 3 - 9/02/16 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Course organization http://www.tulane.edu/~howard/NLP/ 1.1.7. Schedule of assignments Is there anyone here that wasn't here on Monday? NLP, Prof. Howard, Tulane University 02-Sep-2016

Computer hygiene Refresh your browser! http://nomorehairloss.org/wp-content/uploads/2014/06/Hygiene.jpg NLP, Prof. Howard, Tulane University 02-Sep-2016

Scripts for the example code 2.2.5. How to use a script in Spyder NLP, Prof. Howard, Tulane University 02-Sep-2016

There are two, so far 4.1. How to create a string Note: The code for this and the next section can be downloaded as this script nlp4sec1-2.py, presumably to your Downloads folder, and then moved to pyScipts, from whence you can open it in Spyder and run each line one by one. 4.3. How to find your way around a string Note: The code for this section is found at nlp4sec3.py. NLP, Prof. Howard, Tulane University 02-Sep-2016

§4. Computation with strings What is a string? A string is a sequence of characters delimited between single or double quotes. NLP, Prof. Howard, Tulane University 02-Sep-2016

Changes to text NLP, Prof. Howard, Tulane University 02-Sep-2016

4.1.2. Object type >>> type('one') == type(1) >>> str(1) >>> str(1.0) >>> '1' == str(1) >>> '1.0' == str(1.0) >>> type('1') == type(str(1)) >>> type('1.0') == type(str(1.0)) >>> int('1') >>> float('1.0') >>> 1 == int('1') >>> 1.0 == float('1.0') >>> type(1) == type(int('1')) >>> type(1.0) == type(float('1.0')) NLP, Prof. Howard, Tulane University 02-Sep-2016

4.2.5. Practice 1 1. What types are output by len(), sort(), and set()? >>> B = 'balloon' >>> type(len(B)) <type 'int'> >>> type(sorted(B)) <type 'list'> >>> type(set(B)) <type 'set'> NLP, Prof. Howard, Tulane University 02-Sep-2016

4.2.5. Practice 1, cont. 2. Write the code to perform the changes given below on these two strings: >>> S = 'ABCDEFGH' >>> s = 'abcdefgh' a. Extract the first 3 characters of S and make them lowercase. >>> S.strip('DEFGH').lower() b. Extract the last 4 characters of s and make them uppercase. >>> s.strip('abcd').upper() c. Create a string from the first 4 characters of S and the last 4 characters of s and then switch its case. >>> S.strip('EFGH')+s.strip('abcd').swapcase() 'ABCDEFGH' >>> (S.strip('EFGH')+s.strip('abcd')).swapcase() NLP, Prof. Howard, Tulane University 02-Sep-2016

4.2.5. Practice 1, cont. 3. Here are two real life strings to work with: >>> mail = 'howard@tulane.edu' >>> url = 'http://www.tulane.edu/~howard/NLP/' a. How would you strip out the user name and the server name from my email address? >>> mail.strip('@tulane.edu') >>> 'howar' >>> mail.strip('tulane.edu').strip('@') b. Internet addresses start with the transfer protocol that the site uses. For web pages, this is usually the hypertext transfer protocol, http. How would you strip this information out to leave just the address of the book? >>> url.strip('http://') c. Following up on (b), how would you extract just Tulane’s server address? >>> url.lstrip('http://').rstrip('/~howard/NLP') NLP, Prof. Howard, Tulane University 02-Sep-2016

4.2.5. Practice 1, cont. Now we mix types: >>> day = 1 >>> month = 'Sept' >>> year = 2016 Concatenate them into the string ‘Sept. 1, 2016’. >>> month+'. '+str(day)+', '+str(year) Then split the string ‘Nov. 1, 1957’ into its three parts. >>> date = 'Nov. 1, 1957' >>> m = date.strip('. 1, 1957') >>> d = int(date.strip('Nov.').strip('1957').strip().strip(',')) >>> y = int(date.strip('Nov. 1').strip(',').strip()) NLP, Prof. Howard, Tulane University 02-Sep-2016

In a picture NLP, Prof. Howard, Tulane University 02-Sep-2016

4.3.1.3. How to slice a string >>> E[0:3] >>> E[1:4] NLP, Prof. Howard, Tulane University 02-Sep-2016

4.3.4. Practice 2 1. Write the code to perform the changes given below on these two strings, but try to using slicing rather than stripping: >>> S = 'ABCDEFGH' >>> s = 'abcdefgh' a. Make the first 3 characters of S lowercase. >>> S[:3].lower() b. Make the last 4 characters of s uppercase. >>> s[4:].upper() c. Create a string from the first 4 characters of S and the last 4 characters of s and then switch its case. >>> S[:4]+s[4:].swapcase()' 'ABCDEFGH' >>> (S[:4]+s[4:]).swapcase() 'abcdEFGH' d. Concatenate both strings and slice out every even character. >>> (S+s)[1::2] e. Concatenate both strings and reverse the order of the characters. >>> (S+s)[::-1] f. Retrieve the index of ‘E’ and ‘h’. >>> S.index('e') >>> s.index('h') NLP, Prof. Howard, Tulane University 02-Sep-2016

Others 4.3.4. Practice 2 NLP, Prof. Howard, Tulane University 02-Sep-2016

Next time §4. practices 3, 4, 5, 6, 7 -- not all of which are finished yet. NLP, Prof. Howard, Tulane University 02-Sep-2016