Mehmet Kuecuek
commited on
Commit
·
e76a6f7
1
Parent(s):
2a9deb7
Upload 8 files
Browse files- barrylyndon.txt +50 -0
- pdf2txt.py +3 -3
- plot.ipynb +0 -0
- plot_freq_saveopt.py +85 -0
- plot_freq_tag.py +76 -0
- plot_tk.py +49 -0
- textconv.ipynb +0 -0
- tokenize.py +7 -0
barrylyndon.txt
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This is the opening monologue of Roderick for testing purposes for tokenization.
|
2 |
+
Source: http://dailyscript.com/scripts/BarryLyndon.html
|
3 |
+
|
4 |
+
My father, who was well-known to the
|
5 |
+
best circles in this kingdom under
|
6 |
+
the name of roaring Harry James, was
|
7 |
+
killed in a duel, when I was fifteen
|
8 |
+
years old.
|
9 |
+
My mother, after her husband's
|
10 |
+
death, and her retirement, lived in
|
11 |
+
such a way as to defy slander. She
|
12 |
+
refused all offers of marriage,
|
13 |
+
declaring that she lived now for her
|
14 |
+
son only, and for the memory of her
|
15 |
+
departed saint.
|
16 |
+
My mother was the most beautiful
|
17 |
+
women of her day. But if she was
|
18 |
+
proud of her beauty, to do her
|
19 |
+
justice, she was still more proud of
|
20 |
+
her son, and has said a thousand
|
21 |
+
times to me that I was the
|
22 |
+
handsomest fellow in the world.
|
23 |
+
The good soul's pleasure was to
|
24 |
+
dress me; and on Sundays and
|
25 |
+
Holidays, I turned out in a velvet
|
26 |
+
coat with a silver-hilted sword by
|
27 |
+
my side, and a gold garter at my
|
28 |
+
knee as fine as any lord in the
|
29 |
+
land. As we walked to church on
|
30 |
+
Sundays, even the most envious souls
|
31 |
+
would allow that there was not a
|
32 |
+
prettier pair in the kingdom.
|
33 |
+
My uncle's family consisted of ten
|
34 |
+
children, and one of them was the
|
35 |
+
cause of all my early troubles; this
|
36 |
+
was the belle of the family, my
|
37 |
+
cousin, Miss Dorothy Dugan, by name.
|
38 |
+
Ah! That first affair, how well one
|
39 |
+
remembers it! What a noble
|
40 |
+
discovery it is that the boy makes
|
41 |
+
when he finds himself actually and
|
42 |
+
truly in love with some one! A lady
|
43 |
+
who is skilled in dancing or singing
|
44 |
+
never can perfect herself without a
|
45 |
+
deal of study in private. So it is
|
46 |
+
with the dear creatures who are
|
47 |
+
skilled in coquetting. Dorothy, for
|
48 |
+
instance, was always practicing, and
|
49 |
+
she would take poor me to rehearse
|
50 |
+
her accomplishments upon...
|
pdf2txt.py
CHANGED
@@ -14,10 +14,10 @@ def pdf_to_txt(pdf_path, txt_path):
|
|
14 |
print("PDF converted to TXT successfully!")
|
15 |
|
16 |
# Specify the path to your PDF file
|
17 |
-
pdf_path = ''
|
18 |
|
19 |
# Specify the path to save the TXT file
|
20 |
-
txt_path = ''
|
21 |
|
22 |
# Call the function to convert PDF to TXT
|
23 |
-
pdf_to_txt(pdf_path, txt_path)
|
|
|
14 |
print("PDF converted to TXT successfully!")
|
15 |
|
16 |
# Specify the path to your PDF file
|
17 |
+
pdf_path = 'path/to/input.pdf'
|
18 |
|
19 |
# Specify the path to save the TXT file
|
20 |
+
txt_path = 'path/to/output.txt'
|
21 |
|
22 |
# Call the function to convert PDF to TXT
|
23 |
+
pdf_to_txt(pdf_path, txt_path)
|
plot.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
plot_freq_saveopt.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# with this code you can tokenize words of screenplays (txt files)
|
2 |
+
# this is not tested yet
|
3 |
+
|
4 |
+
import tkinter as tk
|
5 |
+
from tkinter import filedialog
|
6 |
+
import nltk
|
7 |
+
import pandas as pd
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
from nltk.tokenize import word_tokenize
|
10 |
+
from nltk.probability import FreqDist
|
11 |
+
from nltk.corpus import wordnet
|
12 |
+
|
13 |
+
|
14 |
+
def get_word_type(word):
|
15 |
+
pos_tag = nltk.pos_tag([word])[0][1]
|
16 |
+
word_type = wordnet.synsets(word, pos=get_wordnet_pos(pos_tag))
|
17 |
+
if word_type:
|
18 |
+
return word_type[0].pos()
|
19 |
+
return None
|
20 |
+
|
21 |
+
|
22 |
+
def get_wordnet_pos(treebank_tag):
|
23 |
+
if treebank_tag.startswith('J'):
|
24 |
+
return wordnet.ADJ
|
25 |
+
elif treebank_tag.startswith('V'):
|
26 |
+
return wordnet.VERB
|
27 |
+
elif treebank_tag.startswith('N'):
|
28 |
+
return wordnet.NOUN
|
29 |
+
elif treebank_tag.startswith('P'):
|
30 |
+
return wordnet.PRON
|
31 |
+
else:
|
32 |
+
return None
|
33 |
+
|
34 |
+
|
35 |
+
def process_file(file_path):
|
36 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
37 |
+
text = file.read()
|
38 |
+
|
39 |
+
tokens = word_tokenize(text)
|
40 |
+
fdist = FreqDist(tokens)
|
41 |
+
|
42 |
+
data = {'Word': [], 'Frequency': [], 'Type': []}
|
43 |
+
for word, frequency in fdist.most_common():
|
44 |
+
word_type = get_word_type(word)
|
45 |
+
if word_type:
|
46 |
+
data['Word'].append(word)
|
47 |
+
data['Frequency'].append(frequency)
|
48 |
+
data['Type'].append(word_type)
|
49 |
+
df = pd.DataFrame(data)
|
50 |
+
|
51 |
+
plt.figure(figsize=(10, 6))
|
52 |
+
plt.plot(df['Word'], df['Frequency'])
|
53 |
+
plt.xlabel('Word')
|
54 |
+
plt.ylabel('Frequency')
|
55 |
+
plt.title('Word Frequency Distribution')
|
56 |
+
plt.xticks(rotation=90)
|
57 |
+
plt.tight_layout()
|
58 |
+
|
59 |
+
# Save the plot as a PDF
|
60 |
+
plt.savefig('word_frequency_plot.pdf')
|
61 |
+
plt.close()
|
62 |
+
|
63 |
+
# Save the DataFrame as a PDF
|
64 |
+
df.to_csv('word_frequency_results.csv', index=False)
|
65 |
+
|
66 |
+
print(df)
|
67 |
+
|
68 |
+
|
69 |
+
def browse_file():
|
70 |
+
file_path = filedialog.askopenfilename(filetypes=[('Text Files', '*.txt')])
|
71 |
+
if file_path:
|
72 |
+
process_file(file_path)
|
73 |
+
|
74 |
+
|
75 |
+
# Create the main Tkinter window
|
76 |
+
root = tk.Tk()
|
77 |
+
|
78 |
+
# Create a label and a button in the main window
|
79 |
+
label = tk.Label(root, text="Drag and drop a text file here")
|
80 |
+
label.pack(pady=20)
|
81 |
+
button = tk.Button(root, text="Browse", command=browse_file)
|
82 |
+
button.pack()
|
83 |
+
|
84 |
+
# Run the Tkinter event loop
|
85 |
+
root.mainloop()
|
plot_freq_tag.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tkinter as tk
|
2 |
+
from tkinter import filedialog
|
3 |
+
import nltk
|
4 |
+
import pandas as pd
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
from nltk.tokenize import word_tokenize
|
7 |
+
from nltk.probability import FreqDist
|
8 |
+
from nltk.corpus import wordnet
|
9 |
+
|
10 |
+
|
11 |
+
def get_word_type(word):
|
12 |
+
pos_tag = nltk.pos_tag([word])[0][1]
|
13 |
+
word_type = wordnet.synsets(word, pos=get_wordnet_pos(pos_tag))
|
14 |
+
if word_type:
|
15 |
+
return word_type[0].pos()
|
16 |
+
return None
|
17 |
+
|
18 |
+
|
19 |
+
def get_wordnet_pos(treebank_tag):
|
20 |
+
if treebank_tag.startswith('J'):
|
21 |
+
return wordnet.ADJ
|
22 |
+
elif treebank_tag.startswith('V'):
|
23 |
+
return wordnet.VERB
|
24 |
+
elif treebank_tag.startswith('N'):
|
25 |
+
return wordnet.NOUN
|
26 |
+
elif treebank_tag.startswith('P'):
|
27 |
+
return wordnet.PRON
|
28 |
+
else:
|
29 |
+
return None
|
30 |
+
|
31 |
+
|
32 |
+
def process_file(file_path):
|
33 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
34 |
+
text = file.read()
|
35 |
+
|
36 |
+
tokens = word_tokenize(text)
|
37 |
+
fdist = FreqDist(tokens)
|
38 |
+
|
39 |
+
data = {'Word': [], 'Frequency': [], 'Type': []}
|
40 |
+
for word, frequency in fdist.most_common():
|
41 |
+
word_type = get_word_type(word)
|
42 |
+
if word_type:
|
43 |
+
data['Word'].append(word)
|
44 |
+
data['Frequency'].append(frequency)
|
45 |
+
data['Type'].append(word_type)
|
46 |
+
df = pd.DataFrame(data)
|
47 |
+
|
48 |
+
plt.figure(figsize=(10, 6))
|
49 |
+
plt.plot(df['Word'], df['Frequency'])
|
50 |
+
plt.xlabel('Word')
|
51 |
+
plt.ylabel('Frequency')
|
52 |
+
plt.title('Word Frequency Distribution')
|
53 |
+
plt.xticks(rotation=90)
|
54 |
+
plt.tight_layout()
|
55 |
+
plt.show()
|
56 |
+
|
57 |
+
print(df)
|
58 |
+
|
59 |
+
|
60 |
+
def browse_file():
|
61 |
+
file_path = filedialog.askopenfilename(filetypes=[('Text Files', '*.txt')])
|
62 |
+
if file_path:
|
63 |
+
process_file(file_path)
|
64 |
+
|
65 |
+
|
66 |
+
# Create the main Tkinter window
|
67 |
+
root = tk.Tk()
|
68 |
+
|
69 |
+
# Create a label and a button in the main window
|
70 |
+
label = tk.Label(root, text="Drag and drop a text file here")
|
71 |
+
label.pack(pady=20)
|
72 |
+
button = tk.Button(root, text="Browse", command=browse_file)
|
73 |
+
button.pack()
|
74 |
+
|
75 |
+
# Run the Tkinter event loop
|
76 |
+
root.mainloop()
|
plot_tk.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tkinter as tk
|
2 |
+
from tkinter import filedialog
|
3 |
+
import nltk
|
4 |
+
import pandas as pd
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
from nltk.tokenize import word_tokenize
|
7 |
+
from nltk.probability import FreqDist
|
8 |
+
|
9 |
+
|
10 |
+
def process_file(file_path):
|
11 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
12 |
+
text = file.read()
|
13 |
+
|
14 |
+
tokens = word_tokenize(text)
|
15 |
+
fdist = FreqDist(tokens)
|
16 |
+
|
17 |
+
data = {'Word': [], 'Frequency': []}
|
18 |
+
for word, frequency in fdist.most_common():
|
19 |
+
data['Word'].append(word)
|
20 |
+
data['Frequency'].append(frequency)
|
21 |
+
df = pd.DataFrame(data)
|
22 |
+
|
23 |
+
plt.figure(figsize=(10, 6))
|
24 |
+
plt.plot(df['Word'], df['Frequency'])
|
25 |
+
plt.xlabel('Word')
|
26 |
+
plt.ylabel('Frequency')
|
27 |
+
plt.title('Word Frequency Distribution')
|
28 |
+
plt.xticks(rotation=90)
|
29 |
+
plt.tight_layout()
|
30 |
+
plt.show()
|
31 |
+
|
32 |
+
|
33 |
+
def browse_file():
|
34 |
+
file_path = filedialog.askopenfilename(filetypes=[('Text Files', '*.txt')])
|
35 |
+
if file_path:
|
36 |
+
process_file(file_path)
|
37 |
+
|
38 |
+
|
39 |
+
# Create the main Tkinter window
|
40 |
+
root = tk.Tk()
|
41 |
+
|
42 |
+
# Create a label and a button in the main window
|
43 |
+
label = tk.Label(root, text="Drag and drop a text file here")
|
44 |
+
label.pack(pady=20)
|
45 |
+
button = tk.Button(root, text="Browse", command=browse_file)
|
46 |
+
button.pack()
|
47 |
+
|
48 |
+
# Run the Tkinter event loop
|
49 |
+
root.mainloop()
|
textconv.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
tokenize.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import nltk
|
2 |
+
|
3 |
+
text = "James rides a bicycle"
|
4 |
+
tokens = nltk.word_tokenize(text)
|
5 |
+
ps_tags = nltk.pos_tag(tokens)
|
6 |
+
|
7 |
+
print(pos_tags)
|