Class: ParseComposition
- Inherits:
-
Object
- Object
- ParseComposition
- Defined in:
- lib/oddb2xml/parslet_compositions.rb
Constant Summary collapse
- ErrorsToFix =
{ /(\d+)\s+\-\s*(\d+)/ => '\1-\2', 'o.1' => '0.1', /\s+(mg|g) DER:/ => ' \1, DER:', ' mind. ' => ' min. ', ' streptococci pyogen. ' => ' streptococci pyogen ', ' ut excipiens' => ', excipiens', ' Corresp. ' => ' corresp. ', ',,' => ',', 'avena elatior,dactylis glomerata' => 'avena elatior, dactylis glomerata', ' color.: corresp. ' => ' corresp.', / U\.: (excipiens) / => ' U. \1 ', / U\.: (alnus|betula|betula|betulae) / => ' U., \1 ', /^(acari allergeni extractum (\(acarus siro\)|).+\s+U\.\:)/ => 'A): \1', }
- @@errorHandler =
ParseUtil::HandleSwissmedicErrors.new( ErrorsToFix )
Instance Attribute Summary collapse
-
#corresp ⇒ Object
Returns the value of attribute corresp.
-
#excipiens ⇒ Object
Returns the value of attribute excipiens.
-
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
-
#label ⇒ Object
Returns the value of attribute label.
-
#label_description ⇒ Object
Returns the value of attribute label_description.
-
#route_of_administration ⇒ Object
Returns the value of attribute route_of_administration.
-
#source ⇒ Object
Returns the value of attribute source.
-
#substances ⇒ Object
Returns the value of attribute substances.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source) ⇒ ParseComposition
constructor
A new instance of ParseComposition.
Constructor Details
#initialize(source) ⇒ ParseComposition
Returns a new instance of ParseComposition.
350 351 352 353 354 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 350 def initialize(source) @substances ||= [] puts "ParseComposition.new from #{source.inspect} @substances #{@substances.inspect}" if VERBOSE_MESSAGES @source = source.to_s end |
Instance Attribute Details
#corresp ⇒ Object
Returns the value of attribute corresp.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def corresp @corresp end |
#excipiens ⇒ Object
Returns the value of attribute excipiens.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def excipiens @excipiens end |
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def galenic_form @galenic_form end |
#label ⇒ Object
Returns the value of attribute label.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def label @label end |
#label_description ⇒ Object
Returns the value of attribute label_description.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def label_description @label_description end |
#route_of_administration ⇒ Object
Returns the value of attribute route_of_administration.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def route_of_administration @route_of_administration end |
#source ⇒ Object
Returns the value of attribute source.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def source @source end |
#substances ⇒ Object
Returns the value of attribute substances.
331 332 333 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 331 def substances @substances end |
Class Method Details
.from_string(string) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 361 def ParseComposition.from_string(string) return nil if string == nil or string.eql?('.') or string.eql?('') stripped = string.gsub(/^"|["\n]+$/, '') return nil unless stripped if /(U\.I\.|U\.)$/.match(stripped) cleaned = stripped else cleaned = stripped.sub(/[\.]+$/, '') end value = nil puts "ParseComposition.from_string #{string}" if VERBOSE_MESSAGES # /ng-tr/.match(Socket.gethostbyname(Socket.gethostname).first) cleaned = @@errorHandler.apply_fixes(cleaned) puts "ParseComposition.new cleaned #{cleaned}" if VERBOSE_MESSAGES and not cleaned.eql?(stripped) CompositionTransformer.clear_substances result = ParseComposition.new(cleaned) parser3 = CompositionParser.new transf3 = CompositionTransformer.new begin if defined?(RSpec) ast = transf3.apply(parser3.parse_with_debug(cleaned)) puts "#{File.basename(__FILE__)}:#{__LINE__}: ==> " if VERBOSE_MESSAGES pp ast if VERBOSE_MESSAGES else ast = transf3.apply(parser3.parse(cleaned)) end rescue Parslet::ParseFailed => error @@errorHandler.nrParsingErrors += 1 puts "#{File.basename(__FILE__)}:#{__LINE__}: failed parsing ==> #{cleaned}" return nil end result.source = string return result unless ast return result if ast.is_a?(Parslet::Slice) result.substances = CompositionTransformer.substances result.excipiens = CompositionTransformer.excipiens result.corresp = CompositionTransformer.corresp if CompositionTransformer.corresp if result.excipiens and result.excipiens.unit pro_qty = "/#{result.excipiens.qty} #{result.excipiens.unit}".sub(/\/1\s+/, '/') result.substances.each { |substance| next unless substance.is_a?(ParseSubstance) substance.chemical_substance.unit = "#{substance.chemical_substance.unit}#{pro_qty}" if substance.chemical_substance substance.dose.unit = "#{substance.dose.unit}#{pro_qty}" if substance.unit and not substance.unit.eql?(result.excipiens.unit) } end if ast.is_a?(Array) and ast.first.is_a?(Hash) label = ast.first[:label].to_s if ast.first[:label] label_description = ast.first[:label_description].to_s if ast.first[:label_description] elsif ast and ast.is_a?(Hash) label = ast[:label].to_s if ast[:label] label_description = ast[:label_description].to_s if ast[:label_description] end if label if label and not /((A|B|C|D|E|I|II|III|IV|\)+)\s+et\s+(A|B|C|D|E|I|II|III|IV|\))+)/.match(label) result.label = label end result.label_description = label_description end return result end |
.report ⇒ Object
358 359 360 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 358 def ParseComposition.report @@errorHandler.report end |
.reset ⇒ Object
355 356 357 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 355 def ParseComposition.reset @@errorHandler = ParseUtil::HandleSwissmedicErrors.new( ErrorsToFix ) end |