Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 388: Computers and Language

Similar presentations


Presentation on theme: "LING 388: Computers and Language"— Presentation transcript:

1 LING 388: Computers and Language
Lecture 9

2 Administrivia Reminder: next week TA Patricia Lee will lead the class
Lecture 8 slides updated with examples from last class Today topic: file handling

3 Python: Files Like all other programming languages, uses a file handle, called file variable: open() infile = open("file.txt","r") outfile = open("results.txt,"w")

4 Python: Files writing-files

5 Sample text file Course webpage: falconheavylaunch.txt
environment Course webpage: falconheavylaunch.txt

6 Class Exercise Download falconheavylaunch.txt to your computer.
Answer the following questions. How many characters are there in the article? How many lines of text are there in the article? How many lines excluding blank lines? How many words are there in the article? How many characters per word? What are the most common words? Recall from lecture 7: from collections import Counter c = Counter() c.most_common()

7 Answers to class exercise

8 Class Example: Questions 1 and 2

9 Class Example: Question 3

10 Class Example: Question 4

11 Class Example: Question 5
4.88 characters per word

12 Class Example: Question 6
Closed class items only in most common 10. First open class items to appear are: rocket, Falcon, Jeavy, aircraft, Elon Recall text summarizati on?

13 Python: Files Writing (assuming you've opened a file for writing):

14 Python: json JSON = JavaScript Object Notation
Saving structured data with json ml#module-json

15 Class Example: Python: json
Explanation: we loaded it back in as a dict. most_common() is a method of Counter


Download ppt "LING 388: Computers and Language"

Similar presentations


Ads by Google