-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
106 lines (92 loc) · 2.92 KB
/
main.py
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
99
100
101
102
103
104
105
106
from jesse import *
import settings
'''
The main routine is in main(filename), the first defined function.
In makeWords function, I make each word into a dict that consists
of (see jesse.py):
word -- the word
low -- int minimum syllable count for the word
high -- int maximum syllable count for the word
repl -- bool whether a character replacement was made
maybe this should include what was replaced
inDict -- if word is in cmuDict
'''
## main
def main(filename):
'''
Main routine. Input is string filename (defined at call)
or the default: "sample.txt"
'''
printBlank(1, 'entering main') ## debug
poem = [] #the poem, by line, will go here
poem = openFile(poem, filename)
metadata = {'title': "", 'author': "", 'date': "", 'nation': ""}
getMetadata(poem, metadata)
outputMetadata(metadata)
poem = makeWords(poem)
prettyOutput(poem,noteDictionary=True)
beginStress(poem)
def outputMetadata(metadata):
print "title | ", metadata['title']
print "author| ", metadata['author']
print "date | ", metadata['date']
print "nation| ", metadata['nation']
def getMetadata(poem, metadata):
'''
Gets metadata information from first four lines of the poem
then removes those four lines from the list (poem)
'''
for word in poem[0]:
metadata['title'] += word
metadata['title'] += " "
for word in poem[1]:
metadata['author'] += word
metadata['author'] += " "
for word in poem[2]:
metadata['date'] += word
for word in poem[3]:
metadata['nation'] += word
for x in range(4): ## delete first four lines of the list/poem
del poem[0]
def beginStress(poem):
'''
Called w/ poem.
Calls syllableMajority, createStressArray, printStress...
lineLen: count of lines w/ syllable_slot (from lineMajority)
freqLineLen: syllable_slot (from lineMajority)
'''
createStressArray(poem)
# printStress(poem)
lineCounts = syllableMajority(poem)
print " ", "LineCounts: ",lineCounts
lineLen, freqLineLen = lineMajority(lineCounts)
print " ","Most frequent syllable count: ", freqLineLen, " appears: ", lineLen
finalScores = buildFullArray(poem, freqLineLen)
checkForms(finalScores)
def generateForms(maximum, forms):
# we want feet, not syllables
feet = maximum / 2
# don't forget needa adjust for 3-syl feet
forms['pyrrhic'] = PYRRHUS*feet
forms['iambic'] = IAMB*feet
forms['trochaic'] = TROCHEE*feet
forms['spondaic'] = SPONDEE*feet
forms['tribrachiac'] = TRIBRACH*feet
forms['dactylic'] = DACTYL*feet
forms['amphibrachiac'] = AMPHIBRACH*feet
forms['anapestic'] = ANAPEST*feet
forms['bacchiac'] = BACCHIUS*feet
forms['antibacchiac'] = ANTIBACCHIUS*feet
forms['creticac'] = CRETIC*feet
forms['molossusiac'] = MOLOSSUS*feet
if ((maximum % 2) == 1):
for key in forms:
forms[key].append(-1)
## main
if __name__ == '__main__':
if len(sys.argv) < 2:
filename = 'sample.txt'
elif len(sys.argv) >= 2:
filename = sys.argv[1]
print '*** Using ', filename, ' ***'
sys.exit(main(filename))