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', 'Solvens: alprostadilum' => 'alprostadilum', }
- @@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.
373 374 375 376 377 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 373 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.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def corresp @corresp end |
#excipiens ⇒ Object
Returns the value of attribute excipiens.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def excipiens @excipiens end |
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def galenic_form @galenic_form end |
#label ⇒ Object
Returns the value of attribute label.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def label @label end |
#label_description ⇒ Object
Returns the value of attribute label_description.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def label_description @label_description end |
#route_of_administration ⇒ Object
Returns the value of attribute route_of_administration.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def route_of_administration @route_of_administration end |
#source ⇒ Object
Returns the value of attribute source.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def source @source end |
#substances ⇒ Object
Returns the value of attribute substances.
353 354 355 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 353 def substances @substances end |
Class Method Details
.from_string(string) ⇒ Object
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 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 384 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) parser = CompositionParser.new transf = CompositionTransformer.new begin if defined?(RSpec) ast = transf.apply(parser.parse_with_debug(cleaned)) puts "#{File.basename(__FILE__)}:#{__LINE__}: ==> " if VERBOSE_MESSAGES pp ast if VERBOSE_MESSAGES else ast = transf.apply(parser.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.gsub(/:+$/, '').strip if label_description end result.corresp = ast[:corresp].to_s.sub(/:\s+/, '') if not result.corresp and ast.is_a?(Hash) and ast[:corresp] return result end |
.report ⇒ Object
381 382 383 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 381 def ParseComposition.report @@errorHandler.report end |
.reset ⇒ Object
378 379 380 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 378 def ParseComposition.reset @@errorHandler = ParseUtil::HandleSwissmedicErrors.new( ErrorsToFix ) end |