daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 67 in 338 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import functions as fun
  3.  
  4. def syllables(word,sn):
  5.     vowels = 'уеыаоэяиюё'
  6.     letters = 'йрлмн'
  7.     stroka = word.text
  8.     lemm = word.lem
  9.     if (len([v for v in stroka if v in vowels])>sn) and fun.check_min(lemm, 'B2') and ('-' not in stroka):
  10.         #берем те, в которых больше x слогов и есть в минимуме
  11.         #print(word)
  12.         n = 0
  13.         sillabs = ''
  14.         for i in range(len(stroka[::-1])):
  15.             if stroka[i] in vowels:
  16.                 sillabs += stroka[n:i]+stroka[i]+'-'
  17.                 #print(sillabs)
  18.                 n = i+ 1
  19.                 vowind = i
  20.             else:
  21.                 if i == len(stroka)-1:
  22.                     sillabs = sillabs[:-1]+stroka[n:]+'-'
  23.         #выравнивание слогоделения для закрытых слогов в середине слова
  24.         #print(sillabs)
  25.         m = 0
  26.         newsillabs = ''
  27.         for j in range(len(sillabs)):
  28.             if ((sillabs[j] in letters) and (sillabs[j-1] == '-') and (sillabs[j+1] not in vowels) and (sillabs[j+1] not in letters) and (sillabs[j+1] != 'ь')):
  29.                 newsillabs = newsillabs+sillabs[m:j-1]+sillabs[j]+'-'+sillabs[j+1:]
  30.                 m = j+1
  31.             if (((sillabs[j] == 'ь') and (sillabs[j-1] in letters)) and (sillabs[j-2] == '-')):
  32.                 newsillabs = newsillabs+sillabs[m:j-2]+sillabs[j-1:j+1]+'-'+sillabs[j+1:]
  33.                 m = j+1
  34.         if newsillabs == '':
  35.             newsillabs = sillabs
  36.         #print(newsillabs[:-1])
  37.        
  38.         split_word = newsillabs[:-1].split('-') #готовый список слогов
  39.        
  40.         shuf_w = split_word[:]
  41.         random.shuffle(shuf_w)
  42.         while shuf_w==split_word: #мешаем слоги так, чтобы точно изменился порядок
  43.           random.shuffle(shuf_w)
  44.          
  45.         shuf_w = '['+''.join(shuf_w)+']' #слово внутри задания
  46.         key_w = '['+strokat+']' #слово внутри ключей - тоже в скобочках, но в верном порядке
  47.        
  48.         shuf_w_token = fun.Token(shuf_w)
  49.         key_w_token = fun.Token(key_w)
  50.        
  51.         return shuf_w_token, key_w_token
  52.     else:
  53.         return word, word
  54.  
  55.  
  56. def make_shuf_sents(old_words):
  57.     shuf_words = ['']*len(old_words)
  58.     key_words = shuf_words[:]
  59.    
  60.     for i, w in enumerate(old_words):
  61.         shuf_words[i], key_words[i] = syllables(w, 2)
  62.    
  63.     return shuf_words,key_words #списки токенов в предложении
  64.  
  65.  
  66. text = fun.reading("6")
  67. sentences = fun.sts(text)
  68. tokens = fun.tkns(sentences)
  69.  
  70. shuf_sents, key_sents = [], []
  71. for sentence in tokens:
  72.     shuf_words, key_words = make_shuf_sents(sentence)
  73.     shuf_sents.append(shuf_words)
  74.     key_sents.append(key_words)
  75. print (join_toks(shuf_words))
  76. print (join_toks(key_words))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top