meiou 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/meiou/book.rb CHANGED
@@ -12,7 +12,10 @@ module BOOK
12
12
  [ :tiny, :info, :short, :med, :long ]
13
13
  end
14
14
  def self.size? w
15
- if w.length > BOOK.size[0] && w.length <= BOOK.size[1]
15
+
16
+ if w.length < BOOK.size[0]
17
+ s = :ignore
18
+ elsif w.length > BOOK.size[0] && w.length <= BOOK.size[1]
16
19
  s = :tiny
17
20
  elsif w.length > BOOK.size[1] && w.length <= BOOK.size[2]
18
21
  s = :info
@@ -46,14 +49,16 @@ module BOOK
46
49
  if !/Project Gutenberg/.match(x)
47
50
  if !/^[[[:upper:]]|[[:blank:]]|[[:punct:]]|[[:digit:]]]*$/.match(x)
48
51
  s = BOOK.size?(x.split(/\s/))
49
- @bin[s].transaction { |db| db[i] = x }
50
- @ind.transaction { |db| db[i] = s }
51
- @mod.transaction { |db| db[i] = MOOD[x] }
52
- puts ":INFO"
53
- Meiou.extract(x) { |e| @tag.transaction { |db| if !db.key?(e[:word]); db[e[:word]] = []; end; db[e[:word]] << i; } }
52
+ Meiou.log "compile load item", "[#{@id}][#{i}] #{s}"
53
+ if s != :ignore
54
+ @bin[s].transaction { |db| db[i] = x }
55
+ @ind.transaction { |db| db[i] = s }
56
+ @mod.transaction { |db| db[i] = MOOD[x] }
57
+ Meiou.extract(x) { |e| @tag.transaction { |db| if !db.key?(e[:word]); db[e[:word]] = []; end; db[e[:word]] << i; } }
58
+ end
54
59
  else
55
60
  if !/GUTENBERG/.match(x)
56
- puts %[#{@id}>#{i}: #{x}]
61
+ Meiou.log "compile load section", %[#{@id}>#{i}: #{x}]
57
62
  @sec.transaction { |db| db[i] = x }
58
63
  @top.transaction { |db| db[x] = i }
59
64
  end
@@ -166,20 +171,20 @@ module BOOK
166
171
  def self.init!
167
172
  Dir['books/*'].each { |e|
168
173
  k = e.gsub("books/", "").gsub(".txt", "").gsub("_", " ");
169
- puts %[Scanning #{k}...]
174
+ Meiou.log :init_scan, %[Scanning #{k}...]
170
175
  @@BOOK[k]
171
176
  }
172
- puts %[Books scanned!]
177
+ Meiou.log :init_done, %[Books scanned!]
173
178
  return "DONE!"
174
179
  end
175
180
 
176
181
  def self.compile!
177
182
  Dir['books/*'].each { |e|
178
183
  k = e.gsub("books/", "").gsub(".txt", "").gsub("_", " ");
179
- puts %[Compiling #{k}...]
184
+ Meiou.log :compile_load, %[#{k}...]
180
185
  @@BOOK[k].load(e)
181
186
  }
182
- puts %[Books compiled!]
187
+ Meiou.log :compile_done, %[done!]
183
188
  return "DONE!"
184
189
  end
185
190
  end
@@ -3,14 +3,19 @@ require 'tokenizer'
3
3
  module DICT
4
4
  # extract a list of tokens from +payload+ and handle with block passing +index+ and +WORD[word]+.
5
5
  def self.[] k
6
- DICT.extract(k)
6
+ DICT.know(k, define: true, example: true )
7
7
  end
8
-
8
+
9
9
  def self.know input, h={}
10
- a = []
11
- DICT[input] { |w|
10
+ a = []
11
+ DICT.keywords(input).each { |e|
12
+ w = WORD[e]
12
13
  if h[:define] == true
13
- a << %[#{w[:word].capitalize} means #{w[:def].sample}.];
14
+ if w[:def].length > 0
15
+ a << %[#{w[:word].capitalize} means #{w[:def].sample}.];
16
+ else
17
+ a << %[#{w[:word].capitalize} means #{w[:word]}.];
18
+ end
14
19
  end
15
20
  BOOK.word(w[:word]) { |r|
16
21
  if h[:cite] == true
@@ -25,13 +30,12 @@ module DICT
25
30
  return a
26
31
  end
27
32
 
28
- def self.extract i, &b
33
+ def self.keywords input, &b
29
34
  a = []
30
- Tokenizer::WhitespaceTokenizer.new().tokenize(i).each do |e|
35
+ Tokenizer::WhitespaceTokenizer.new().tokenize(input).each do |e|
31
36
  d = Meiou.word[e]
32
37
  if d != nil
33
- if "#{e}".length > 2 && !/[[:punct:]]/.match(e) && !['the','and','but','this','that'].include?(e.downcase) && d != false
34
- #puts %[Meiou | #{e} | #{d[:pos].sample} | #{d[:def].sample}]
38
+ if "#{e}".length > 2 && !/[[:punct:]]/.match(e) && !['the','and','but','this','that'].include?(e.downcase) && d != false
35
39
  if block_given?
36
40
  a << b.call(d)
37
41
  else
@@ -45,12 +49,14 @@ module DICT
45
49
  end
46
50
 
47
51
  module Meiou
48
- def self.keywords k
49
- DICT.know(k)
50
- end
51
- def self.extract k
52
- DICT[k]
52
+ def self.extract k, &b
53
+ if block_given?
54
+ DICT.keywords(k) { |e| b.call(e) }
55
+ else
56
+ DICT.keywords(k)
57
+ end
53
58
  end
59
+
54
60
  def self.[] k
55
61
  DICT.know(k, define: true, example: true)
56
62
  end
data/lib/meiou/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meiou
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/meiou/word.rb CHANGED
@@ -5,7 +5,17 @@ module WORD
5
5
  # find +word+.
6
6
  def self.term word
7
7
  ds, df = [], []
8
- WordNet::Lemma.find_all(word).each { |e| ds << e.pos; e.synsets.each { |ee| df << ee.gloss.gsub('"', "").gsub("--", " ").split("; ")[0] } }
8
+ WordNet::Lemma.find_all(word).each { |e|
9
+ ds << e.pos;
10
+ e.synsets.each { |ee|
11
+ ee.expanded_hypernyms.each { |eee|
12
+ ee.gloss.gsub('"', "").gsub("--", " ").split("; ").each { |eeee|
13
+ df << eeee
14
+ df.uniq!
15
+ }
16
+ }
17
+ }
18
+ }
9
19
  #if ds.include?('n') && !ds.include?('v')
10
20
  if ds.length > 0
11
21
  return { word: word, pos: ds, def: df }
@@ -29,6 +39,9 @@ module Meiou
29
39
  def self.word
30
40
  WORD
31
41
  end
42
+ def self.meaning(w, ww, &b)
43
+ WORD[w][:def].each { |e| if Regexp.new(ww).match(e); b.call(e); end }
44
+ end
32
45
  def self.words
33
46
  WORD.keys
34
47
  end
data/lib/meiou.rb CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'pstore'
4
4
 
5
+ if !Dir.exist? 'db'
6
+ Dir.mkdir 'db'
7
+ end
8
+
5
9
  module Meiou
6
10
  TRAMPSTAMP = '[MEIOU]'
7
11
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meiou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
@@ -136,7 +136,6 @@ files:
136
136
  - books/Applied_Psychology_for_Nurses.txt
137
137
  - books/Crystallizing_Public_Opinion.txt
138
138
  - books/Doctor_and_Patient.txt
139
- - books/Increasing_Human_Efficiency_in_Business.txt
140
139
  - books/Roman_Farm_Management.txt
141
140
  - books/Social_Organization.txt
142
141
  - books/interpretation_of_dreams.txt