-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_poetry_code
More file actions
98 lines (79 loc) · 2.74 KB
/
python_poetry_code
File metadata and controls
98 lines (79 loc) · 2.74 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import random
from textblob import TextBlob
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
with open ('/content/drive/MyDrive/Creative Coding/DorianGray.txt') as f:
gray_text = f.read()
gray_blob = TextBlob(gray_text)
poem_text = """
The stars in the sky
In vain
The tragedy of Hamlet
In vain
The key in the lock
In vain
The sleeping mother
In vain
The lamp in the corner
In vain
The lamp in the corner unlit
In vain
Abraham Lincoln
In vain
The Aztec empire
In vain
The writing hand: in vain
(The shoetrees in the shoes
In vain
The windowshade string upon
the hand bible
In vain—
The glitter of the greenglass
ashtray
In vain
The bear in the woods
In vain
The Life of Buddha
In vain)
"""
poem_blob = TextBlob(poem_text)
poem_blob.tags
singular_nouns = []
plural_nouns = []
adjectives = []
for word,pos in gray_blob.tags:
if(pos == 'NN'):
singular_nouns.append(word)
if(pos == 'NNS'):
plural_nouns.append(word)
if(pos == 'JJ'):
adjectives.append(word)
random.choice(plural_nouns)
print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print("In vain")
print("The " + random.choice(singular_nouns) + " of " + random.choice(singular_nouns))
print(" " + "In vain")
print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + "In vain")
print("The " + random.choice(adjectives) + " " + random.choice(plural_nouns))
print(" " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " in the corner")
print(" " + " " + " " + " " + "In vain")
print(random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(plural_nouns) + " hand: in vain")
print("(The " + random.choice(plural_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " " + random.choice(adjectives) + " upon")
print(" " + " " + " " + " " + " " + "the " + random.choice(adjectives) + " " + random.choice(singular_nouns))
print(" " + "In vain—")
print("The " + random.choice(adjectives) + " of the " + random.choice(adjectives))
print(" " + " " + " " + " " + " " + random.choice(plural_nouns))
print("In vain")
print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " of " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain)")