Module: DICT

Defined in:
lib/meiou/dictionary.rb

Class Method Summary collapse

Class Method Details

.[](k) ⇒ Object

extract a list of tokens from payload and handle with block passing index and WORD[word].



5
6
7
# File 'lib/meiou/dictionary.rb', line 5

def self.[] k
  DICT.know(k, define: true, example: true )
end

.keywords(input, &b) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/meiou/dictionary.rb', line 33

def self.keywords input, &b
  a = []
  Tokenizer::WhitespaceTokenizer.new().tokenize(input).each do |e|
    d = Meiou.word[e]
    if d != nil
      if "#{e}".length > 2 && !/[[:punct:]]/.match(e) && !['the','and','but','this','that'].include?(e.downcase) && d != false 
        if block_given?
          a << b.call(d)
        else
          a << e
        end
      end
    end
  end
  return a
end

.know(input, h = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/meiou/dictionary.rb', line 9

def self.know input, h={}
  a = []
  DICT.keywords(input).each { |e|
    w = WORD[e]
    if h[:define] == true
      if w[:def].length > 0
        a << %[#{w[:word].capitalize} means #{w[:def].sample}.];
      else
        a << %[#{w[:word].capitalize} means #{w[:word]}.];
      end
    end
    BOOK.word(w[:word]) { |r|
      if h[:cite] == true
        a << %[[#{r[:book]}:#{r[:index]}:#{w[:word]}] #{r[:text]}]
      else
        if h[:example] == true
          a << %[#{r[:text]}]
        end
      end
    }
  }
  return a
end