Class: Olyx::Guardrails::Text::MappedNormalization

Inherits:
Object
  • Object
show all
Defined in:
lib/olyx/guardrails/text/mapped_normalization.rb

Overview

Holds normalized detector text and translates matches to original spans.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ MappedNormalization

Returns a new instance of MappedNormalization.



12
13
14
15
# File 'lib/olyx/guardrails/text/mapped_normalization.rb', line 12

def initialize(source)
  @source = source
  @text, @starts, @endings = MappedBuilder.call(source)
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



10
11
12
# File 'lib/olyx/guardrails/text/mapped_normalization.rb', line 10

def text
  @text
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/olyx/guardrails/text/mapped_normalization.rb', line 17

def changed?
  @text != @source
end

#original_span(starting, ending) ⇒ Object



21
22
23
# File 'lib/olyx/guardrails/text/mapped_normalization.rb', line 21

def original_span(starting, ending)
  [@starts.fetch(starting), @endings.fetch(ending - 1)]
end