Class: Kotoshu::Readers::LookupBuilder
- Inherits:
-
Object
- Object
- Kotoshu::Readers::LookupBuilder
- Defined in:
- lib/kotoshu/readers/lookup_builder.rb
Overview
Builder for creating Lookup::Lookuper instances from Hunspell data.
This class can either read from files or accept pre-read aff/dic data.
Constant Summary collapse
- DEFAULT_MAX_NGRAM_SUGS =
Hunspell upstream defaults for suggester directives. These apply when the .aff file is silent on the directive. See the Hunspell documentation at https://hunspell.github.io/ and the spylls
Affdefaults for reference. 4- DEFAULT_MAX_CPD_SUGS =
3- DEFAULT_MAX_DIFF =
5
Instance Attribute Summary collapse
-
#aff_data ⇒ Object
readonly
Returns the value of attribute aff_data.
-
#aff_path ⇒ Object
readonly
Returns the value of attribute aff_path.
-
#dic_path ⇒ Object
readonly
Returns the value of attribute dic_path.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
-
.from_data(aff_data, words) ⇒ LookupBuilder
Create a new LookupBuilder from pre-read data.
Instance Method Summary collapse
-
#build ⇒ Algorithms::Lookup::Lookuper
Build the Lookuper instance.
-
#initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin, aff_data: nil, words: nil) ⇒ LookupBuilder
constructor
Create a new LookupBuilder from file paths.
Constructor Details
#initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin, aff_data: nil, words: nil) ⇒ LookupBuilder
Create a new LookupBuilder from file paths.
41 42 43 44 45 46 47 48 49 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 41 def initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin, aff_data: nil, words: nil) @aff_path = aff_path @dic_path = dic_path @encoding = encoding @script = script @aff_data = aff_data @words = words end |
Instance Attribute Details
#aff_data ⇒ Object (readonly)
Returns the value of attribute aff_data.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def aff_data @aff_data end |
#aff_path ⇒ Object (readonly)
Returns the value of attribute aff_path.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def aff_path @aff_path end |
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def dic_path @dic_path end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def encoding @encoding end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def script @script end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
29 30 31 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 29 def words @words end |
Class Method Details
.from_data(aff_data, words) ⇒ LookupBuilder
Create a new LookupBuilder from pre-read data.
56 57 58 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 56 def self.from_data(aff_data, words) new(nil, nil, aff_data: aff_data, words: words) end |
Instance Method Details
#build ⇒ Algorithms::Lookup::Lookuper
Build the Lookuper instance.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 63 def build # Read files if data not already provided aff_data_to_use = @aff_data || read_aff_data words_to_use = @words || read_dic_data(aff_data_to_use) # Build the aff structure for Lookuper aff = build_aff_structure(aff_data_to_use) # Build the dic structure for Lookuper. Dictionary `ph:` morph data # is a source of REP entries (Hunspell 1.7+), so build_dic_structure # also enriches aff[:REP] — see PhRepExtractor. dic = build_dic_structure(words_to_use, aff: aff) # Create and return the Lookuper Algorithms::Lookup::Lookuper.new(aff, dic) end |