Class: EncodingEstimator::LanguageModel
- Inherits:
-
Object
- Object
- EncodingEstimator::LanguageModel
- Defined in:
- lib/encoding_estimator/language_model.rb
Overview
Class representing a language model. This can either be an internal model (provided by the gem) or an external one (user defined model).
Instance Method Summary collapse
-
#distribution ⇒ EncodingEstimator::Distribution
Load the distribution file into a distribution object.
-
#external? ⇒ Boolean
Check if this instance represents an external model file.
-
#initialize(language) ⇒ LanguageModel
constructor
Initialize a new object from a language file or an internal language profile.
-
#internal? ⇒ Boolean
Check if this instance represents an internal model file.
-
#path ⇒ String
Get the full (absolute) path to the language model file.
-
#valid? ⇒ Boolean
Check if the instance is a valid language model representation.
Constructor Details
#initialize(language) ⇒ LanguageModel
Initialize a new object from a language file or an internal language profile
14 15 16 |
# File 'lib/encoding_estimator/language_model.rb', line 14 def initialize( language ) @language = language end |
Instance Method Details
#distribution ⇒ EncodingEstimator::Distribution
Load the distribution file into a distribution object
53 54 55 |
# File 'lib/encoding_estimator/language_model.rb', line 53 def distribution @distribution ||= EncodingEstimator::Distribution.new( self ) end |
#external? ⇒ Boolean
Check if this instance represents an external model file
39 40 41 |
# File 'lib/encoding_estimator/language_model.rb', line 39 def external? !internal? end |
#internal? ⇒ Boolean
Check if this instance represents an internal model file
32 33 34 |
# File 'lib/encoding_estimator/language_model.rb', line 32 def internal? @language.is_a? Symbol end |
#path ⇒ String
Get the full (absolute) path to the language model file
46 47 48 |
# File 'lib/encoding_estimator/language_model.rb', line 46 def path @path ||= ( internal? ? internal_path : external_path ) end |
#valid? ⇒ Boolean
Check if the instance is a valid language model representation
21 22 23 24 25 26 27 |
# File 'lib/encoding_estimator/language_model.rb', line 21 def valid? if external? File.file? external_path else @language.to_s.size == 2 and File.file? internal_path end end |