Class: KyTea

Inherits:
Object
  • Object
show all
Defined in:
lib/kytea.rb

Instance Method Summary collapse

Constructor Details

#initialize(option = "") ⇒ KyTea

Returns a new instance of KyTea.



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

def initialize(option = "")
  @model = Mykytea::Mykytea.new(option)
end

Instance Method Details

#segment(input) ⇒ Object



9
10
11
12
13
# File 'lib/kytea.rb', line 9

def segment(input)
  @model.getWS(input).map do |word|
    word.force_encoding(Encoding.default_external)
  end
end

#tag_info_of(input) ⇒ Object



15
16
17
# File 'lib/kytea.rb', line 15

def tag_info_of(input)
  @model.getTagsToString(input).force_encoding(Encoding.default_external)
end

#tags_of(input, full_tag: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kytea.rb', line 19

def tags_of(input, full_tag: false)
  raw_tags = full_tag ? @model.getAllTags(input) : @model.getTags(input)
  raw_tags.map do |e|
    tags = e.tag.map do |t|
              t.map do |k, v|
                {
                  tag: k.force_encoding("UTF-8"),
                  val: v
                }
              end
            end
    {
      surface: e.surface.force_encoding("UTF-8"),
      tags: tags
    }
  end
end