class ShipEngine::RecognizedEntity
An entity is a single piece of data that was recognized in unstructured text. For example, a city, a postal code, package dimensions, insured value, etc. Each entity includes the original text and the parsed value.
Attributes
The index of the last character of this entity within the original text
The normalized value of the entity. Most entity results have a `value` field, which is the normalized value of the entity. For example, if the substring "john doe" was recognized as a "person" entity, then the value might be normalized to have proper capitalization (e.g. "John Doe"). Or if the substring "ft worth" was recognized as a "city" entity, then the value might be normalized to "Fort Worth". Some entities have other information in addition to, or instead of a `value`. For example, a "dimensions" entity will have separate fields for `length`, `width`, `height`, and `unit`.
A confidence score between zero and one that indicates how certain the API is that it correctly recognized this entity
The index of the first character of this entity within the original text
The substring from the original text that was recognized as this entity
The Entity type (e.g. "weight", "person", "address_line1", etc.)
Public Class Methods
Attribute mapping from ruby-style variable name to JSON key.
# File lib/ship_engine/models/recognized_entity.rb, line 37 def self.attribute_map { :'type' => :'type', :'score' => :'score', :'text' => :'text', :'start_index' => :'start_index', :'end_index' => :'end_index', :'result' => :'result' } end
Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself
# File lib/ship_engine/models/recognized_entity.rb, line 276 def self.build_from_hash(attributes) new.build_from_hash(attributes) end
Initializes the object @param [Hash] attributes Model attributes in the form of hash
# File lib/ship_engine/models/recognized_entity.rb, line 68 def initialize(attributes = {}) if (!attributes.is_a?(Hash)) fail ArgumentError, "The input argument (attributes) must be a hash in `ShipEngine::RecognizedEntity` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } if attributes.key?(:'type') self.type = attributes[:'type'] end if attributes.key?(:'score') self.score = attributes[:'score'] end if attributes.key?(:'text') self.text = attributes[:'text'] end if attributes.key?(:'start_index') self.start_index = attributes[:'start_index'] end if attributes.key?(:'end_index') self.end_index = attributes[:'end_index'] end if attributes.key?(:'result') if (value = attributes[:'result']).is_a?(Hash) self.result = value end end end
List of attributes with nullable: true
# File lib/ship_engine/models/recognized_entity.rb, line 61 def self.openapi_nullable Set.new([ ]) end
Attribute type mapping.
# File lib/ship_engine/models/recognized_entity.rb, line 49 def self.openapi_types { :'type' => :'String', :'score' => :'Float', :'text' => :'String', :'start_index' => :'Integer', :'end_index' => :'Integer', :'result' => :'Hash<String, Object>' } end
Public Instance Methods
Checks equality by comparing each attribute. @param [Object] Object to be compared
# File lib/ship_engine/models/recognized_entity.rb, line 250 def ==(o) return true if self.equal?(o) self.class == o.class && type == o.type && score == o.score && text == o.text && start_index == o.start_index && end_index == o.end_index && result == o.result end
Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data
# File lib/ship_engine/models/recognized_entity.rb, line 304 def _deserialize(type, value) case type.to_sym when :DateTime DateTime.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?<inner_type>.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model ShipEngine.const_get(type).build_from_hash(value) end end
Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash
# File lib/ship_engine/models/recognized_entity.rb, line 373 def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end
Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself
# File lib/ship_engine/models/recognized_entity.rb, line 283 def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) end # or else data not found in attributes(hash), not an issue as the data can be optional end self end
Custom attribute writer method with validation @param [Object] end_index
Value to be assigned
# File lib/ship_engine/models/recognized_entity.rb, line 236 def end_index=(end_index) if end_index.nil? fail ArgumentError, 'end_index cannot be nil' end if end_index < 0 fail ArgumentError, 'invalid value for "end_index", must be greater than or equal to 0.' end @end_index = end_index end
@see the `==` method @param [Object] Object to be compared
# File lib/ship_engine/models/recognized_entity.rb, line 263 def eql?(o) self == o end
Calculates hash code according to all attributes. @return [Integer] Hash code
# File lib/ship_engine/models/recognized_entity.rb, line 269 def hash [type, score, text, start_index, end_index, result].hash end
Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properties with the reasons
# File lib/ship_engine/models/recognized_entity.rb, line 108 def list_invalid_properties invalid_properties = Array.new if @type.nil? invalid_properties.push('invalid value for "type", type cannot be nil.') end if @type.to_s.length < 1 invalid_properties.push('invalid value for "type", the character length must be great than or equal to 1.') end if @score.nil? invalid_properties.push('invalid value for "score", score cannot be nil.') end if @score > 1 invalid_properties.push('invalid value for "score", must be smaller than or equal to 1.') end if @score < 0 invalid_properties.push('invalid value for "score", must be greater than or equal to 0.') end if @text.nil? invalid_properties.push('invalid value for "text", text cannot be nil.') end if @text.to_s.length < 1 invalid_properties.push('invalid value for "text", the character length must be great than or equal to 1.') end if @start_index.nil? invalid_properties.push('invalid value for "start_index", start_index cannot be nil.') end if @start_index < 0 invalid_properties.push('invalid value for "start_index", must be greater than or equal to 0.') end if @end_index.nil? invalid_properties.push('invalid value for "end_index", end_index cannot be nil.') end if @end_index < 0 invalid_properties.push('invalid value for "end_index", must be greater than or equal to 0.') end invalid_properties end
Custom attribute writer method with validation @param [Object] score Value to be assigned
# File lib/ship_engine/models/recognized_entity.rb, line 190 def score=(score) if score.nil? fail ArgumentError, 'score cannot be nil' end if score > 1 fail ArgumentError, 'invalid value for "score", must be smaller than or equal to 1.' end if score < 0 fail ArgumentError, 'invalid value for "score", must be greater than or equal to 0.' end @score = score end
Custom attribute writer method with validation @param [Object] start_index
Value to be assigned
# File lib/ship_engine/models/recognized_entity.rb, line 222 def start_index=(start_index) if start_index.nil? fail ArgumentError, 'start_index cannot be nil' end if start_index < 0 fail ArgumentError, 'invalid value for "start_index", must be greater than or equal to 0.' end @start_index = start_index end
Custom attribute writer method with validation @param [Object] text Value to be assigned
# File lib/ship_engine/models/recognized_entity.rb, line 208 def text=(text) if text.nil? fail ArgumentError, 'text cannot be nil' end if text.to_s.length < 1 fail ArgumentError, 'invalid value for "text", the character length must be great than or equal to 1.' end @text = text end
Returns the object in the form of hash @return [Hash] Returns the object in the form of hash
# File lib/ship_engine/models/recognized_entity.rb, line 355 def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end hash[param] = _to_hash(value) end hash end
Returns the string representation of the object @return [String] String presentation of the object
# File lib/ship_engine/models/recognized_entity.rb, line 343 def to_s to_hash.to_s end
Custom attribute writer method with validation @param [Object] type Value to be assigned
# File lib/ship_engine/models/recognized_entity.rb, line 176 def type=(type) if type.nil? fail ArgumentError, 'type cannot be nil' end if type.to_s.length < 1 fail ArgumentError, 'invalid value for "type", the character length must be great than or equal to 1.' end @type = type end
Check to see if the all the properties in the model are valid @return true if the model is valid
# File lib/ship_engine/models/recognized_entity.rb, line 159 def valid? return false if @type.nil? return false if @type.to_s.length < 1 return false if @score.nil? return false if @score > 1 return false if @score < 0 return false if @text.nil? return false if @text.to_s.length < 1 return false if @start_index.nil? return false if @start_index < 0 return false if @end_index.nil? return false if @end_index < 0 true end