Skip to content

Instantly share code, notes, and snippets.

@jdecuirm
Created February 11, 2015 03:58
Show Gist options
  • Select an option

  • Save jdecuirm/c09ebbc1bd04cda1aca1 to your computer and use it in GitHub Desktop.

Select an option

Save jdecuirm/c09ebbc1bd04cda1aca1 to your computer and use it in GitHub Desktop.
Comparing Words
class Lexicon
#Arrays that holds the words to compare
@directions = %w{south west east north}
@verbs = %w{go kill eat play say talk jump fight throw smile hit punch climb}
@nouns = %w{bear princess penguin mole cherry lollipop pillow}
@stop_words = %w{the in of}
#Class method that gets a string and classify the word. It makes an array of the classification and the word
def self.scan(inputed_text)
defined_array_words = []
words = inputed_text.split(" ")
words.each do |word|
@directions.each do |direction|
if word == direction
word_catego = []
word_catego << 'direction'
word_catego << word
defined_array_words << word_catego
end
end
end
defined_array_words
end
end
require 'rake/testtask'
Rake::TestTask.new do |task|
task.libs << "tests"
task.test_files = FileList['tests/test*.rb']
task.verbose = true
task.warning = true
end
require './lib/EX48/lexicon.rb'
require 'test/unit'
class TestName < Test::Unit::TestCase
def test_directions()
assert_equal(Lexicon.scan('north'),[['direction','north']])
result = Lexicon.scan("north south east")
assert_equal(result,[['direction','north'],['direction','south'],['direction','east']])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment