Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # corpus_gen_for_my_unique_ML_algorithm.py
- from itertools import combinations, permutations
- from random import randint as rndi, sample, choice, shuffle
- import webbrowser
- import tempfile
- try:
- # Python2
- from Tkinter import *
- from urllib2 import urlopen
- except ImportError:
- # Python3
- from tkinter import *
- from urllib.request import urlopen
- srcfilename=tempfile.mktemp(".txt", "demo_") # .html
- web="""<html>
- <head></head>
- <body>@</body>
- </html>"""
- def index_permu(alist, index):
- alist = alist[:]
- for i in range(len(alist)-1):
- index, j = divmod(index, len(alist)-i)
- alist[i], alist[i+j] = alist[i+j], alist[i]
- return alist
- def back():
- anew()
- r = rndi(0,12**12)
- t = index_permu(list('cdghjkmnopqrsv'), r)
- while aaa:
- aaa.pop()
- aaa.extend(t[:12])
- def seq(zzz, eee=[]):
- back()
- if eee:
- for e in eee:
- k,v = e
- if k == vvv:
- t = choice(arr)
- arr.remove(t)
- aaa[t] = choice(list(v))
- else:
- arr.remove(k)
- if v:
- aaa[k] = choice(v)
- for z in zzz:
- z = ttt[z]
- a = z[rndi(0,len(z)-1)]
- sss = list(a)
- nnn = sample(arr, len(a))
- nnn.sort()
- for t in nnn:
- arr.remove(t)
- aaa[t] = sss.pop(0)
- t = str([yn, ''.join(aaa), ''.join(at)])
- if t in ccc:
- seq(zzz,eee)
- else:
- ccc.append(t) ### at
- print ccc[-1]
- def anew():
- while arr:
- arr.pop()
- arr.extend(list(range(12)))
- aaa = []
- arr = []
- ccc = []
- ttt = {}
- at = ['']
- ttt[0] = [''.join(z) for z in list(permutations('beau', 4))]
- ttt[1] = [''.join(z) for z in list(permutations('beautiful', 9))]
- ttt[2] = sum([[''.join(z) for z in list(permutations('beautiful', i))] for i in [1,2,3,5,6,7,8]], [])
- ttt[3] = 'XX XY XZ YX YY YZ ZX ZY'.split()
- ttt[4] = 'XYX XZX YXY YZY ZXZ ZYZ ZZZ XYZ'.split()
- ttt[5] = 'Y Z ZZ XXX XXY XXZ XYY XZY XZZ YXX YXZ YYX YYY YYZ YZX YZZ ZXX ZXY ZYX ZYY ZZX ZZY'.split() + ['']
- vvv = 'beautiful'
- iii = 200000
- while len(ccc) < iii:
- yn = 1
- seq([0,3])
- seq([0,4],[[9,'X']])
- seq([0,5],[[9,'']])
- seq([1,3])
- seq([2,3])
- seq([2,4])
- ### ------------
- yn = 0
- seq([0,3],[[vvv,'be']])
- seq([0,4],[[9,'']])
- seq([0,5],[[9,'X']])
- seq([1],[[vvv,'be']])
- seq([1,5])
- seq([2,5])
- shuffle(ccc)
- ccc = ['# yn -- combos -- at'] + ccc
- urls='\n'.join(ccc) # <br>
- temp=open(srcfilename, 'w')
- temp.write(urls) # web.replace('@',urls)
- temp.close()
- webbrowser.open_new_tab(srcfilename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement