Class: Kotoshu::Language::Segment
- Inherits:
-
Struct
- Object
- Struct
- Kotoshu::Language::Segment
- Defined in:
- lib/kotoshu/language/segmenter.rb
Overview
Value object: a contiguous run of text nodes that all share a detected language. Produced by Kotoshu::Language::Segmenter#segment.
Carries the detected language_code, the text_nodes belonging
to the segment (in source order), and the confidence the
detector returned for the segment's text. Multi-language
checkers consume segments one at a time, resolving resources
per-language.
Instance Attribute Summary collapse
-
#confidence ⇒ Object
Returns the value of attribute confidence.
-
#language_code ⇒ Object
Returns the value of attribute language_code.
-
#text_nodes ⇒ Object
Returns the value of attribute text_nodes.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
True when no text nodes are in the segment.
-
#flattened_text ⇒ String
Concatenated flattened text of every node in this segment.
-
#length ⇒ Integer
Number of text nodes in this segment.
Instance Attribute Details
#confidence ⇒ Object
Returns the value of attribute confidence
13 14 15 |
# File 'lib/kotoshu/language/segmenter.rb', line 13 def confidence @confidence end |
#language_code ⇒ Object
Returns the value of attribute language_code
13 14 15 |
# File 'lib/kotoshu/language/segmenter.rb', line 13 def language_code @language_code end |
#text_nodes ⇒ Object
Returns the value of attribute text_nodes
13 14 15 |
# File 'lib/kotoshu/language/segmenter.rb', line 13 def text_nodes @text_nodes end |
Instance Method Details
#empty? ⇒ Boolean
True when no text nodes are in the segment.
31 32 33 |
# File 'lib/kotoshu/language/segmenter.rb', line 31 def empty? text_nodes.nil? || text_nodes.empty? end |
#flattened_text ⇒ String
Concatenated flattened text of every node in this segment.
17 18 19 |
# File 'lib/kotoshu/language/segmenter.rb', line 17 def flattened_text text_nodes.map(&:text).join end |
#length ⇒ Integer
Number of text nodes in this segment.
24 25 26 |
# File 'lib/kotoshu/language/segmenter.rb', line 24 def length text_nodes.length end |