meiou 0.1.0 → 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,15 +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
- if s == :info
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] }
53
57
  Meiou.extract(x) { |e| @tag.transaction { |db| if !db.key?(e[:word]); db[e[:word]] = []; end; db[e[:word]] << i; } }
54
58
  end
55
59
  else
56
60
  if !/GUTENBERG/.match(x)
57
- puts %[#{@id}>#{i}: #{x}]
61
+ Meiou.log "compile load section", %[#{@id}>#{i}: #{x}]
58
62
  @sec.transaction { |db| db[i] = x }
59
63
  @top.transaction { |db| db[x] = i }
60
64
  end
@@ -167,20 +171,20 @@ module BOOK
167
171
  def self.init!
168
172
  Dir['books/*'].each { |e|
169
173
  k = e.gsub("books/", "").gsub(".txt", "").gsub("_", " ");
170
- puts %[Scanning #{k}...]
174
+ Meiou.log :init_scan, %[Scanning #{k}...]
171
175
  @@BOOK[k]
172
176
  }
173
- puts %[Books scanned!]
177
+ Meiou.log :init_done, %[Books scanned!]
174
178
  return "DONE!"
175
179
  end
176
180
 
177
181
  def self.compile!
178
182
  Dir['books/*'].each { |e|
179
183
  k = e.gsub("books/", "").gsub(".txt", "").gsub("_", " ");
180
- puts %[Compiling #{k}...]
184
+ Meiou.log :compile_load, %[#{k}...]
181
185
  @@BOOK[k].load(e)
182
186
  }
183
- puts %[Books compiled!]
187
+ Meiou.log :compile_done, %[done!]
184
188
  return "DONE!"
185
189
  end
186
190
  end
@@ -2,24 +2,20 @@ require 'tokenizer'
2
2
 
3
3
  module DICT
4
4
  # extract a list of tokens from +payload+ and handle with block passing +index+ and +WORD[word]+.
5
- def self.[] payload, &block
6
- Tokenizer::WhitespaceTokenizer.new().tokenize(payload).each do |e|
7
- d = Meiou.word[e]
8
- if d != nil
9
- if "#{e}".length > 2 && !/[[:punct:]]/.match(e) && !['the','and','but','this','that'].include?(e.downcase) && d != false
10
- #puts %[Meiou | #{e} | #{d[:pos].sample} | #{d[:def].sample}]
11
- block.call(d)
12
- end
13
- end
14
- end
15
- return nil
5
+ def self.[] k
6
+ DICT.know(k, define: true, example: true )
16
7
  end
17
-
8
+
18
9
  def self.know input, h={}
19
- a = []
20
- DICT[input] { |w|
10
+ a = []
11
+ DICT.keywords(input).each { |e|
12
+ w = WORD[e]
21
13
  if h[:define] == true
22
- 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
23
19
  end
24
20
  BOOK.word(w[:word]) { |r|
25
21
  if h[:cite] == true
@@ -33,9 +29,34 @@ module DICT
33
29
  }
34
30
  return a
35
31
  end
32
+
33
+ def self.keywords input, &b
34
+ a = []
35
+ Tokenizer::WhitespaceTokenizer.new().tokenize(input).each do |e|
36
+ d = Meiou.word[e]
37
+ if d != nil
38
+ if "#{e}".length > 2 && !/[[:punct:]]/.match(e) && !['the','and','but','this','that'].include?(e.downcase) && d != false
39
+ if block_given?
40
+ a << b.call(d)
41
+ else
42
+ a << e
43
+ end
44
+ end
45
+ end
46
+ end
47
+ return a
48
+ end
36
49
  end
37
50
 
38
51
  module Meiou
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
58
+ end
59
+
39
60
  def self.[] k
40
61
  DICT.know(k, define: true, example: true)
41
62
  end
@@ -0,0 +1,68 @@
1
+ require 'tokipona'
2
+ require 'yaml'
3
+
4
+ module TOKI
5
+ @@T = Hash.new { |h,k| h[k] = T.new(k) }
6
+ class T
7
+ attr_reader :pos
8
+ def initialize k
9
+ @id = k
10
+ @pos = {}
11
+ end
12
+ def pos? k
13
+ if @pos.has_key? k
14
+ return true
15
+ else
16
+ return false
17
+ end
18
+ end
19
+ def [] k
20
+ @pos[k]
21
+ end
22
+ def keys
23
+ @pos.keys
24
+ end
25
+ def define h={}
26
+ h.each_pair do |k,v|
27
+ [v].flatten.each { |e| TOKI.concept[e] = @id }
28
+ @pos[k] = v
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.[] k
34
+ @@T[k]
35
+ end
36
+ def self.keys
37
+ @@T.keys
38
+ end
39
+
40
+ @@C = {}
41
+ def self.concept
42
+ @@C
43
+ end
44
+
45
+ def self.english s
46
+ h = {}
47
+ Tokipona::Tokenizer.tokenize(s).each do |e|
48
+ if !/[[:punct:]]/.match(e)
49
+ h[e] = TOKI[e]
50
+ end
51
+ end
52
+ return h
53
+ end
54
+
55
+ def self.tokipona s
56
+ h = {}
57
+ Tokenizer::WhitespaceTokenizer.new().tokenize(s).each do |e|
58
+ if !/[[:punct:]]/.match(e)
59
+ if TOKI.concept.has_key?(e)
60
+ h[e] = TOKI.concept[e]
61
+ end
62
+ end
63
+ end
64
+ return h
65
+ end
66
+
67
+ YAML.load(File.read(ENV['TOKIPONA'] || '../tokipona.yaml')).each_pair { |k,v| @@T[k].define(v) }
68
+ 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.0"
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
@@ -40,4 +44,6 @@ require_relative "meiou/book"
40
44
 
41
45
  require_relative "meiou/mood"
42
46
 
47
+ require_relative "meiou/tokipona"
48
+
43
49
  Meiou.init!
data/meiou.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "rwordnet"
37
37
  spec.add_dependency "tokenizer"
38
38
  spec.add_dependency "textmood"
39
+ spec.add_dependency "tokipona"
39
40
  # For more information and examples about making a new gem, check out our
40
41
  # guide at: https://bundler.io/guides/creating_gem.html
41
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meiou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wikipedia-client
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tokipona
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: A wrapper for for wikipedia entries, curated txt files, and other sources
84
98
  of knowledge.
85
99
  email:
@@ -122,7 +136,6 @@ files:
122
136
  - books/Applied_Psychology_for_Nurses.txt
123
137
  - books/Crystallizing_Public_Opinion.txt
124
138
  - books/Doctor_and_Patient.txt
125
- - books/Increasing_Human_Efficiency_in_Business.txt
126
139
  - books/Roman_Farm_Management.txt
127
140
  - books/Social_Organization.txt
128
141
  - books/interpretation_of_dreams.txt
@@ -131,6 +144,7 @@ files:
131
144
  - lib/meiou/book.rb
132
145
  - lib/meiou/dictionary.rb
133
146
  - lib/meiou/mood.rb
147
+ - lib/meiou/tokipona.rb
134
148
  - lib/meiou/version.rb
135
149
  - lib/meiou/wiki.rb
136
150
  - lib/meiou/word.rb