module ClockWordnet
ClockWordnet — playful WordNet gloss lines for upside-down clock words. Public: association_lines Depends: Dictionary plugin Tests: test/lib/clock_wordnet_test.rb
Constants
- DEFAULT_FLAGS
- MAX_LINES
- SENSE_LINE
Public Instance Methods
Source
# File lib/clock/wordnet.rb, line 17 def association_lines(word, lookup: Dictionary.default_run, max_lines: MAX_LINES) token = word.to_s.strip.downcase return [] if token.length < 2 return [] unless token.match?(/\A[a-z]+\z/) output, status = Dictionary.run_lookup(token, DEFAULT_FLAGS.dup, run: lookup) return [] if Dictionary.wn_miss?(output, status) extract_sense_lines(output.lines.map(&:rstrip)) .first(max_lines) .map { |line| playful_line(line, token) } .reject(&:empty?) rescue StandardError [] end
Source
# File lib/clock/wordnet.rb, line 33 def extract_sense_lines(lines) body = [] lines.each do |line| cleaned = Dictionary.clean_line(line) next if cleaned.empty? next if cleaned.match?(/\AOverview of /i) next if cleaned.match?(/\AThe (noun|verb|adj|adverb) /i) next if cleaned.match?(/\A\d+ of \d+ senses of /i) body << format_sense_line(cleaned) if cleaned.match?(/\A\d+\./) end body end
Source
# File lib/clock/wordnet.rb, line 47 def format_sense_line(line) cleaned = Dictionary.clean_line(line) match = cleaned.match(SENSE_LINE) return cleaned unless match number, words, gloss = match.captures "#{number}. #{words} — #{gloss}" end
Source
# File lib/clock/wordnet.rb, line 56 def playful_line(line, word) cleaned = Dictionary.clean_line(line) match = cleaned.match(/\A(\d+)\.\s*(.+?)\s+—\s+(.+)\z/) return cleaned unless match number, _head, gloss = match.captures flip = word.to_s.strip.downcase "#{number}. #{flip} — #{gloss}" end