getting a random word
Opened this issue · 0 comments
tansaku commented
This is a great little gem, but I am having trouble modifying it. Checking out locally I can't run any tests - not sure what version of ruby it's supposed to run with ... here's the output I get trying to run the tests:
❯ rake test
/Users/samueljoseph/.rvm/rubies/ruby-2.7.5/bin/ruby -w -I"lib" /Users/samueljoseph/.rvm/gems/ruby-2.7.5/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/unit/db_test.rb" "test/unit/lemma_test.rb" "test/unit/pointer_test.rb" "test/unit/synset_test.rb"
RUBY_GC_HEAP_INIT_SLOTS=800000 (default value: 10000)
RUBY_GC_MALLOC_LIMIT=79000000 (default value: 16777216)
W, [2021-12-08T16:16:37.558747 #56128] WARN -- : This usage of the Code Climate Test Reporter is now deprecated. Since version
1.0, we now require you to run `SimpleCov` in your test/spec helper, and then
run the provided `codeclimate-test-reporter` binary separately to report your
results to Code Climate.
More information here: https://github.com/codeclimate/ruby-test-reporter/blob/master/README.md
rake aborted!
Command failed with status (1): [ruby -w -I"lib" /Users/samueljoseph/.rvm/gems/ruby-2.7.5/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/unit/db_test.rb" "test/unit/lemma_test.rb" "test/unit/pointer_test.rb" "test/unit/synset_test.rb" ]
/Users/samueljoseph/.rvm/gems/ruby-2.7.5/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/Users/samueljoseph/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `eval'
/Users/samueljoseph/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
in a console it's trivial to grab a random word like so:
SPACE = ' '
cache = {}
WordNet::DB.open(File.join("dict", "index.noun")).each_line.each_with_index do |line, index|
word = line.slice(0, line.index(SPACE))
cache[word] = [line, index+1]
end
keys = cache.keys
keys[rand(keys.length)]
and I'd love to add a method like this to lemma.rb
def rand(pos)
pos = POS_SHORTHAND[pos] || pos
cache = @@cache[pos] ||= build_cache(pos)
keys = cache.keys
keys[rand(keys.length)]
end
and contribute back to the repo, but ... well ... I guess I can put in a PR. will monkey match for the time being I guess ...