Class: Openphar::Linkers::HerbapediaLinker
- Inherits:
-
Object
- Object
- Openphar::Linkers::HerbapediaLinker
- Defined in:
- lib/openphar/linkers/herbapedia_linker.rb
Overview
Links pharmacopoeia monographs to data-herbapedia entities
Instance Attribute Summary collapse
-
#ayurveda_profiles_index ⇒ Object
readonly
Returns the value of attribute ayurveda_profiles_index.
-
#preparations_index ⇒ Object
readonly
Returns the value of attribute preparations_index.
-
#tcm_profiles_index ⇒ Object
readonly
Returns the value of attribute tcm_profiles_index.
Instance Method Summary collapse
-
#find_ayurveda_profile(sanskrit:) ⇒ String?
Find an Ayurveda profile in data-herbapedia.
-
#find_preparation(latin_name:, chinese_name: nil) ⇒ String?
Find a HerbalPreparation in data-herbapedia.
-
#find_tcm_profile(pinyin:) ⇒ String?
Find a TCM profile in data-herbapedia.
-
#initialize(herbapedia_data_path: nil) ⇒ HerbapediaLinker
constructor
A new instance of HerbapediaLinker.
-
#link_monograph(monograph_data) ⇒ Hash
Link a monograph to herbapedia entities.
Constructor Details
#initialize(herbapedia_data_path: nil) ⇒ HerbapediaLinker
Returns a new instance of HerbapediaLinker.
9 10 11 12 13 14 15 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 9 def initialize(herbapedia_data_path: nil) @herbapedia_data_path = herbapedia_data_path @preparations_index = {} @tcm_profiles_index = {} @ayurveda_profiles_index = {} load_indexes if herbapedia_data_path end |
Instance Attribute Details
#ayurveda_profiles_index ⇒ Object (readonly)
Returns the value of attribute ayurveda_profiles_index.
7 8 9 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 7 def ayurveda_profiles_index @ayurveda_profiles_index end |
#preparations_index ⇒ Object (readonly)
Returns the value of attribute preparations_index.
7 8 9 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 7 def preparations_index @preparations_index end |
#tcm_profiles_index ⇒ Object (readonly)
Returns the value of attribute tcm_profiles_index.
7 8 9 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 7 def tcm_profiles_index @tcm_profiles_index end |
Instance Method Details
#find_ayurveda_profile(sanskrit:) ⇒ String?
Find an Ayurveda profile in data-herbapedia
51 52 53 54 55 56 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 51 def find_ayurveda_profile(sanskrit:) return nil if ayurveda_profiles_index.empty? normalized = normalize_name(sanskrit) ayurveda_profiles_index[normalized]&.dig(:iri) end |
#find_preparation(latin_name:, chinese_name: nil) ⇒ String?
Find a HerbalPreparation in data-herbapedia
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 21 def find_preparation(latin_name:, chinese_name: nil) return nil if preparations_index.empty? # Try exact Latin name match first normalized = normalize_name(latin_name) match = preparations_index[normalized] # Try Chinese name if no match if !match && chinese_name match = preparations_index.values.find do |prep| prep[:names]&.any? { |n| n[:zh] == chinese_name } end end match&.dig(:iri) end |
#find_tcm_profile(pinyin:) ⇒ String?
Find a TCM profile in data-herbapedia
41 42 43 44 45 46 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 41 def find_tcm_profile(pinyin:) return nil if tcm_profiles_index.empty? normalized = normalize_name() tcm_profiles_index[normalized]&.dig(:iri) end |
#link_monograph(monograph_data) ⇒ Hash
Link a monograph to herbapedia entities
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/openphar/linkers/herbapedia_linker.rb', line 61 def link_monograph(monograph_data) result = monograph_data.dup # Try to find preparation by Latin name latin_name = monograph_data[:name] || monograph_data.dig(:pref_label, "en") chinese_name = monograph_data.dig(:pref_label, "zh") || monograph_data.dig(:pref_label, "zh-Hant") if latin_name prep_iri = find_preparation(latin_name: latin_name, chinese_name: chinese_name) result[:references_preparation] = prep_iri if prep_iri end result end |