Class: Kotoshu::Language::Segment

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#confidenceObject

Returns the value of attribute confidence

Returns:

  • (Object)

    the current value of confidence



13
14
15
# File 'lib/kotoshu/language/segmenter.rb', line 13

def confidence
  @confidence
end

#language_codeObject

Returns the value of attribute language_code

Returns:

  • (Object)

    the current value of language_code



13
14
15
# File 'lib/kotoshu/language/segmenter.rb', line 13

def language_code
  @language_code
end

#text_nodesObject

Returns the value of attribute text_nodes

Returns:

  • (Object)

    the current value of 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.

Returns:

  • (Boolean)


31
32
33
# File 'lib/kotoshu/language/segmenter.rb', line 31

def empty?
  text_nodes.nil? || text_nodes.empty?
end

#flattened_textString

Concatenated flattened text of every node in this segment.

Returns:

  • (String)


17
18
19
# File 'lib/kotoshu/language/segmenter.rb', line 17

def flattened_text
  text_nodes.map(&:text).join
end

#lengthInteger

Number of text nodes in this segment.

Returns:

  • (Integer)


24
25
26
# File 'lib/kotoshu/language/segmenter.rb', line 24

def length
  text_nodes.length
end