forked from jhave/upst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispersions.py
More file actions
31 lines (22 loc) · 813 Bytes
/
dispersions.py
File metadata and controls
31 lines (22 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env python
import nltk
import sys, os
from configparser import SafeConfigParser
# First, let's get input from the user:
word = input("Enter the word for which you would like to see a dispersion graph: ")
# I can't get this to work for multiple words
# words = raw_input().split(",")
# Then we need to transform the base text using a series of steps.
# Get file to use from settings.cfg:
config = SafeConfigParser()
script_dir = os.path.dirname(__file__)
config_file = os.path.join(script_dir, 'settings.cfg')
config.read(config_file)
textfile = config.get('files','full_text')
thefile = open(textfile, 'r')
rawtext = thefile.read()
tokens = nltk.word_tokenize(rawtext)
text = nltk.Text(tokens)
# Now we can actually look at a word:
graphed = text.dispersion_plot([word])
# print(similarwords)