Module: TOKI

Defined in:
lib/meiou/tokipona.rb

Defined Under Namespace

Classes: T

Constant Summary collapse

@@T =
Hash.new { |h,k| h[k] = T.new(k) }
@@C =
{}

Class Method Summary collapse

Class Method Details

.[](k) ⇒ Object



36
37
38
# File 'lib/meiou/tokipona.rb', line 36

def self.[] k
  @@T[k]
end

.conceptObject



44
45
46
# File 'lib/meiou/tokipona.rb', line 44

def self.concept
  @@C
end

.english(s) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/meiou/tokipona.rb', line 48

def self.english s
  h = {}
  Tokipona::Tokenizer.tokenize(s).each do |e|
    if !/[[:punct:]]/.match(e)
      h[e] = TOKI[e].to_h
    end
  end
  return h
end

.init!Object



69
70
71
72
# File 'lib/meiou/tokipona.rb', line 69

def self.init!
  YAML.load(File.read('lang/tokipona.yaml')).each_pair { |k,v| @@T[k].define(v) }
  return "#{@@T.keys.length} words. #{@@C.keys.length} concepts."
end

.keysObject



39
40
41
# File 'lib/meiou/tokipona.rb', line 39

def self.keys
  @@T.keys
end

.tokipona(s) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/meiou/tokipona.rb', line 58

def self.tokipona s
  a = []
  Tokenizer::WhitespaceTokenizer.new().tokenize(s).each do |e|
    if !/[[:punct:]]/.match(e)
      if TOKI.concept.has_key?(e)
        a << TOKI.concept[e]
      end
    end
  end
  return %[#{a.join(" ")}.]
end