Class: CRFPP::Token
- Inherits:
-
Object
- Object
- CRFPP::Token
- Defined in:
- lib/crfpp/token.rb
Instance Attribute Summary collapse
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#word ⇒ Object
Returns the value of attribute word.
Class Method Summary collapse
Instance Method Summary collapse
- #answer ⇒ Object
-
#initialize(*arguments) ⇒ Token
constructor
Creates a new Token instance.
- #to_s ⇒ Object
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
#tags ⇒ Object
Returns the value of attribute tags.
4 5 6 |
# File 'lib/crfpp/token.rb', line 4 def @tags end |
#word ⇒ Object
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
#answer ⇒ Object
22 23 24 |
# File 'lib/crfpp/token.rb', line 22 def answer @tags[-1] end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/crfpp/token.rb', line 26 def to_s [@word.to_s, @tags].flatten.join(' ') end |