Class: Srx::Engine

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

Overview

Engine for performing SRX segmenting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, format: :text) ⇒ Engine

Returns a new instance of Engine.

Parameters:



11
12
13
14
# File 'lib/srx/engine.rb', line 11

def initialize(data, format: :text)
  @data = data
  @format = Format.get(format)
end

Instance Attribute Details

#dataData (readonly)

Returns:



7
8
9
# File 'lib/srx/engine.rb', line 7

def data
  @data
end

Instance Method Details

#segment(str, language:) ⇒ Array<String>

Parameters:

  • str (String)
  • language (String)

Returns:

  • (Array<String>)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/srx/engine.rb', line 19

def segment(str, language:)
  results = []
  rules = rules(language)

  plain_text, markups = @format.extract_markups(str)

  pos = 0
  breaks_by_pos(plain_text, rules).each do |break_pos, _|
    results << build_segment!(plain_text, markups, pos, break_pos)
    pos = break_pos
  end

  results
end