Module: Yanagi::Rules

Defined in:
lib/yanagi/rules.rb

Constant Summary collapse

DATA_DIR =
File.expand_path("../../data", __dir__).freeze
CORPUS_FILES =

Policy rules ship with the gem. Corpus-derived data (the lexicon and the native-Ukrainian allowlist) is generated from a specific translation project and is NOT distributed: point YANAGI_DATA_DIR at a directory holding those files, or build them with yanagi lexicon build.

%w[lexicon.yml native_ua_allowlist.yml].freeze

Class Method Summary collapse

Class Method Details

.combinatorialObject



44
45
46
# File 'lib/yanagi/rules.rb', line 44

def self.combinatorial
  @combinatorial ||= load_yaml("combinatorial.yml")
end

.corpus_dirObject

Where corpus-derived files are read from. Defaults to the gem's data directory so a local checkout keeps working without configuration.



23
24
25
# File 'lib/yanagi/rules.rb', line 23

def self.corpus_dir
  ENV.fetch("YANAGI_DATA_DIR", DATA_DIR)
end

.data_dirObject



17
18
19
# File 'lib/yanagi/rules.rb', line 17

def self.data_dir
  DATA_DIR
end

.exceptionsObject



60
61
62
# File 'lib/yanagi/rules.rb', line 60

def self.exceptions
  @exceptions ||= load_yaml("exceptions.yml")
end

.exonymsObject



48
49
50
# File 'lib/yanagi/rules.rb', line 48

def self.exonyms
  @exonyms ||= load_yaml("exonyms.yml")
end

.lexiconObject



52
53
54
# File 'lib/yanagi/rules.rb', line 52

def self.lexicon
  @lexicon ||= load_yaml("lexicon.yml")
end

.load_yaml(filename) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/yanagi/rules.rb', line 32

def self.load_yaml(filename)
  path = path_for(filename)
  return {}.freeze unless File.exist?(path)

  data = YAML.safe_load_file(path, permitted_classes: [Symbol, Date], symbolize_names: true) || {}
  deep_freeze(data)
end

.mora_mapObject



40
41
42
# File 'lib/yanagi/rules.rb', line 40

def self.mora_map
  @mora_map ||= load_yaml("mora.yml")
end

.native_ua_allowlistObject



56
57
58
# File 'lib/yanagi/rules.rb', line 56

def self.native_ua_allowlist
  @native_ua_allowlist ||= load_yaml("native_ua_allowlist.yml")
end

.path_for(filename) ⇒ Object



27
28
29
30
# File 'lib/yanagi/rules.rb', line 27

def self.path_for(filename)
  dir = CORPUS_FILES.include?(filename) ? corpus_dir : DATA_DIR
  File.join(dir, filename)
end

.reload!Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/yanagi/rules.rb', line 64

def self.reload!
  @mutex.synchronize do
    @mora_map = nil
    @combinatorial = nil
    @exonyms = nil
    @lexicon = nil
    @native_ua_allowlist = nil
    @exceptions = nil
  end
end