Class: CRFPP::Token

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arguments) ⇒ Token

Creates a new Token instance.

call-seq: Token.new(word) Token.new(word, tags) Token.new(word, tag, tag, tag …)



18
19
20
# File 'lib/crfpp/token.rb', line 18

def initialize(*arguments)
  @word, *@tags = *arguments.flatten
end

Instance Attribute Details

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/crfpp/token.rb', line 4

def tags
  @tags
end

#wordObject

Returns the value of attribute word.



4
5
6
# File 'lib/crfpp/token.rb', line 4

def word
  @word
end

Class Method Details

.parse(string) ⇒ Object



6
7
8
9
# File 'lib/crfpp/token.rb', line 6

def self.parse(string)
  tokens = string.split(/\s+/).compact
  tokens.empty? ? nil : new(tokens)
end

Instance Method Details

#answerObject



22
23
24
# File 'lib/crfpp/token.rb', line 22

def answer
  @tags[-1]
end

#to_sObject



26
27
28
# File 'lib/crfpp/token.rb', line 26

def to_s
  [@word.to_s, @tags].flatten.join(' ')
end