Skip to content

Commit

Permalink
Remove all dependencies that the target of
Browse files Browse the repository at this point in the history
abstractions is a locally accessible database column.

Closes #33
Makes progress on #22
  • Loading branch information
mgurley committed Aug 14, 2014
1 parent 9940ffd commit b6e7171
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
38 changes: 21 additions & 17 deletions lib/abstractor/methods/models/abstractor_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,30 @@ def abstract_sentential_value(about, abstractor_abstraction, abstractor_abstract
abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
abstractor_object_value_ids = abstractor_abstraction_schema.abstractor_object_values.map(&:id)

adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
case adapter
when 'sqlserver'
abstractor_object_value_variants = Abstractor::AbstractorObjectValueVariant.where("abstractor_object_value_id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} LIKE ('%' + abstractor_object_value_variants.value + '%'))", abstractor_object_value_ids, source[:source_id]).all
when 'sqlite3'
abstractor_object_value_variants = Abstractor::AbstractorObjectValueVariant.where("abstractor_object_value_id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} LIKE ('%' || abstractor_object_value_variants.value || '%'))", abstractor_object_value_ids, source[:source_id]).all
when 'postgresql'
abstractor_object_value_variants = Abstractor::AbstractorObjectValueVariant.where("abstractor_object_value_id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} ILIKE ('%' || abstractor_object_value_variants.value || '%'))", abstractor_object_value_ids, source[:source_id]).all
abstractor_object_values = []
abstractor_object_value_variants = []
target_abstractor_object_values =[]
target_abstractor_object_value_variants = Abstractor::AbstractorObjectValueVariant.where("abstractor_object_value_id in (?)", abstractor_object_value_ids)

at = nil
at = abstractor_text.downcase unless abstractor_text.blank?
target_abstractor_object_value_variants.each do |abstractor_object_value_variant|
re = Regexp.new(Regexp.escape(abstractor_object_value_variant.value.downcase))
if re =~ at
abstractor_object_value_variants << abstractor_object_value_variant
abstractor_object_values << abstractor_object_value_variant.abstractor_object_value
target_abstractor_object_value_variants.delete_if { |aovv| aovv.abstractor_object_value.id == abstractor_object_value_variant.abstractor_object_value.id }
end
end

abstractor_object_values = abstractor_object_value_variants.map(&:abstractor_object_value).uniq
target_abstractor_object_values = abstractor_abstraction_schema.abstractor_object_values
target_abstractor_object_values = target_abstractor_object_values - abstractor_object_values

adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
case adapter
when 'sqlserver'
abstractor_object_values.concat(Abstractor::AbstractorObjectValue.where("abstractor_object_values.id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} LIKE ('%' + abstractor_object_values.value + '%'))", abstractor_object_value_ids, source[:source_id]).all).uniq
when 'sqlite3'
abstractor_object_values.concat(Abstractor::AbstractorObjectValue.where("abstractor_object_values.id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} LIKE ('%' || abstractor_object_values.value || '%'))", abstractor_object_value_ids, source[:source_id]).all).uniq
when 'postgresql'
abstractor_object_values.concat(Abstractor::AbstractorObjectValue.where("abstractor_object_values.id in (?) AND EXISTS (SELECT 1 FROM #{source[:source_type].table_name} WHERE #{source[:source_type].table_name}.id = ? AND #{source[:source_type].table_name}.#{source[:source_method]} ILIKE ('%' || abstractor_object_values.value || '%'))", abstractor_object_value_ids, source[:source_id]).all).uniq
target_abstractor_object_values.each do |abstractor_object_value|
re = Regexp.new(Regexp.escape(abstractor_object_value.value.downcase))
if re =~ at
abstractor_object_values << abstractor_object_value
end
end

parser = Abstractor::Parser.new(abstractor_text)
Expand Down
4 changes: 2 additions & 2 deletions spec/models/abstractor/surgery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
@abstractor_abstraction_group = @surgery.reload.abstractor_abstraction_groups.select { |abstractor_abstraction_group| abstractor_abstraction_group.abstractor_subject_group == @abstractor_subject_group }.first
end

it "to 'not applicable'", focus: true do
it "to 'not applicable'", focus: false do
@abstractor_abstraction_group.abstractor_abstractions.map(&:not_applicable).should == [nil, nil,]
Abstractor::AbstractorAbstraction.update_abstractor_abstraction_other_value(@abstractor_abstraction_group.abstractor_abstractions, Abstractor::Enum::ABSTRACTION_OTHER_VALUE_TYPE_NOT_APPLICABLE)
@abstractor_abstraction_group.reload.abstractor_abstractions.map(&:not_applicable).should == [true, true]
end

it "to 'unknown'", focus: true do
it "to 'unknown'", focus: false do
@abstractor_abstraction_group.abstractor_abstractions.map(&:unknown).should == [nil, nil]
Abstractor::AbstractorAbstraction.update_abstractor_abstraction_other_value(@abstractor_abstraction_group.abstractor_abstractions, Abstractor::Enum::ABSTRACTION_OTHER_VALUE_TYPE_UNKNOWN)
@abstractor_abstraction_group.reload.abstractor_abstractions.map(&:unknown).should == [true, true]
Expand Down

0 comments on commit b6e7171

Please sign in to comment.