Created
June 14, 2010 16:17
-
-
Save vsalbaba/437895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Correcter | |
def initialize(input, dictionary) | |
@input = File.read(input) | |
@dictionary = File.read(dictionary) | |
@internal_dictionary = normalize_dictionary | |
@sentences = split_input_to_sentences | |
end | |
def normalize_dictionary | |
@dictionary.split | |
end | |
def split_input_to_sentences | |
acc = @input | |
sentences = [] | |
until acc.empty? do | |
break unless index = acc.index(/[\.\!\?]/) | |
sentences << acc.slice!(0..index) | |
end | |
sentences | |
end | |
def correct_sentence(sentence) | |
sentence.split.each do |word| | |
if not known_word? word then | |
correct_word word, sentence | |
end | |
end | |
end | |
def known_word?(word) | |
@internal_dictionary.include?(word) | |
end | |
def correct_word(word, sentence) | |
print_sentence_and_word(word, sentence, 'blah') | |
end | |
def print_sentence_and_word(word, sentence, correction) | |
puts "Je třeba opravit slovo '#{word}' ve větě '#{sentence}'" | |
puts "Chcete: | |
a) Slovo nechat ve větě beze změny. | |
b) Slovo nechat ve větě a zároveň zařadit jako gramaticky správné do slovníku. | |
c) Slovo opravit - původní slovo se nahradí slovem, které je vloženo z klávesnice. | |
d) Nahradit slovo '#{word}' slovem '#{correction}' | |
Zvolte a, b, c, d" | |
case gets.chomp | |
when 'a' then | |
puts 'zvoleno a' | |
when 'b' then | |
puts 'zvoleno b' | |
when 'c' then | |
puts "Zadejte slovo kterym se ma '#{word}' nahradit a stiskn2te enter" | |
return gets.chomp | |
when 'd' then | |
puts 'zvoleno d' | |
else | |
puts 'neplatna volba' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment