Class: AtlasEngine::AddressValidation::Token
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Token
- Extended by:
- T::Sig
- Defined in:
- app/models/atlas_engine/address_validation/token.rb,
app/models/atlas_engine/address_validation/token/sequence.rb,
app/models/atlas_engine/address_validation/token/synonyms.rb,
app/models/atlas_engine/address_validation/token/comparator.rb,
app/models/atlas_engine/address_validation/token/comparison.rb,
app/models/atlas_engine/address_validation/token/sequence/comparator.rb,
app/models/atlas_engine/address_validation/token/sequence/comparison.rb,
app/models/atlas_engine/address_validation/token/sequence/comparison_policy.rb
Defined Under Namespace
Classes: Comparator, Comparison, Sequence, Synonyms
Instance Attribute Summary collapse
-
#end_offset ⇒ Object
Returns the value of attribute end_offset.
-
#position ⇒ Object
Returns the value of attribute position.
-
#position_length ⇒ Object
readonly
Returns the value of attribute position_length.
-
#start_offset ⇒ Object
Returns the value of attribute start_offset.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value:, start_offset:, end_offset:, position:, type: nil, position_length: 1) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #inspect_short ⇒ Object
- #offset_range ⇒ Object
- #preceeds?(other) ⇒ Boolean
Constructor Details
#initialize(value:, start_offset:, end_offset:, position:, type: nil, position_length: 1) ⇒ Token
Returns a new instance of Token.
37 38 39 40 41 42 43 44 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 37 def initialize(value:, start_offset:, end_offset:, position:, type: nil, position_length: 1) @value = value @start_offset = start_offset @end_offset = end_offset @type = type @position = position @position_length = position_length end |
Instance Attribute Details
#end_offset ⇒ Object
Returns the value of attribute end_offset.
22 23 24 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 22 def end_offset @end_offset end |
#position ⇒ Object
Returns the value of attribute position.
16 17 18 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 16 def position @position end |
#position_length ⇒ Object (readonly)
Returns the value of attribute position_length.
25 26 27 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 25 def position_length @position_length end |
#start_offset ⇒ Object
Returns the value of attribute start_offset.
19 20 21 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 19 def start_offset @start_offset end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 13 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 10 def value @value end |
Class Method Details
.from_analyze(token) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 100 def from_analyze(token) new( value: token["token"], start_offset: token["start_offset"], end_offset: token["end_offset"], type: token["type"], position: token["position"], position_length: token["positionLength"] || 1, ) end |
.from_field_term_vector(field_terms) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 86 def from_field_term_vector(field_terms) field_terms["terms"].flat_map do |term, term_info| term_info["tokens"].map do |token| new( value: term, position: token["position"], start_offset: token["start_offset"], end_offset: token["end_offset"], ) end end.sort_by(&:position) end |
Instance Method Details
#==(other) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 68 def ==(other) value == other.value && start_offset == other.start_offset && end_offset == other.end_offset && type == other.type && position == other.position && position_length == other.position_length end |
#inspect ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 52 def inspect t = " type:#{type}" if type.present? pos_length = " pos_length:#{position_length}" if position_length > 1 id = "id:#{object_id.to_s[-4..-1]}" details = " strt:#{start_offset} end:#{end_offset} pos:#{position}#{t}#{pos_length}" "<tok #{id} val:\"#{value}\"#{details}/>" end |
#inspect_short ⇒ Object
62 63 64 65 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 62 def inspect_short id = "id:#{object_id.to_s[-4..-1]}" "<tok #{id} val:\"#{value}\"/>" end |
#offset_range ⇒ Object
47 48 49 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 47 def offset_range @offset_range ||= start_offset...end_offset end |
#preceeds?(other) ⇒ Boolean
78 79 80 |
# File 'app/models/atlas_engine/address_validation/token.rb', line 78 def preceeds?(other) position == other.position - position_length end |