Class: Openphar::Parsers::JpJaHtmlParser
- Inherits:
-
JpHtmlParserBase
- Object
- JpHtmlParserBase
- Openphar::Parsers::JpJaHtmlParser
- Defined in:
- lib/openphar/parsers/jp_ja_html_parser.rb
Overview
Parser for Japanese (JA) Japan Pharmacopoeia HTML monographs
Parses JP monographs from Japanese HTML files where:
- class="s1" contains Japanese names
- class="s2" contains Latin names
- class="s5" contains section headers
- class="s3" contains content paragraphs
Japanese section headers:
- 生薬の性状 / 性状 - Macroscopic Description
- 顕微鏡的性状 - Microscopic Description
- 確認試験 - Identification
- 純度試験 - Purity
- 異物 - Foreign Matter
- 乾燥減量 - Loss on Drying
- 灰分 - Total Ash
- 酸不溶性灰分 - Acid Insoluble Ash
- エキス量 - Extractive
- 定量法 - Assay
- 貯法 - Storage
- 容器 - Container
Constant Summary collapse
- CRUDE_DRUG_SECTION_PATTERNS =
Japanese section patterns for crude drugs
{ definition: /(?:生薬の性状|性状|成分規格)/, macroscopic_description: /生薬の性状/, microscopic_description: /顕微鏡的性状/, identification: /確認試験/, purity: /純度試験/, foreign_matter: /異物/, loss_on_drying: /乾燥減量/, total_ash: /灰分/, acid_insoluble_ash: /酸不溶性灰分/, extractive: /エキス量/, assay: /定量法/, storage: /貯法/, container: /容器/ }.freeze
- CHEMICAL_DRUG_SECTION_PATTERNS =
Japanese section patterns for chemical drugs
{ specification: /成分規格/, description: /性状/, identification: /確認試験/, purity: /純度試験/, loss_on_drying: /乾燥減量/, residue_on_ignition: /強熱残分/, assay: /定量法/, storage: /貯法/ }.freeze
- JAPANESE_NAME_SELECTOR =
CSS selectors for Japanese HTML
"p.s1"- LATIN_NAME_SELECTOR =
"p.s2"- CONTENT_SELECTOR =
"p.s3"- SECTION_HEADER_CLASS =
"s5"- REFERENCE_PATTERN =
Reference marker patterns (Japanese uses 〈〉 instead of <>)
/〈([^〉]+)〉/
Instance Attribute Summary collapse
-
#monographs ⇒ Object
readonly
Returns the value of attribute monographs.
Attributes inherited from JpHtmlParserBase
Instance Method Summary collapse
-
#initialize(html_content, monograph_type: :crude_drug) ⇒ JpJaHtmlParser
constructor
Initialize parser with HTML content.
-
#parse ⇒ Array<Hash>
Parse all monographs from the document.
Methods inherited from JpHtmlParserBase
Constructor Details
#initialize(html_content, monograph_type: :crude_drug) ⇒ JpJaHtmlParser
Initialize parser with HTML content
71 72 73 74 75 76 77 78 79 |
# File 'lib/openphar/parsers/jp_ja_html_parser.rb', line 71 def initialize(html_content, monograph_type: :crude_drug) super(html_content) @monograph_type = monograph_type @section_patterns = if monograph_type == :crude_drug CRUDE_DRUG_SECTION_PATTERNS else CHEMICAL_DRUG_SECTION_PATTERNS end end |
Instance Attribute Details
#monographs ⇒ Object (readonly)
Returns the value of attribute monographs.
65 66 67 |
# File 'lib/openphar/parsers/jp_ja_html_parser.rb', line 65 def monographs @monographs end |
Instance Method Details
#parse ⇒ Array<Hash>
Parse all monographs from the document
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/openphar/parsers/jp_ja_html_parser.rb', line 84 def parse @monographs = [] current_monograph = nil # Iterate through all paragraph elements document.css("p").each do |paragraph| classes = paragraph.classes if classes.include?("s1") && monograph_name?(paragraph.text) # Start of a new monograph if current_monograph @monographs << current_monograph end current_monograph = start_new_monograph(paragraph) elsif current_monograph && classes.include?("s2") # Latin name follows Japanese name latin_name = extract_latin_name(paragraph.text) current_monograph[:latin_name] = latin_name if latin_name elsif current_monograph # Check for section headers (s5 class) if classes.include?(SECTION_HEADER_CLASS) current_section = detect_section(paragraph.text) current_monograph[:current_section] = current_section else # Content for current section add_content_to_section(current_monograph, paragraph.text) end end end # Don't forget the last monograph @monographs << current_monograph if current_monograph @monographs end |