# File stringDemo2.py
# Author: G.Doeben-Henisch
# First date: July 19, 2019
'''
ACTOR STORY
1. There is a user (as executive actor) who can enter single or multiple words into the input interface of an assisting interface.
2. After confirming the input the assisting actor will respond in a creative manner. These creativity is manifested in changed orders of symbols and words as well as by replaced symbols.
3. After the response the user can either repeat the sequence or he can stop. If repeating then he can select between two options: (i) enter manually new words as input or (ii) redirect the output of the system as new input. This allows a continuous creative change of the words.
4. The repeated re-direction offers again two options: (i) Closed world; no real input; (ii) Open world; some real new input
'''
############################
# IMPORTS
import random as rnd
############################
# SUPPORTING FUNCTION
#
# re-order the sequence of words in a word-sequence -> sqorder()
def sqorder(w):
wl = w.split() # list() method would split the words into single letters
print('List version of sqorder input =\n',wl)
wll=[]
n=len(wl)
for i in range(n):
r=rnd.randrange(0,n)
wll.append(wl[r])
wnew=''
for i in range(n):
wnew=wnew+' '+wll[i]
print('New word order in sequence with sqorder(): \n',wnew)
return wnew
# re-order the sequence of symbols in a word w -> worder()
def worder(w):
wl = list(w)
wll=[]
n=len(wl)
for i in range(n):
r=rnd.randrange(0,n)
wll.append(wl[r])
wnew=''
for i in range(n):
wnew=wnew+wll[i]
print('New in-word order with worder():\n ',wnew)
return wnew
# multiple re-order of single words in closed world ->mcworder()
def mcworder(w):
wl = w.split() # list() method would split the words into single letters
print('List version of input in mcworder()=\n',wl)
n=len(wl) # number of words!
wn=''
for i in range(n):
wnn=''
wnn=wnn+wl[i] # Make single word string
wn=wn+' '+worder(wnn) # Make word sequence with processing new word
print('New word-sequence order :\n ',wn)
return wn
# multiple re-order of single words in open world->moworder()
def moworder(w):
wl = w.split() # list() method would split the words into single letters
print('List version of input in moworder()=\n',wl)
n=len(wl) # number of words!
wn=''
for i in range(n):
wnn=''
wnn=wnn+wl[i] # Make single word string
wnn=wreplace(wnn)
wn=wn+' '+worder(wnn) # Make word sequence with processing new word
print('New word-sequence order :\n ',wn)
return wn
# select randomly a new lower case letter and replace a given letter by this new one
def wreplace(w):
# Get randomly a new lower case letter
coderange=[97,122]
letter=chr(rnd.randrange(coderange[0],coderange[1]+1))
# Insert new letter randomly in given list of letters
wl = list(w)
n=len(wl)
r=rnd.randrange(0,n)
wl[r]=letter
wnew=''
for i in range(n):
wnew=wnew+wl[i]
print('New word with new letter : ',wnew)
return wnew
##########################
# Main Programm
###############
# Start main loop
#
# The loop will work as long as the value of the variable 'loop' is different to 'N'
loop='Y'
while loop!='N':
###################
# The user is invited to give some ordering decisions:
# 'Closed' world means that the set of participating letters will not be expanded
# 'Open' world means that the set of participating letters will be expanded
opt=input("Single word = '1' or Multiple words = '2'\n")
opt2=input("New manual input ='1' or Redirect the last output = '2'\n")
opt3=input("Closed world ='1' or Open world ='2'\n")
if opt=='1' and opt2=='1' and opt3=='1':
w1=input('Input a single word\n')
print('Your input word is =',w1)
# Here you need a function which
# (i) re-orders the sequence of symbols in the word -> worder()
wnew=worder(w1)
# (ii) replaces a symbol by some randomly selected new one -> wreplace()
# wcreative() = worder() ^ wreplace()
elif opt=='1' and opt2=='2' and opt3=='1':
print('The last output was =',wnew)
# Here you need a function which
# (i) re-orders the sequence of symbols in the word -> worder()
wnew=worder(wnew)
elif opt=='1' and opt2=='2' and opt3=='2':
print('The last output was =',wnew)
# Here you need a function which
# (i) re-orders the sequence of symbols in the word -> worder()
wnew=worder(wnew)
# (ii) replaces a symbol by some randomly selected new one -> wreplace()
wnew=wreplace(wnew)
# wcreative() = worder() ^ wreplace()
elif opt=='2' and opt2=='1' and opt3=='1':
w1=input('Input multiple words\n')
print('Your input words are =',w1)
# Here you need a function which
# (i) re-orders the sequence of words -> sqorder()
wnew=sqorder(w1)
# (ii) reorder the symbols in each word -> mcworder()
wnew=mcworder(wnew)
# (iii) replace in each word randomly a symbol -> wreplace()
# sqcreative() = sqorder ^ wcreative()
elif opt=='2' and opt=='2' and opt3=='1':
print('The last output was =',wnew)
# Here you need a function which
# (i) re-orders the sequence of words in the word-sequence -> sqorder()
wnew=sqorder(wnew )
# (ii) reorder the symbols in each word -> mcworder()
wnew=mcworder(wnew)
elif opt=='2' and opt=='2' and opt3=='2':
print('The last output was =',wnew)
# Here you need a function which
# (i) re-orders the sequence of words in the word-sequence -> sqorder()
wnew=sqorder(wnew )
# (ii) reorder the symbols in each word -> moworder()
wnew=moworder(wnew)
# Clarify how to continue
loop=input("STOP = 'N', CONTINUE != 'N' \n")