NLTK python Flashcards

1
Q

find occurrence of a word in context in text1

A

text1.concordance(“word”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

find words that occur in a similar context to a word (spits out a list of words)

A

text1.concordance(“word”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

explore contexts that are shared by 2 or more words in text1

A

text1.common_contexts([“worda”, “wordb”])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

determine the location of a word or set of words in text1

A

text1.dispersion_plot([“worda”, “wordb”, “wordc”])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

generate text in the style of text5

A

text5.generate() note nothing goes between ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

find the length of text5

A

len(text5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

find and display distinct words in a text

A

set(text)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

find and display a sorted list of the distinct types (punctuation), words, and word types (e.g. capitalized) of the text1

A

sorted(set(text1))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

calculate lexical richness of text1 (how often each word is used on avg)

A

> > > from __future__ import division

|&raquo_space;> len(text3) / len(set(text3))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

see how often a word occurs in text3

A

text3.count(“word”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

see what percentage of text5 is taken up by a specific word

A

100 * text5.count(“word”) / len(text5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

write a function for lexical diversity

A

> > > def lexical_diversity(text):

… return len(text) / len(set(text)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

write a function to find the percentage of text made up by a word

A

> > > def percentage(count, total):

… return 100 * count / total

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

count the occurrences of a word in text1

A

text1.count(“word”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

find the index where a the word first occurs in text4

A

text4.index(‘awaken’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

print the first sentence in a body of text as a list

A

sent1

13
Q

get the length of sentence2

A

len(sent2)

14
Q

count the occurrences of a word in text1

A

text1.count(“word”)

15
Q

find the index where a the word first occurs in text4

A

text4.index(‘awaken’)