5.3 Mapping Words to Properties Using Python Dictionaries

As we have seen, a tagged word of the form (word, tag) is an association between a
word and a part-of-speech tag. Once we start doing part-of-speech tagging, we will be
creating programs that assign a tag to a word, the tag which is most likely in a given
context. We can think of this process as mapping from words to tags. The most natural
way to store mappings in Python uses the so-called dictionary data type (also known
as an associative array or hash array in other programming languages). In this sec
tion, we look at dictionaries and see how they can represent a variety of language in
formation, including parts-of-speech.

Indexing Lists Versus Dictionaries
A text, as we have seen, is treated in Python as a list of words. An important property
of lists is that we can “look up” a particular item by giving its index, e.g., text1[100].
Notice how we specify a number and get back a word. In the case of a phonebook, we look up an entry using a name and get back a number.
When we type a domain name in a web browser, the computer looks this up to get
back an IP address. A word frequency table allows us to look up a word and find its
frequency in a text collection. In all these cases, we are mapping from names to num
bers, rather than the other way around as with a list. In general, we would like to be
able to map between arbitrary types of information.

Leave a Reply