Class: RMMSeg::Token

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

Overview

A Token consists of a term’s text and the start and end offset of the term.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, start_pos, end_pos) ⇒ Token

text is the ref to the whole text. In other words: text[start_pos...end_pos] should be the string held by this token.



19
20
21
22
23
# File 'lib/rmmseg/token.rb', line 19

def initialize(text, start_pos, end_pos)
  @text = text
  @start = start_pos
  @end = end_pos
end

Instance Attribute Details

#endObject

The one greater than the position of the last byte of the token. This is byte index instead of character.



14
15
16
# File 'lib/rmmseg/token.rb', line 14

def end
  @end
end

#startObject

The start position of the token. This is byte index instead of character.



10
11
12
# File 'lib/rmmseg/token.rb', line 10

def start
  @start
end

#textObject

The text of the token



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

def text
  @text
end

Instance Method Details

#to_sObject



25
26
27
# File 'lib/rmmseg/token.rb', line 25

def to_s
  @text.dup
end