Class: UnihanLang::ChineseScoreAnalyzer
- Inherits:
-
Object
- Object
- UnihanLang::ChineseScoreAnalyzer
- Defined in:
- lib/unihan_lang/chinese_score_analyzer.rb
Instance Attribute Summary collapse
-
#simplified_score ⇒ Object
readonly
Returns the value of attribute simplified_score.
-
#total_chinese ⇒ Object
readonly
Returns the value of attribute total_chinese.
-
#traditional_score ⇒ Object
readonly
Returns the value of attribute traditional_score.
Instance Method Summary collapse
- #dominant_language ⇒ Object
-
#initialize(text, chinese_processor, variant_mapping) ⇒ ChineseScoreAnalyzer
constructor
A new instance of ChineseScoreAnalyzer.
- #language_ratio ⇒ Object
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_score ⇒ Object (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_chinese ⇒ Object (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_score ⇒ Object (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_language ⇒ Object
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_ratio ⇒ Object
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 |