Class: ODDB::FiParse::MiniFi::Handler
- Inherits:
-
Rpdf2txt::ColumnHandler
- Object
- Rpdf2txt::ColumnHandler
- ODDB::FiParse::MiniFi::Handler
- Defined in:
- ext/fiparse/src/minifi.rb
Constant Summary collapse
- SECTION_HEADINGS =
%r{^(Indi[ck]ation |Dosierung:?$|Posologie:?$ |Wirksamkeit|Efficacit. |Unerw.nschte Wirkungen|Effets ind.sirables |Pharmakokinetik|Pharmacocin.tique |Interaktionen|Interactions |Kontraindikationen|Contre-?indications ) }uix
- HYPHEN =
/-$/u
- NAME_PTRN =
%r{ (?:Wirk?s?toffe?s: [^\(]*\((?<name>[^,\s®\(]+))(®|\(TM\)) | (?:(?:(?:(?:Impf|Wirk?)stoffe?s?) |(?:Zulassung\s*des\s*ersten[^:]+)): (?:\s+Informationen\s+zu)? \s*(?<name>[^,\s®\(]+(,?\s*ad\s*us\.\s*vet\.)?)) | ^(?:Zulassung\s*von\s*[,"„«]{1,2})(?<name>[^,"“»]+) }ux
Instance Attribute Summary collapse
-
#minifis ⇒ Object
readonly
Returns the value of attribute minifis.
Instance Method Summary collapse
- #clean! ⇒ Object
- #column_count ⇒ Object
- #create_document ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #new_font(font) ⇒ Object
- #send_column ⇒ Object
- #send_line_break ⇒ Object
- #send_page ⇒ Object
- #set_bold(font) ⇒ Object
- #start_page ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
34 35 36 37 38 |
# File 'ext/fiparse/src/minifi.rb', line 34 def initialize super('', '') @minifis = [] start_page end |
Instance Attribute Details
#minifis ⇒ Object (readonly)
Returns the value of attribute minifis.
12 13 14 |
# File 'ext/fiparse/src/minifi.rb', line 12 def minifis @minifis end |
Instance Method Details
#clean! ⇒ Object
39 40 41 42 43 44 |
# File 'ext/fiparse/src/minifi.rb', line 39 def clean! if(@chapter.respond_to?(:clean!)) @chapter.clean! @chapter = nil end end |
#column_count ⇒ Object
95 96 97 |
# File 'ext/fiparse/src/minifi.rb', line 95 def column_count 2 end |
#create_document ⇒ Object
45 46 47 48 |
# File 'ext/fiparse/src/minifi.rb', line 45 def create_document clean! @chapter = Text::Chapter.new end |
#new_font(font) ⇒ Object
49 50 51 52 |
# File 'ext/fiparse/src/minifi.rb', line 49 def new_font(font) set_bold(font) @font = font end |
#send_column ⇒ Object
53 54 55 56 |
# File 'ext/fiparse/src/minifi.rb', line 53 def send_column super set_bold(@font) end |
#send_line_break ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'ext/fiparse/src/minifi.rb', line 57 def send_line_break line = (@lines.last || []).join.strip case line when %r{^Zulassung eines( pflanzlichen)? Arzneimittels mit( einem)? neue[mn] Wirk?stoff}iu, %r{^Neuzulassung eines Medikamente?s mit( einem)? neue[mn] Wirkstoff}iu, %r{^(Erst)?Zulassung eines neuen (Impf|Wirk)stoffe?s}iu, %r{^Zulassung des ersten}iu, %r{^Zulassung von [,"„«]{1,2}}iu if(@reached_news) @current = {} @minifis.push(@current) @current[:de] = create_document end when %r{^Autorisation d.un (phyto)?m.dicament contenant un nouveau}iu, %r{^Autorisation d.livr.es? pour (un|de) nouveaux? principes? actifs?}iu, %r{^Autorisation d.livr.es? pour (un|de) nouveaux? produits? de vaccins?}iu, %r{^Autorisation d.un nouveau (principe actif|vaccin)}iu, %r{^Autorisation du premier}iu, %r{^Autorisation de [,"„«]{1,2}}iu, %r{^Autorisation d.(livr.e pour )?un m.dicament avec un nouveau}iu @current[:fr] = create_document if @current when %r{Arzneimittel Nachrichten( / M.dicaments)?$}u, %r{^M.dicaments$}u @reached_news = true #ignore when %r{Arzneimittel\s*Statistik\s*/\s*Miscellan.es}u, %r{Regulatory News / R.glementation}u, %r{Regulatory News}u, %r{Infosplitter(\s*/\s*En\s*vrac)?}u, %r{Richtigstellung}u, %r{Berichtigung}u, %r{Medizinprodukte(\s*/\s*Dispositifs m.dicaux)?}u, %r{Zulassung eines Tierarzneimittels}u, %r{Entlassung aus der Heilmittelkontrolle}u, %r{Mitteilung an die Fachpersonen}u, %r{Zum Vertrieb freigegebene Chargen}u, %r{^Heparinum natricum ad usum externum}u # dtstcpw for 02/2006 clean! @current = nil end super end |
#send_page ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'ext/fiparse/src/minifi.rb', line 98 def send_page if(@chapter) max_idx = @lines.collect { |line| line.size }.push(1).max - 1 @lines.each { |line| line[max_idx] ||= nil } target, section = nil if(@chapter.empty?) target = @chapter.heading section = @chapter.next_section else section = @chapter.sections.last target = section.paragraphs.last || section.next_paragraph end previous_was_hyphenated = false row = 0 @lines.transpose.each_with_index { |column, col| previous_width = nil column.each_with_index { |line, row| if(line.is_a?(String)) line.gsub!(/\s+/, ' ') line.strip! case line when '' if(!target.empty? && !previous_was_hyphenated) if(section.subheading.empty?) section = @chapter.next_section end target = section.next_paragraph end when %r{Arzneimittel Nachrichten( / M.dicaments)?}u, %r{^\s*/?\s*M.dicaments$}u, %r{^Actualit.s$}u, # misplaced header in 05/2003:416 %r{^Arzneimittel Statistik$}u #ignore when %r{Swissmedic\s*Journal\s+[_\d]+}u, %r{^\d+$}u target = section.next_paragraph else bold = @bold_lines[col][row] title = [@chapter.heading, section.subheading].any? { |ttl| ttl.equal?(target) } if(bold && !previous_was_hyphenated \ && (!title || (target == @chapter.heading \ && SECTION_HEADINGS.match(line)))) section = @chapter.next_section target = section.subheading elsif(!bold && title) target << "\n" target = section.next_paragraph elsif(/^[o·-]\s/u.match(line)) target = section.next_paragraph elsif(!title && previous_width \ && previous_width < (line.length * 0.65)) target = section.next_paragraph end previous_width = line.length if(line.match(HYPHEN)) previous_was_hyphenated = true if(!((nxt = column.at(row.next)) \ && /^[A-Z]/u.match(nxt.to_s))) target << line.gsub(HYPHEN, '') else target << line end else previous_was_hyphenated = false target << line << ' ' end # Ensure all bold text at the start of a page counts # towards the heading - this solution works post 12/2005 if bold && target == @chapter.heading \ && (other = @lines[row][1]) target << other other.replace '' end end elsif(@chapter.heading == target && NAME_PTRN.match(target)) target = section.next_paragraph end } } if(match = NAME_PTRN.match(@chapter.heading)) @current[:name] = match['name'] end end start_page send_line_break end |
#set_bold(font) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'ext/fiparse/src/minifi.rb', line 187 def set_bold(font) line = @columns[@current_column].to_s bold = @bold_lines[@current_column] prev = (@lines[-2] || [])[@current_column] if(font && font.bold? \ && (bold[@lines.size - 1] || line.empty? \ || SECTION_HEADINGS.match(line))) bold[@lines.size - 1] = true elsif(!(font && font.symbol?)) bold[@lines.size - 1] = false end end |