module Abstractor::NegationDetection
Public Class Methods
clear_invalid_utf8_bytes(scoped_sentence)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/abstractor/negation_detection.rb, line 39 def self.parse(sentence) `java lingscope.drivers.SentenceTagger scope crf #{File.expand_path('../../', __FILE__)}/lingscope/negation_models/crf_scope_words_all_both.model "#{sentence}"` end
parse_negation_scope(sentence)
click to toggle source
# 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