Class: UnihanLang::ChineseScoreAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/unihan_lang/chinese_score_analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, chinese_processor, variant_mapping) ⇒ ChineseScoreAnalyzer

Returns a new instance of ChineseScoreAnalyzer.



7
8
9
10
11
12
13
14
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 7

def initialize(text, chinese_processor, variant_mapping)
  @text = text
  @chinese_processor = chinese_processor
  @variant_mapping = variant_mapping
  @traditional_score = 0
  @simplified_score = 0
  analyze
end

Instance Attribute Details

#simplified_scoreObject (readonly)

Returns the value of attribute simplified_score.



5
6
7
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 5

def simplified_score
  @simplified_score
end

#total_chineseObject (readonly)

Returns the value of attribute total_chinese.



5
6
7
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 5

def total_chinese
  @total_chinese
end

#traditional_scoreObject (readonly)

Returns the value of attribute traditional_score.



5
6
7
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 5

def traditional_score
  @traditional_score
end

Instance Method Details

#dominant_languageObject



16
17
18
19
20
21
22
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 16

def dominant_language
  return "Unknown" if total_chinese.zero?
  return "ZH_TW" if traditional_score > simplified_score
  return "ZH_CN" if simplified_score > traditional_score

  "Unknown"
end

#language_ratioObject



24
25
26
27
28
29
30
# File 'lib/unihan_lang/chinese_score_analyzer.rb', line 24

def language_ratio
  return :unknown if total_chinese != @text.length
  return :tw if traditional_score > simplified_score
  return :cn if simplified_score >= traditional_score

  :unknown
end