# automatically generates sentences based on source words
# from output_shortlist.txt
# with a=action (verb), d=descriptor (adjective/adverb), t=thing (noun/pronoun), c=connector (preposition)

import random

filename1 = 'output_shortlist.txt'

# get lines of file into a list:
with open(filename1,'r') as f1:
    data = f1.readlines()

def getWord(wordType='d'):
    global data # needed to access data without constantly re-getting data first
    
    if wordType!='c':
        i = random.randrange(0,len(data))
        label = data[i].split(',')[-1].strip() # need .strip() to remove whitespace character(s)
        while label != wordType:
            i = random.randrange(0,len(data))
            label = data[i].split(',')[-1].strip() # need .strip() to remove whitespace character(s)
        word = data[i].split(',')[0]
        translation = data[i].split(',')[1]
    elif wordType=='c':
        connectorIndices = [7,8,231,232,233,234,235,236]
        i = random.choice(connectorIndices)
        word = data[i].split(',')[0]
        translation = data[i].split(',')[1]
    
    return word, translation

def buildSentence(pattern):
    sentence = ''
    translation = ''
    for letter in pattern:
        newword, newwordtrans = getWord(wordType=letter)
        sentence += newword + ' '
        translation += newwordtrans + ' '
    # remove last space, capitalize first letter, add period at end:
    sentence, translation = sentence.rstrip().capitalize()+'.', translation.rstrip().capitalize()+'.'
    return sentence, translation




# if this .py file is being run as a standalone by the user:
if __name__ == '__main__':
    print('')
    print('WARNING: Words are chosen at random within word types and may produce unexpected sentences.')
    print('')
    
    pattern = 'tat'
    print('AUTO-GENERATED SENTENCE 1: ***1***, with pattern "'+pattern+'"')
    sentence, translation = buildSentence(pattern)
    print(sentence)
    print(translation)
    
    print('')
    
    pattern = 'tact'
    print('AUTO-GENERATED SENTENCE 2: ***2***, with pattern "'+pattern+'"')
    sentence, translation = buildSentence(pattern)
    print(sentence)
    print(translation)
    
    print('')
    
    pattern = 'dtadtcdt'
    print('AUTO-GENERATED SENTENCE 3: ***3***, with pattern "'+pattern+'"')
    sentence, translation = buildSentence(pattern)
    print(sentence)
    print(translation)
    
    print('')
@@ -330,16 +330,397 @@
 ines()%0A%0A
+def justTwoInitSylls(word):%0A    for vowel1 in word:%0A        if vowel1 in 'aeiou':%0A            afterThisIndex = word.index(vowel1)%0A            break%0A    for vowel2 in word%5BafterThisIndex+1:%5D:%0A        if vowel2 in 'aeiou':%0A            beforeThisIndex = word%5BafterThisIndex+1:%5D.index(vowel2)+1 + afterThisIndex+1%0A            break%0A    word = word%5B:beforeThisIndex+1%5D%0A    return word%0A%0A
 def getW
@@ -735,16 +735,26 @@
 Type='d'
+,full=True
 ):%0A    g
@@ -1457,24 +1457,83 @@
 plit(',')%5B1%5D
+%0A%0A    if full==False:%0A        word = justTwoInitSylls(word)
 %0A    %0A    re
@@ -1581,16 +1581,26 @@
 (pattern
+,full=True
 ):%0A    s
@@ -1715,16 +1715,26 @@
 e=letter
+,full=full
 )%0A      
@@ -2322,32 +2322,33 @@
 rn %22'+pattern+'%22
+:
 ')%0A    sentence,
@@ -2375,32 +2375,38 @@
 Sentence(pattern
+,False
 )%0A    print(sent
@@ -2544,32 +2544,33 @@
 rn %22'+pattern+'%22
+:
 ')%0A    sentence,
@@ -2597,32 +2597,38 @@
 Sentence(pattern
+,False
 )%0A    print(sent
@@ -2778,16 +2778,17 @@
 ttern+'%22
+:
 ')%0A    s
@@ -2831,16 +2831,257 @@
 (pattern
+,False)%0A    print(sentence)%0A    print(translation)%0A    %0A    print('')%0A    %0A    pattern = 'tat'%0A    print('AUTO-GENERATED SENTENCE 4: ***1***, with pattern %22'+pattern+'%22 and full words:')%0A    sentence, translation = buildSentence(pattern,True
 )%0A    pr

use 2 init syllables by id'ing 2 vowels