Module: Abstractor::NegationDetection
- Defined in:
- lib/abstractor/negation_detection.rb
Class Method Summary collapse
- .clear_invalid_utf8_bytes(scoped_sentence) ⇒ Object
- .manual_negated_match_value?(sentence, match_value) ⇒ Boolean
- .negated_match_value?(scoped_sentence, match_value) ⇒ Boolean
- .parse(sentence) ⇒ Object
- .parse_negation_scope(sentence) ⇒ Object
Class Method Details
.clear_invalid_utf8_bytes(scoped_sentence) ⇒ Object
3 4 5 |
# File 'lib/abstractor/negation_detection.rb', line 3 def self.clear_invalid_utf8_bytes(scoped_sentence) scoped_sentence = scoped_sentence.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') end |
.manual_negated_match_value?(sentence, match_value) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/abstractor/negation_detection.rb', line 22 def self.manual_negated_match_value?(sentence, match_value) negated = false ['non-','\bthere is no evidence of a ', '\bthere is no evidence of a metastatic ', '\binsufficient to make the diagnosis of ', '\binsufficient to make the diagnosis of metastatic ', '\binsufficient for the diagnosis of ', '\binsufficient for the diagnosis of metastatic ', '\brule out ', '\brule out metastatic ', '\bnegative for ', '\bnegative for metastatic ', '\bno ', '\bno metastatic ', '\bnot ', '\bnot metastatic ', '\bno evidence of ', '\bno evidence of metastatic ', '\bno evidence of a ', '\bno evidence of a metastatic ', '\brules out the possibility of a ', '\brules out the possibility of a metastatic ', '\bto exclude the possibility of ', '\bto exclude the possibility of metastic '].each do |negation_cue| if !(sentence.downcase.scan(Regexp.new(negation_cue + match_value.downcase)).empty?) negated = true end end [' is not seen\b', ' less likely\b'].each do |negation_cue| if !(sentence.downcase.scan(Regexp.new(match_value.downcase + negation_cue)).empty?) negated = true end end negated end |
.negated_match_value?(scoped_sentence, match_value) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/abstractor/negation_detection.rb', line 16 def self.negated_match_value?(scoped_sentence, match_value) negated = !scoped_sentence.scan('|B-S').empty? && match_value.split(' ').all? do |match_value_token| !(scoped_sentence.scan(Regexp.new(match_value_token + '\|I-S')).empty?) end end |
.parse(sentence) ⇒ Object
39 40 41 |
# File 'lib/abstractor/negation_detection.rb', line 39 def self.parse(sentence) `java lingscope.drivers.SentenceTagger scope crf #{File.('../../', __FILE__)}/lingscope/negation_models/crf_scope_words_all_both.model "#{sentence}"` end |
.parse_negation_scope(sentence) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/abstractor/negation_detection.rb', line 7 def self.parse_negation_scope(sentence) parse_results = { :sentence => nil, :scoped_sentence => nil } if sentence parse_results[:sentence] = sentence parse_results[:scoped_sentence] = clear_invalid_utf8_bytes(NegationDetection.parse(sentence)) end parse_results end |