Module: Kumi::Core::Functions::Loader
- Defined in:
- lib/kumi/core/functions/loader.rb
Class Method Summary collapse
- .build_function_spec(fn_hash) ⇒ Object
- .load_file(file_path) ⇒ Object
- .load_minimal_functions ⇒ Object
- .parse_constraint_semantics(semantics_hash) ⇒ Object
Class Method Details
.build_function_spec(fn_hash) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kumi/core/functions/loader.rb', line 31 def build_function_spec(fn_hash) function_id = fn_hash.fetch("id") function_kind = fn_hash.fetch("kind").to_sym parameter_names = (fn_hash["params"] || []).map { |p| p["name"].to_sym } dtype_rule_fn = TypeRules.compile_dtype_rule(fn_hash.fetch("dtype"), parameter_names) constraint_semantics = parse_constraint_semantics(fn_hash["constraint_semantics"]) Functions::FunctionSpec.new( id: function_id, kind: function_kind, parameter_names: parameter_names, dtype_rule: dtype_rule_fn, constraint_semantics: constraint_semantics ) end |
.load_file(file_path) ⇒ Object
26 27 28 29 |
# File 'lib/kumi/core/functions/loader.rb', line 26 def load_file(file_path) doc = YAML.safe_load_file(file_path, permitted_classes: [], aliases: false) || {} (doc["functions"] || []).map { |fn_hash| build_function_spec(fn_hash) } end |
.load_minimal_functions ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kumi/core/functions/loader.rb', line 13 def load_minimal_functions functions_root = File.("../../../../data/functions", __dir__) yaml_files = Dir.glob(File.join(functions_root, "**/*.yaml")) function_specs = {} yaml_files.each do |file| specs = load_file(file) specs.each { |spec| function_specs[spec.id] = spec } end function_specs end |
.parse_constraint_semantics(semantics_hash) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kumi/core/functions/loader.rb', line 47 def parse_constraint_semantics(semantics_hash) return nil unless semantics_hash { domain_effect: semantics_hash["domain_effect"]&.to_sym, pure_combiner: semantics_hash["pure_combiner"], commutativity: semantics_hash["commutativity"], associativity: semantics_hash["associativity"], identity: semantics_hash["identity"], forward_propagation: semantics_hash["forward_propagation"], reverse_propagation: semantics_hash["reverse_propagation"] } end |