diff options
Diffstat (limited to 'analyze_new.py')
-rwxr-xr-x[-rw-r--r--] | analyze_new.py | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/analyze_new.py b/analyze_new.py index db066c2..93322c1 100644..100755 --- a/analyze_new.py +++ b/analyze_new.py @@ -3,6 +3,7 @@ import re import operator import itertools import sys +import argparse from pprint import pprint def load_text(n): @@ -10,10 +11,18 @@ def load_text(n): text = f.read() lines = re.split(r'[\?\.\!]+', text) + lines = list(map(lambda l: l.strip(), lines)) lines = list(map(lambda s: s.replace(' ', '').replace('-', ''), lines)) return "\n".join(lines).strip() +def spaceitout(string,amount): + amountint= int(amount) + pile= "" + for char in string: + pile= pile + char + " "*amount + return pile.strip() + def letter_pos(letter): if letter in predefined_table: return predefined_table[letter] @@ -24,12 +33,28 @@ def letter_pos(letter): else: return None +def die(t): + pprint(t) + sys.exit() + +def dump_lines(): + i = 0 + for l in lines: + print('%d ' % i, end='') + print(l) + i += 1 + alphabet = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' +a = spaceitout(alphabet, 1) +a = a.replace(' ', ',') +print(a) +sys.exit() text = '' text += load_text(1) + "\n" +text += load_text(2) + "\n" text += load_text(3) + "\n" -#text += load_text(2) +#text += load_text(4) text = text.upper() predefined_table = { @@ -55,6 +80,9 @@ predefined_table = { table = {} lines = text.split("\n") +#dump_lines() +#sys.exit() + for a in alphabet: table[a] = {} for line in lines: @@ -70,14 +98,13 @@ for a, t in table.items(): ts = sorted(t.items(), key=operator.itemgetter(1), reverse=True) table[a] = ts -#pprint(table['Э']) -#sys.exit() +#die(table) variants = [] for line in lines: valid = [] for a in table: - if True: + if False: index = letter_pos(a) if index == None: continue @@ -88,12 +115,12 @@ for line in lines: except IndexError: continue - if False: + else: letter_table = table[a] if not len(letter_table): continue - for i in range(3): + for i in range(2): if i > len(letter_table)-1: continue @@ -111,12 +138,11 @@ for line in lines: #print('('+''.join(valid)+')') variants = list(filter(lambda a: len(a), variants)) -variants = variants[11:31] - -pprint(variants) -sys.exit() +#variants = list(map(lambda l: sorted(l), variants)) +#die(variants) -#variants = variants[11:] +#variants = variants[63:72] +variants = variants[:7] res = list(itertools.product(*variants)) for r in res: if r[0] == 'Ь': continue |