One of the nice things about Python is that you can type directly into the ** interactive interpreter **.
** Interactive interpreter ** is a code written in a programming language that is translated into machine language by reading one line and executed, and translated by reading one line so that one question is returned when one question is asked. It is a method of sequential translation called execution.
You can access the Python interpreter using a simple graphical interface called the Interactive DeveLopment Environment (** IDLE **). You can find it in Applications → MacPython on Mac and in All Programs → Python on Windows. If you can't run the Python interpreter, it's probably because Python isn't installed correctly. See here for detailed instructions.
The prompt reappears when the interpreter completes the calculation and display of the answer. This means that the Python interpreter is waiting for another instruction. (Prompt means ">")
>>>1 + 5 * 2 - 3
8
>>>
You can use an asterisk (*) for multiplication, a slash (/) for division, and () to enclose the expression in parentheses. The above example shows how to work interactively with the Python interpreter and experiment with different expressions in the language to see how they work.
>>> 1 +
File "<stdin>", line 1
1 +
^
SyntaxError: invalid syntax
>>>
This caused a syntax error. In Python, it doesn't make sense to end an instruction with a plus sign. The Python interpreter indicated the line where the error occurred as ** line 1 **, and the error occurred on the first line. Will tell you.
Now that you have the Python interpreter available, you're ready to start working with your language data.
Before you can proceed further, you need to install NLTK 3.0, which can be downloaded for free from here. Follow the instructions there to download the version you need for your platform.
NLTK is an abbreviation for Natural Language Tool Kit, which is a library implemented in Python for natural language processing. The feature is that you can play with English by default.
After installing NLTK, launch the Python interpreter, enter the following two commands at the Python prompt to install the required data for the book, and select the collection of books as shown in Figure 1.1.
Figure 1.1: Download NLTK Book Collection: Use nltk.download () to browse for available packages. The downloader's Collection tab shows how packages are grouped into sets. You need to select the line labeled Book to get all the data you need for the examples and exercises in this book.
Once the data is downloaded to your PC, you can use the Python interpreter to load some of it. The first step is to enter a special command at the Python prompt.
:from nltk.book import *。
It tells the interpreter to load the text to explore and says "load all items from the NLTK book module". This module contains all the data you need to read this chapter. The command is shown again with the output displayed here. Be careful to get the spelling and punctuation correctly.
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>>
text1: Herman Melville 1851 "Moby Dick" text2: Senses and sensibilities by Jane Austen 1811 text3: Genesis text4: Inaugural Address Corpus text5: Chat Corpus text6: Monty Python and the Holy Grail text7: The Wall Street Journal text8: Personal Corpus text9: Thursday man by G. K. Chesterton 1908
Whenever you want to know about these texts, you can look them up by simply typing their name at the Python prompt.
>>> text1
<Text: Moby Dick by Herman Melville 1851>
>>> text2
<Text: Sense and Sensibility by Jane Austen 1811>
>>>
You can now use the Python interpreter to process some data.
Recommended Posts