Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/nickel/nlp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def parse

extract_message
correct_case
replace_hyphen

@construct_interpreter = ConstructInterpreter.new(@construct_finder.constructs, @input_date) # input_date only needed for wrappers
@construct_interpreter.run
Expand Down Expand Up @@ -84,13 +85,25 @@ def correct_case
orig = @query.split
latest = @message.split
orig.each_with_index do |original_word, j|
if i = latest.index(original_word.downcase)
if i = latest.index(original_word.gsub(/[,.;'`]/, '').downcase)
latest[i] = original_word
end
end
@message = latest.join(' ')
end

def replace_hyphen
orig = @query.split
latest = @message.split
orig.each_with_index do |original_word, j|
if original_word =~ /-/ && original_word.gsub(/[,.;'`]/, '').downcase == "#{latest[j]}-#{latest[j+1]}"
latest[j] = original_word
latest.delete_at(j+1)
end
end
@message = latest.join(' ')
end

def validate_input(query, date_time)
fail 'Empty NLP query' unless query.length > 0
fail 'NLP says: date_time is not in the correct format' unless date_time =~ /^\d{8}T\d{6}$/
Expand Down
38 changes: 38 additions & 0 deletions spec/lib/nickel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,44 @@
end
end

context "when the query is 'call Jake's bakery at 11am'" do
let(:query) { "call Jake's bakery everyday at 11am" }
let(:run_date) { Time.local(2014, 2, 26) }

describe '#message' do
it "is 'call Jake's bakery'" do
expect(n.message).to eq "call Jake's bakery"
end
end

describe '#occurrences' do
it 'is daily at 11:00am' do
expect(n.occurrences).to match_array [
Nickel::Occurrence.new(type: :daily, interval: 1, start_date: Nickel::ZDate.new('20140226'), start_time: Nickel::ZTime.new('11'))
]
end
end
end

context "when the query is 'send Jake's E-mail everyday at 11am'" do
let(:query) { "send Jake's E-mail everyday at 11am" }
let(:run_date) { Time.local(2014, 2, 26) }

describe '#message' do
it "is 'send Jake's E-mail'" do
expect(n.message).to eq "send Jake's E-mail"
end
end

describe '#occurrences' do
it 'is daily at 11:00am' do
expect(n.occurrences).to match_array [
Nickel::Occurrence.new(type: :daily, interval: 1, start_date: Nickel::ZDate.new('20140226'), start_time: Nickel::ZTime.new('11'))
]
end
end
end

context "when the query is 'guitar lessons every tuesday at 5pm'" do
let(:query) { 'guitar lessons every tuesday at 5pm' }
let(:run_date) { Time.local(2014, 2, 26) }
Expand Down