-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposChainer.py
More file actions
52 lines (47 loc) · 2.12 KB
/
posChainer.py
File metadata and controls
52 lines (47 loc) · 2.12 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
import random
#makes repetition-many chains with the sectiondepths,
def goChainPOS(sectiondepths, dicts, repetition):
result = ''
#split title and the chains by a linebreak
for i in range(repetition):
results = mkPOSchain(sectiondepths, dicts)
result += results[0]
result += "\n"
result += results[1]
result += "\n"
return result #make the chain, returns string
def mkPOSchain(depths, dicts):
sectionLists = []
for sectionIterator in range(
len(depths)
): #there are possibly different sections (as of right now there are two)
currentChainDepth = depths[sectionIterator]
currentChain = dicts[
sectionIterator] #for different sections there are different chainpieces
currentString = ['$START$'] * currentChainDepth #start
#we need a start variable for the chain; it is defined as ['£$', 'START']
nextWord = ['$START$', 'START']
while True:
#find next possible words according to previous and the type for the next word described by the last word.
nextChoices = currentChain[tuple((tuple(
([currentString[-r] for r in range(1, currentChainDepth + 1)])),
nextWord[1]))]
nextWord = nextChoices[random.randrange(
len(nextChoices))] #randomly choose one of the choices
if nextWord[0] == '$END$': #end signal
break
else:
currentString.append(nextWord[0]) #append it to the end
#currentString now looks pretty bad
currentOutput = ''
for word in currentString[(
currentChainDepth +
1):]: #up to currentChainDepth+1 it is just start
if word[0].isalpha() or word[0].isdigit():
currentOutput += ' ' + word
else: #if it is only ,.;'
currentOutput += word
sectionLists.append(
currentOutput) #append sectionoutput to combination of others
print('€@' + str(sectionIterator) + ': ' + currentOutput)
return sectionLists