mirror of
https://github.com/Oreolek/Togataltu.git
synced 2024-05-19 17:38:20 +03:00
Поиск рифм.
This commit is contained in:
parent
6058c05e18
commit
ab417a7860
|
@ -11,7 +11,7 @@ end
|
|||
#$source = Source.new("Dankon pro la mondkreintoj\nkiuj per heroestimo\ndonos al ni pliegigon\nlaux verkitaj plimensiloj.",@log)
|
||||
$source = Source.new("I ásked no óther thing,\nNo óther was deníed.\nI óffered Béing for it;\nThe míghty mérchant smíled.",@log)#Эмили Дикинсон
|
||||
#заметьте: в слове denied ударение на второй слог, в слове offered — на первый
|
||||
#$source.find_rhymes()
|
||||
$source.find_rhymes()
|
||||
$source.replace()
|
||||
result = $source.translate()
|
||||
if result != false then
|
||||
|
|
22
source.rb
22
source.rb
|
@ -32,18 +32,20 @@ class Source
|
|||
end #@text.each_line
|
||||
end
|
||||
def find_rhymes()
|
||||
last_words = Array.new
|
||||
this_line_number = 0
|
||||
@text.each_line do |line|
|
||||
last_words << line[/([abcdefghijklmnopqrstuvwxyzáéíóúý]+\s[abcdefghijklmnopqrstuvwxyzáéíóúý]+)\W*$/, 1] #массив двух последних слов строк
|
||||
end
|
||||
last_words.each_with_index do |word, word_index|
|
||||
current_vowels = word.match(/([áéíóúý]).*([aeioy])*/)
|
||||
last_words.each_with_index do |word2,word2_index|
|
||||
vowels = word2.scan(/([áéíóúý]).*([aeioy])*/)
|
||||
if vowels == current_vowels then
|
||||
temp = word.gsub(/.*[áéíóúý]/,"")
|
||||
this_line_number = this_line_number + 1
|
||||
this_last_vowel = line.split.at(-1).scan(/[áéíóúý]/)
|
||||
other_line_number = 0
|
||||
@text.each_line do |line_other|
|
||||
other_line_number = other_line_number + 1
|
||||
if other_line_number == this_line_number then next end
|
||||
other_last_vowel = line_other.split.at(-1).scan(/[áéíóúý]/)
|
||||
if other_last_vowel = this_last_vowel then
|
||||
matched_vowels = 1
|
||||
if line.split.at(-2).scan(/[áéíóúý]/) == line_other.split.at(-2).scan(/[áéíóúý]/) then matched_vowels = 2 end #можно сделать и так далее, но не стоит, наверное
|
||||
@rhymed.push(""+this_line_number.to_s+" "+other_line_number.to_s+" "+matched_vowels.to_s)
|
||||
end
|
||||
@rhymed.push(""+word_index.to_s+" "+word2_index.to_s+vowels.length.to_s+temp.length.to_s)
|
||||
end
|
||||
end
|
||||
@log << @rhymed.to_s
|
||||
|
|
Loading…
Reference in a new issue