abstractor 1.0.23 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjVhYzRjMmQyYTc3MGFiNWQ4OWRkODQ1NmI2OTUyN2JkZTJjMmJlYg==
4
+ ZmI1ZTY3ZWJlZTU1MjhhNWU1MDYxZWNkNWQxMWE5YTUzOTlmYjM3NA==
5
5
  data.tar.gz: !binary |-
6
- OGQ2ODg1YTA4OTEwNTMzMGRiMmM0MzQzNjBlNWVlMDBjZGUxN2NmYQ==
6
+ M2YyMGQwOWFmMTRiYzdkZTRlY2IzOWFhNzAwYzIzYmU1MjUzMzdhMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzlhMjAxNTdhZGY4ODZmMjhkZGQzZTgyOTM3ZGJhNjIwZjUyYjYxZjA3OTVl
10
- M2ExNTRjNjhhZWRiZDA4Zjk2YWZiOTY3MDFhMWUyNzMyMTY5NmZkNGNlNWQz
11
- ZDZmNjY4YzhiZGFhZTNhNTJjNjEwNmU0OWM3YTEzOGJhMDg3NjE=
9
+ YTAxZDAyMzE0OTQ2YzYxYWE0OWY4ZmUyYzhmYzlkOWJjN2M1ZWE4YzcxZmE4
10
+ MDdiZTNjZDA1ZDljYTc3ZjJkZDZjNDY2ZDAwZTMxMGFiMzdjN2Y0NGRlYzk0
11
+ YTkwOTdmMjY5N2M3NjQ3ZDkxODYxZDRhOTI0ODE0ODRlYzQxMzY=
12
12
  data.tar.gz: !binary |-
13
- YjQzY2RjMjI3ZTAxZDlkNDdkMDk5MmI5ZjAwY2U1OGQ4YzM0MWZlZDIyODYy
14
- ODRkZjZhZWE1MWQ1NDlkM2YxYzBhNmZiM2YyM2Y1YTE3ZTRhYTBjNGE1NDZm
15
- YWZjMjhiN2E4Mjg4ZTRiMGMyNzNmYWExNTljNjcxMDBmMzA1ZTI=
13
+ YWM2YmE0MDI2ZmEzZjljMmU0OWVlMmE1MmQ5YTgzNzg3ZDk0Mzc0OTFlMWNk
14
+ YTA1M2JlMWZiY2QyZDU1ZGEwYjYxZWJiMzQ1NTg4ZmRhMTY2YWY0Mjc2Yzk4
15
+ YTU3YzdhNWUzMTk5NzgyMTY4ZmMzMDJlNzI3ZmRlZjM4MTE4Mzg=
@@ -71,6 +71,13 @@ Abstractor.AbstractionUI = function(){
71
71
  zIndex: 40000,
72
72
  dialogClass: "ui-dialog_abstractor"
73
73
  });
74
+
75
+ $(document).on('change', 'select.indirect_source_list', function () {
76
+ var source_type = $(this).attr('rel'),
77
+ value = $(this).find('option:selected').prop('value');
78
+ $(this).siblings('.indirect_source_text').hide();
79
+ $(this).siblings('.' + source_type + '_' + value).show();
80
+ });
74
81
  };
75
82
 
76
83
  Abstractor.AbstractionSuggestionUI = function(){
@@ -310,4 +310,24 @@ span.tooltip_img {
310
310
  }
311
311
  .abstractor_abstraction_actions a {
312
312
  margin: .25em;
313
+ }
314
+
315
+ .abstractor_abstraction_edit .indirect_source_list {
316
+ margin-bottom: 1em;
317
+ }
318
+
319
+ .indirect_sources label {
320
+ font-weight: bold !important;
321
+ }
322
+
323
+ .indirect_source_list {
324
+ width: 20em;
325
+ }
326
+
327
+ .indirect_source_text {
328
+ border: 1px solid #969696;
329
+ }
330
+
331
+ .indirect_source {
332
+ margin-bottom: 1em;
313
333
  }
@@ -1,6 +1,7 @@
1
1
  module Abstractor
2
2
  class AbstractorAbstraction < ActiveRecord::Base
3
3
  include Abstractor::Methods::Models::AbstractorAbstraction
4
- # @!parse extend Moo::ClassMethods
4
+ # @!parse include Abstractor::Methods::Models::AbstractorAbstraction::InstanceMethods
5
+ # @!parse extend Abstractor::Methods::Models::AbstractorAbstraction::ClassMethods
5
6
  end
6
7
  end
@@ -1,6 +1,5 @@
1
1
  module Abstractor
2
2
  class AbstractorAbstractionGroupMember < ActiveRecord::Base
3
3
  include Abstractor::Methods::Models::AbstractorAbstractionGroupMember
4
- # @!parse extend Moo::ClassMethods
5
4
  end
6
5
  end
@@ -0,0 +1,5 @@
1
+ module Abstractor
2
+ class AbstractorAbstractionSourceType < ActiveRecord::Base
3
+ include Abstractor::Methods::Models::AbstractorAbstractionSourceType
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Abstractor
2
+ class AbstractorIndirectSource < ActiveRecord::Base
3
+ include Abstractor::Methods::Models::AbstractorIndirectSource
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  module Abstractor
2
2
  class AbstractorSubject < ActiveRecord::Base
3
3
  include Abstractor::Methods::Models::AbstractorSubject
4
- # @!parse extend Moo::ClassMethods
4
+ # @!parse include Abstractor::Methods::Models::AbstractorSubject::InstanceMethods
5
5
  end
6
6
  end
@@ -57,7 +57,7 @@
57
57
  %hr
58
58
  - else
59
59
  .column-9
60
- - abstractor_abstraction.abstractor_subject.abstractor_abstraction_sources.each do |abstractor_abstraction_source|
60
+ - abstractor_abstraction.abstractor_subject.abstractor_abstraction_sources.select { |s| s.abstractor_abstraction_source_type.name == 'nlp suggestion' }.each do |abstractor_abstraction_source|
61
61
  - from_method = abstractor_abstraction_source.from_method
62
62
  - if about.respond_to?(from_method)
63
63
  %span{ :class => 'abstractor_abstraction_source_tooltip_img label', :rel => "#abstraction_text_#{abstractor_abstraction_source.id}", :title => "#{about.class.to_s} #{from_method}"}
@@ -43,10 +43,9 @@
43
43
  = f.label :unknown, 'unknown'
44
44
  .column-3
45
45
  - abstractor_abstraction = f.object
46
- - abstraction_sources = abstractor_abstraction.abstractor_subject.abstractor_abstraction_sources.reject{|s| s.from_method == 'unknown'}
46
+ - abstraction_sources = abstractor_abstraction.abstractor_subject.abstractor_abstraction_sources.select { |s| s.abstractor_abstraction_source_type.name == 'nlp suggestion' }
47
47
  - abstraction_sources.each do |abstraction_source|
48
48
  - from_method = abstraction_source.from_method
49
- -#%b= from_method.titleize
50
49
  %span{ :class => 'abstractor_abstraction_source_tooltip_img label', :rel => "#abstraction_text_#{abstraction_source.id}", :title => "#{abstractor_abstraction.about.class.to_s} #{from_method}"}
51
50
  = image_tag('abstractor/page.png', :id => "abstraction_text_link_#{abstraction_source.id}")
52
51
  %br
@@ -56,3 +55,19 @@
56
55
  = f.submit 'Save', :class => 'button positive'
57
56
  = link_to 'Cancel', abstractor_abstraction, :class => 'button negative', :remote => true
58
57
  .clear
58
+ .indirect_sources
59
+ - abstraction_sources = abstractor_abstraction.abstractor_subject.abstractor_abstraction_sources.select { |s| s.abstractor_abstraction_source_type.name == 'indirect' }
60
+ = f.fields_for :abstractor_indirect_sources, f.object.abstractor_indirect_sources do |abstractor_indirect_source_form|
61
+ .indirect_source
62
+ - abstraction_source = abstraction_sources.select { |abstraction_source| abstraction_source.id == abstractor_indirect_source_form.object.abstractor_abstraction_source_id }.first
63
+ - source_setup = abstractor_abstraction.about.send(abstraction_source.from_method)
64
+ - sources = source_setup[:sources].all
65
+ %label
66
+ Indirect Source:
67
+ = source_setup[:source_type].tableize.humanize
68
+ %br
69
+ = abstractor_indirect_source_form.select :source_id, sources.map{ |s| [s.send(source_setup[:source_name_method]), s.id] }, { :include_blank => 'None' }, :size => "#{sources.size + 1}", class: 'indirect_source_list', rel: "#{source_setup[:source_type]}"
70
+ - sources.each do |source|
71
+ - hidden = abstractor_indirect_source_form.object.source_id == source.id ? '' : 'hidden'
72
+ %div{ class: "indirect_source_text #{hidden} #{source_setup[:source_type]}_#{source.id}"}
73
+ = source.send(source_setup[:source_method])
@@ -0,0 +1,29 @@
1
+ class RefactorAbstractorRuleTypes < ActiveRecord::Migration
2
+ def up
3
+ create_table :abstractor_abstraction_source_types do |t|
4
+ t.string :name
5
+ t.datetime :deleted_at
6
+ t.timestamps
7
+ end
8
+
9
+ add_column :abstractor_abstraction_sources, :abstractor_abstraction_source_type_id, :integer
10
+ add_column :abstractor_abstraction_sources, :abstractor_rule_type_id, :integer
11
+ remove_column :abstractor_subjects, :abstractor_rule_type_id
12
+
13
+ create_table :abstractor_indirect_sources do |t|
14
+ t.integer :abstractor_abstraction_id
15
+ t.integer :abstractor_abstraction_source_id
16
+ t.string :source_type
17
+ t.integer :source_id
18
+ t.string :source_method
19
+ t.datetime :deleted_at
20
+ t.timestamps
21
+ end
22
+ end
23
+
24
+ def down
25
+ drop_table :abstractor_abstraction_source_types
26
+ remove_column :abstractor_abstraction_sources, :abstractor_abstraction_source_type_id
27
+ add_column :abstractor_subjects, :abstractor_rule_type_id, :integer
28
+ end
29
+ end
@@ -1,5 +1,7 @@
1
1
  module Abstractor
2
2
  module Abstractable
3
+ # @!parse include Abstractor::Abstractable::InstanceMethods
4
+ # @!parse extend Abstractor::Abstractable::ClassMethods
3
5
  def self.included(base)
4
6
  base.class_eval do
5
7
  has_many :abstractor_abstractions, class_name: Abstractor::AbstractorAbstraction, as: :about
@@ -66,16 +68,20 @@ module Abstractor
66
68
  end
67
69
 
68
70
  module ClassMethods
69
- def by_abstractor_suggestion_status(abstractor_suggestion_status)
70
- abstractor_suggestion_status_needs_review = Abstractor::AbstractorSuggestionStatus.where(:name => 'Needs review').first
71
- abstractor_suggestion_status_accepted= Abstractor::AbstractorSuggestionStatus.where(:name => 'Accepted').first
72
- abstractor_suggestion_status_rejected = Abstractor::AbstractorSuggestionStatus.where(:name => 'Rejected').first
73
-
74
- case abstractor_suggestion_status
71
+ ##
72
+ # Returns all abstractable entities filtered by the parameter abstractor_abstraction_status:
73
+ #
74
+ # * 'needs_review': Filter abstractable entites having at least one abstraction without a determined value (value, unknown or not_applicable).
75
+ # * 'reviewed': Filter abstractable entites having no abstractions without a determined value (value, unknown or not_applicable).
76
+ #
77
+ # @param [String] abstractor_abstraction_status Filter abstactable entities that an abstraction that 'needs_review' or are all abstractions are 'reviewed'.
78
+ # @return [ActiveRecord::Relation] List of abstractable entities.
79
+ def by_abstractor_abstraction_status(abstractor_abstraction_status)
80
+ case abstractor_abstraction_status
75
81
  when 'needs_review'
76
- where(["EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}' JOIN abstractor_suggestions aas ON aa.id = aas.abstractor_abstraction_id AND aas.abstractor_suggestion_status_id = ? WHERE #{self.table_name}.id = aa.about_id)", abstractor_suggestion_status_needs_review])
82
+ where(["EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}' WHERE #{self.table_name}.id = aa.about_id AND aa.value IS NULL AND (aa.unknown IS NULL OR aa.unknown = ?) AND (aa.not_applicable IS NULL OR aa.not_applicable = ?))", false, false])
77
83
  when 'reviewed'
78
- where(["EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}' JOIN abstractor_suggestions aas ON aa.id = aas.abstractor_abstraction_id WHERE #{self.table_name}.id = aa.about_id) AND NOT EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}' JOIN abstractor_suggestions aas ON aa.id = aas.abstractor_abstraction_id AND aas.abstractor_suggestion_status_id = ? WHERE #{self.table_name}.id = aa.about_id)", abstractor_suggestion_status_needs_review])
84
+ where(["EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}' WHERE #{self.table_name}.id = aa.about_id) AND NOT EXISTS (SELECT 1 FROM abstractor_subjects asb JOIN abstractor_abstractions aa ON asb.id = aa.abstractor_subject_id AND asb.subject_type = '#{self.to_s}'WHERE #{self.table_name}.id = aa.about_id AND aa.value IS NOT NULL AND aa.unknown != ? AND aa.not_applicable != ?)", true, true])
79
85
  else
80
86
  where(nil)
81
87
  end
@@ -11,19 +11,21 @@ module Abstractor
11
11
 
12
12
  base.send :has_many, :abstractor_suggestions
13
13
  base.send :has_many, :abstractor_abstraction_sources, :through => :abstractor_abstractor_suggestions
14
+ base.send :has_many, :abstractor_indirect_sources
14
15
 
15
16
  base.send :has_one, :abstractor_abstraction_group_member
16
17
  base.send :has_one, :abstractor_abstraction_group, :through => :abstractor_abstraction_group_member
17
18
  base.send :has_one, :abstractor_abstraction_schema, :through => :abstractor_subject
18
19
 
19
20
  base.send :accepts_nested_attributes_for, :abstractor_suggestions
21
+ base.send :accepts_nested_attributes_for, :abstractor_indirect_sources
20
22
 
21
23
  base.send :belongs_to, :about, polymorphic: true
22
24
 
23
- base.send :attr_accessible, :about, :abstractor_subject, :abstractor_subject_id, :value, :about_type, :about_id, :unknown, :not_applicable, :deleted_at
25
+ base.send :attr_accessible, :about, :abstractor_subject, :abstractor_subject_id, :value, :about_type, :about_id, :unknown, :not_applicable, :deleted_at, :abstractor_indirect_sources_attributes
24
26
 
25
27
  # Hooks
26
- base.send :after_save, :review_matching_suggestions#, :if => lambda {|abstractor_abstraction| abstractor_abstraction.value_changed?}
28
+ base.send :after_save, :review_matching_suggestions
27
29
 
28
30
  base.send(:include, InstanceMethods)
29
31
  base.extend(ClassMethods)
@@ -68,6 +70,19 @@ module Abstractor
68
70
  abstractor_suggestion_status_needs_review = Abstractor::AbstractorSuggestionStatus.where(name: 'Needs review').first
69
71
  abstractor_suggestions.any? { |abstractor_suggestion| abstractor_suggestion.abstractor_suggestion_status == abstractor_suggestion_status_needs_review }
70
72
  end
73
+
74
+ ##
75
+ # Detects if the abstraction already has an Abstractor::AbstractorIndirectSource based on the Abstractor::AbstractorAbstractionSource passed via the abstractor_abstraction_source parameter.
76
+ # Retuns it if present. Otherwise nil.
77
+ #
78
+ # @param [Abstractor::AbstractorAbstractionSource] abstractor_abstraction_source An instance of Abstractor::AbstractorAbstractionSource to check for the presence of an Abstractor::AbstractorIndirectSource.
79
+ # @return [Abstractor::AbstractorIndirectSource, nil]
80
+ def detect_abstractor_indirect_source(abstractor_abstraction_source)
81
+ abstractor_indirect_source = nil
82
+ abstractor_indirect_source = abstractor_indirect_sources(true).detect do |ais|
83
+ ais.abstractor_abstraction_source == abstractor_abstraction_source
84
+ end
85
+ end
71
86
  end
72
87
 
73
88
  module ClassMethods
@@ -7,10 +7,13 @@ module Abstractor
7
7
 
8
8
  # Associations
9
9
  base.send :belongs_to, :abstractor_subject
10
+ base.send :belongs_to, :abstractor_rule_type
11
+ base.send :belongs_to, :abstractor_abstraction_source_type
10
12
  base.send :has_many, :abstractor_suggestion_sources
11
13
  base.send :has_many, :abstractor_abstractions, :through => :abstractor_suggestion_sources
14
+ base.send :has_many, :abstractor_indirect_sources
12
15
 
13
- base.send :attr_accessible, :abstractor_subject, :abstractor_subject_id, :deleted_at, :from_method, :custom_method
16
+ base.send :attr_accessible, :abstractor_subject, :abstractor_subject_id, :deleted_at, :from_method, :custom_method, :abstractor_rule_type, :abstractor_rule_type_id, :abstractor_abstraction_source_type, :abstractor_abstraction_source_type_id
14
17
  end
15
18
 
16
19
  def normalize_from_method_to_sources(about)
@@ -0,0 +1,16 @@
1
+ module Abstractor
2
+ module Methods
3
+ module Models
4
+ module AbstractorAbstractionSourceType
5
+ def self.included(base)
6
+ base.send :include, SoftDelete
7
+
8
+ # Associations
9
+ base.send :has_many, :abstractor_abstraction_sources
10
+
11
+ base.send :attr_accessible, :deleted_at, :name
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Abstractor
2
+ module Methods
3
+ module Models
4
+ module AbstractorIndirectSource
5
+ def self.included(base)
6
+ base.send :include, SoftDelete
7
+
8
+ # Associations
9
+ base.send :belongs_to, :abstractor_abstraction_source
10
+ base.send :belongs_to, :abstractor_abstraction
11
+
12
+ base.send :attr_accessible, :abstractor_abstraction_id, :abstractor_abstraction, :abstractor_abstraction_source_id, :abstractor_abstraction_source, :source_type, :source_id, :source_method, :reviewed
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -6,7 +6,7 @@ module Abstractor
6
6
  base.send :include, SoftDelete
7
7
 
8
8
  # Associations
9
- base.send :has_many, :abstractor_subjects
9
+ base.send :has_many, :abstractor_abstraction_sources
10
10
 
11
11
  base.send :attr_accessible, :deleted_at, :description, :name, :abstractor_subjects
12
12
  end
@@ -6,7 +6,6 @@ module Abstractor
6
6
  base.send :include, SoftDelete
7
7
 
8
8
  # Associations
9
- base.send :belongs_to, :abstractor_rule_type
10
9
  base.send :belongs_to, :abstractor_abstraction_schema
11
10
 
12
11
  base.send :has_one, :abstractor_subject_group_member
@@ -19,119 +18,168 @@ module Abstractor
19
18
  base.send :has_many, :subject_relations, :class_name => "Abstractor::AbstractorSubjectRelation", :foreign_key => "subject_id"
20
19
 
21
20
 
22
- base.send :attr_accessible, :abstractor_abstraction_schema, :abstractor_abstraction_schema_id, :abstractor_rule_type, :abstractor_rule_type_id, :subject_type, :dynamic_list_method
21
+ base.send :attr_accessible, :abstractor_abstraction_schema, :abstractor_abstraction_schema_id, :subject_type, :dynamic_list_method
23
22
  base.send(:include, InstanceMethods)
24
23
  end
25
24
 
26
25
  module InstanceMethods
27
26
  ##
28
- # Creates or finds and instance of an Abstactor::AbstractorAbstraction.
27
+ # Creates or finds an instance of an Abstractor::AbstractorAbstraction.
29
28
  # The method will create instances of Abstractor::AbstractorSuggestion and
30
29
  # Abstractor::AbstractorSuggestionSource for the abstractable entity
31
30
  # passed via the about parameter.
32
31
  #
33
- # The Abstractor::AbstractorSubject#abstractor_rule_type attribute determines the abstraction strategy:
32
+ # The method cycles through each Abstractor::AbstractorAbstractionSource setup
33
+ # for the instance of the Abstractor::AbstractorSubject.
34
+ # The Abstractor::AbstractorSubject#abstractor_abstraction_source_type
35
+ # attribute determines the abstraction strategy:
36
+ #
37
+ # * 'nlp suggestion': creates instances of Abstractor::AbstractorSuggestion based on natural language processing (nlp) logic searching the text provided by the Abstractor::AbstractorSubject#from_methd attribute.
38
+ # * 'custom suggestion': creates instances of Abstractor::AbstractorSuggestion based on custom logic delegated to the method configured in AbstractorAbstractionSource#custom_method.
39
+ # * 'indirect': creates an instance of Abstractor::AbstractorIndirectSource wih null source_type, source_id, source_method attributes -- all waiting to be set upon selection of an indirect source.
40
+ #
41
+ # @param [ActiveRecord::Base] about The entity to abstract. An instance of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
42
+ # @return [void]
43
+ def abstract(about)
44
+ abstractor_abstraction = about.find_or_create_abstractor_abstraction(abstractor_abstraction_schema, self)
45
+
46
+ abstractor_abstraction_sources.each do |abstractor_abstraction_source|
47
+ case abstractor_abstraction_source.abstractor_abstraction_source_type.name
48
+ when 'nlp suggestion'
49
+ abstract_nlp_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
50
+ when 'custom suggestion'
51
+ abstract_custom_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
52
+ when 'indirect'
53
+ abstract_indirect_source(about, abstractor_abstraction, abstractor_abstraction_source)
54
+ end
55
+ end
56
+ end
57
+
58
+ ##
59
+ # Creates an instance of Abstractor::AbstractorIndirectSource -- if one does not already exist --
60
+ # for the abstractor_abstraction and abstraction_source parameters.
61
+ # An 'indirect' Abstractor::AbstractorAbstractionSources give developers
62
+ # the ability to define a pool of documents that are indrectly related to an
63
+ # abstraction. The developer is responsible for implementing a
64
+ # method on the abstractable enttiy specified in Abstractor::AbstractorAbstractionSource#from_method.
65
+ # The method should return a hash with the following keys populated:
66
+ #
67
+ # * [Array<ActiveRecord::Base>] :sources An array of active record objects that constitute the list of indirect sources.
68
+ # * [Symbol] :source_id A method specifying the primary key of each member in sources.
69
+ # * [Symbol] :source_method A method specifying the source text of each member in sources.
70
+ #
71
+ # @param [ActiveRecord::Base] about The entity to abstract. An instance of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
72
+ # @param [Abstractor::AbstractorAbstraction] abstractor_abstraction The instance of Abstractor::AbstractorAbstraction to insert an indirect source.
73
+ # @param [Abstractor::AbstractorAbstractionSource] abstractor_abstraction_source The instance of the Abstractor::AbstractorAbstractionSource that provides the indirec source.
74
+ # @return [void]
75
+ def abstract_indirect_source(about, abstractor_abstraction, abstractor_abstraction_source)
76
+ if !abstractor_abstraction.detect_abstractor_indirect_source(abstractor_abstraction_source)
77
+ source = about.send(abstractor_abstraction_source.from_method)
78
+ abstractor_abstraction.abstractor_indirect_sources.build(abstractor_abstraction_source: abstractor_abstraction_source, source_type: source[:source_type], source_method: source[:source_method])
79
+ abstractor_abstraction.save!
80
+ end
81
+ end
82
+
83
+ ##
84
+ # Creates instances of Abstractor::AbstractorSuggestion and Abstractor::AbstractorSuggestionSource
85
+ # based on natural languange processing (nlp).
86
+ #
87
+ # The Abstractor::AbstractorSubject#abstractor_rule_type attribute determines the nlp strategy to employ:
34
88
  #
35
89
  # * 'name/value': attempts to search for non-negated sentences mentioning of an Abstractor::AbstractorAbstractionSchema#predicate and an Abstractor::AbstractorObjectValue
36
90
  # * 'value': attempts to search for non-negated sentences mentioning an Abstractor::AbstractorObjectValue
37
91
  # * 'unknown': will automatically create an 'unknown' Abstractor::AbstractorSuggestion
38
- # * 'custom': will create instances of Abstractor::AbstractorSuggestion based on custom logic delegated to the method on the about parameter configured in AbstractorAbstractionSource#custom_method
39
92
  #
40
- # @param [ActiveRecord::Base] about the entity abstract. An instnace of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
93
+ # @param [ActiveRecord::Base] about The entity to abstract. An instance of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
94
+ # @param [Abstractor::AbstractorAbstraction] abstractor_abstraction The instance of Abstractor::AbstractorAbstraction to make suggestions against.
95
+ # @param [Abstractor::AbstractorAbstractionSource] abstractor_abstraction_source The instance of the Abstractor::AbstractorAbstractionSource that provides the rule type and from method to make nlp suggestions.
41
96
  # @return [void]
42
- def abstract(about)
43
- abstractor_abstraction = about.find_or_create_abstractor_abstraction(abstractor_abstraction_schema, self)
44
- case abstractor_rule_type.name
97
+
98
+ def abstract_nlp_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
99
+ case abstractor_abstraction_source.abstractor_rule_type.name
45
100
  when 'name/value'
46
- abstract_name_value(about, abstractor_abstraction)
101
+ abstract_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
47
102
  when 'value'
48
- abstract_value(about, abstractor_abstraction)
103
+ abstract_value(about, abstractor_abstraction, abstractor_abstraction_source)
49
104
  when 'unknown'
50
- abstract_unknown(about, abstractor_abstraction)
51
- when 'custom'
52
- abstract_custom(about, abstractor_abstraction)
105
+ abstract_unknown(about, abstractor_abstraction, abstractor_abstraction_source)
53
106
  end
54
107
  end
55
108
 
56
- # Cycle through instances of Abstractor::AbstractorSuggestionSources
57
- # --each time calling the method on the about paramter configured by
58
- # the AbstractorAbstractionSource#custom_method attribute.
59
- # Setting up an Abstractor::AbstractorSubject with a
60
- # 'custom' rule type obligates the developer to implement an instance
109
+ # Creates instances of Abstractor::AbstractorSuggestion and Abstractor::AbstractorSuggestionSource
110
+ # based on calling the method configured by the AbstractorAbstractionSource#custom_method attribute.
111
+ # The method is called on the abstractable entity passed via the about parameter.
112
+ #
113
+ # Setting up an Abstractor::AbstractorSubject with an AbstractorAbstractionSource
114
+ # with an AbstractorAbstractionSource#abstractor_abstraction_source_type attribute
115
+ # set to 'custom suggestion' obligates the developer to implement an instance
61
116
  # method on the abstractable entitty to make suggestions as
62
- # appropriate. The 'custom' rule type is intened to faciliate a
63
- # way to generate suggestions in a completely customizable way.
117
+ # appropriate. The 'custom suggestion' source type is
118
+ # intended to faciliate the generation of suggestions in a customizable way.
64
119
  #
65
- # @param [ActiveRecord::Base] about the entity to abstraction
66
- # @param [Abstractor::AbstractorAbstraction] abstractor_abstraction the instance of an abstractor abstraction
120
+ # @param [ActiveRecord::Base] about The entity to abstract. An instance of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
121
+ # @param [Abstractor::AbstractorAbstraction] abstractor_abstraction The instance of Abstractor::AbstractorAbstraction to make suggestions against.
122
+ # @param [Abstractor::AbstractorAbstractionSource] abstractor_abstraction_source The instance of the Abstractor::AbstractorAbstractionSource that provides the custom method to invoke on the abstractable entity to make custom suggestions.
67
123
  # @return [void]
68
- def abstract_custom(about, abstractor_abstraction)
69
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
70
- suggested_values = about.send(abstractor_abstraction_source.custom_method)
71
- suggested_values.each do |suggested_value|
72
- suggest(abstractor_abstraction, abstractor_abstraction_source, nil, nil, about.id, about.class.to_s, abstractor_abstraction_source.from_method, suggested_value, nil, nil, abstractor_abstraction_source.custom_method)
73
- end
74
- create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
124
+ def abstract_custom_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
125
+ suggested_values = about.send(abstractor_abstraction_source.custom_method)
126
+ suggested_values.each do |suggested_value|
127
+ suggest(abstractor_abstraction, abstractor_abstraction_source, nil, nil, about.id, about.class.to_s, abstractor_abstraction_source.from_method, suggested_value, nil, nil, abstractor_abstraction_source.custom_method)
75
128
  end
129
+ create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
76
130
  end
77
131
 
78
- def abstract_unknown(about, abstractor_abstraction)
79
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
80
- create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
81
- end
132
+ def abstract_unknown(about, abstractor_abstraction, abstractor_abstraction_source)
133
+ create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
82
134
  end
83
135
 
84
- def abstract_value(about, abstractor_abstraction)
85
- abstract_sentential_value(about, abstractor_abstraction)
86
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
87
- create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
88
- end
136
+ def abstract_value(about, abstractor_abstraction, abstractor_abstraction_source)
137
+ abstract_sentential_value(about, abstractor_abstraction, abstractor_abstraction_source)
138
+ create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
89
139
  end
90
140
 
91
- def abstract_sentential_value(about, abstractor_abstraction)
92
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
93
- abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
94
- abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
95
- abstractor_object_value_ids = abstractor_abstraction_schema.abstractor_object_values.map(&:id)
96
-
97
- adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
98
- case adapter
99
- when 'sqlserver'
100
- 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
101
- when 'sqlite3'
102
- 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
103
- when 'postgresql'
104
- 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
105
- end
141
+ def abstract_sentential_value(about, abstractor_abstraction, abstractor_abstraction_source)
142
+ abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
143
+ abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
144
+ abstractor_object_value_ids = abstractor_abstraction_schema.abstractor_object_values.map(&:id)
106
145
 
107
- abstractor_object_values = abstractor_object_value_variants.map(&:abstractor_object_value).uniq
146
+ adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
147
+ case adapter
148
+ when 'sqlserver'
149
+ 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
150
+ when 'sqlite3'
151
+ 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
152
+ when 'postgresql'
153
+ 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
154
+ end
108
155
 
109
- adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
110
- case adapter
111
- when 'sqlserver'
112
- 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
113
- when 'sqlite3'
114
- 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
115
- when 'postgresql'
116
- 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
117
- end
156
+ abstractor_object_values = abstractor_object_value_variants.map(&:abstractor_object_value).uniq
118
157
 
119
- parser = Abstractor::Parser.new(abstractor_text)
120
- abstractor_object_values.each do |abstractor_object_value|
121
- object_variants(abstractor_object_value, abstractor_object_value_variants).each do |object_variant|
122
- ranges = parser.range_all(Regexp.escape(object_variant.downcase))
123
- if ranges.any?
124
- ranges.each do |range|
125
- sentence = parser.find_sentence(range)
126
- if sentence
127
- scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
128
- reject = (
129
- Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], object_variant) ||
130
- Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], object_variant)
131
- )
132
- if !reject
133
- suggest(abstractor_abstraction, abstractor_abstraction_source, object_variant.downcase, sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
134
- end
158
+ adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
159
+ case adapter
160
+ when 'sqlserver'
161
+ 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
162
+ when 'sqlite3'
163
+ 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
164
+ when 'postgresql'
165
+ 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
166
+ end
167
+
168
+ parser = Abstractor::Parser.new(abstractor_text)
169
+ abstractor_object_values.each do |abstractor_object_value|
170
+ object_variants(abstractor_object_value, abstractor_object_value_variants).each do |object_variant|
171
+ ranges = parser.range_all(Regexp.escape(object_variant.downcase))
172
+ if ranges.any?
173
+ ranges.each do |range|
174
+ sentence = parser.find_sentence(range)
175
+ if sentence
176
+ scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
177
+ reject = (
178
+ Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], object_variant) ||
179
+ Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], object_variant)
180
+ )
181
+ if !reject
182
+ suggest(abstractor_abstraction, abstractor_abstraction_source, object_variant.downcase, sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
135
183
  end
136
184
  end
137
185
  end
@@ -141,34 +189,30 @@ module Abstractor
141
189
  end
142
190
  end
143
191
 
144
- def abstract_name_value(about, abstractor_abstraction)
145
- abstract_canonical_name_value(about, abstractor_abstraction)
146
- abstract_sentential_name_value(about, abstractor_abstraction)
147
- create_unknown_abstractor_suggestion_name_only(about, abstractor_abstraction)
148
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
149
- create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
150
- end
192
+ def abstract_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
193
+ abstract_canonical_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
194
+ abstract_sentential_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
195
+ create_unknown_abstractor_suggestion_name_only(about, abstractor_abstraction, abstractor_abstraction_source)
196
+ create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
151
197
  end
152
198
 
153
- def abstract_canonical_name_value(about, abstractor_abstraction)
154
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
155
- abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
156
- abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
157
- parser = Abstractor::Parser.new(abstractor_text)
158
- abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
159
- abstractor_abstraction_schema.abstractor_object_values.each do |abstractor_object_value|
160
- abstractor_object_value.object_variants.each do |object_variant|
161
- match_value = "#{Regexp.escape(predicate_variant)}:\s*#{Regexp.escape(object_variant)}"
162
- matches = parser.scan(match_value, word_boundary: true).uniq
163
- matches.each do |match|
164
- suggest(abstractor_abstraction, abstractor_abstraction_source, match, match, source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
165
- end
199
+ def abstract_canonical_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
200
+ abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
201
+ abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
202
+ parser = Abstractor::Parser.new(abstractor_text)
203
+ abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
204
+ abstractor_abstraction_schema.abstractor_object_values.each do |abstractor_object_value|
205
+ abstractor_object_value.object_variants.each do |object_variant|
206
+ match_value = "#{Regexp.escape(predicate_variant)}:\s*#{Regexp.escape(object_variant)}"
207
+ matches = parser.scan(match_value, word_boundary: true).uniq
208
+ matches.each do |match|
209
+ suggest(abstractor_abstraction, abstractor_abstraction_source, match, match, source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
210
+ end
166
211
 
167
- match_value = "#{Regexp.escape(predicate_variant)}#{Regexp.escape(object_variant)}"
168
- matches = parser.scan(match_value, word_boundary: true).uniq
169
- matches.each do |match|
170
- suggest(abstractor_abstraction, abstractor_abstraction_source, match, match, source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
171
- end
212
+ match_value = "#{Regexp.escape(predicate_variant)}#{Regexp.escape(object_variant)}"
213
+ matches = parser.scan(match_value, word_boundary: true).uniq
214
+ matches.each do |match|
215
+ suggest(abstractor_abstraction, abstractor_abstraction_source, match, match, source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
172
216
  end
173
217
  end
174
218
  end
@@ -176,31 +220,29 @@ module Abstractor
176
220
  end
177
221
  end
178
222
 
179
- def abstract_sentential_name_value(about, abstractor_abstraction)
180
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
181
- abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
182
- abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
183
- parser = Abstractor::Parser.new(abstractor_text)
184
- abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
185
- ranges = parser.range_all(Regexp.escape(predicate_variant))
186
- if ranges.any?
187
- ranges.each do |range|
188
- sentence = parser.find_sentence(range)
189
- if sentence
190
- abstractor_abstraction_schema.abstractor_object_values.each do |abstractor_object_value|
191
- abstractor_object_value.object_variants.each do |object_variant|
192
- match = parser.match_sentence(sentence[:sentence], Regexp.escape(object_variant))
193
- if match
194
- scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
195
- reject = (
196
- Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], predicate_variant) ||
197
- Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], predicate_variant) ||
198
- Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], object_variant) ||
199
- Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], object_variant)
200
- )
201
- if !reject
202
- suggest(abstractor_abstraction, abstractor_abstraction_source, sentence[:sentence], sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
203
- end
223
+ def abstract_sentential_name_value(about, abstractor_abstraction, abstractor_abstraction_source)
224
+ abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
225
+ abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
226
+ parser = Abstractor::Parser.new(abstractor_text)
227
+ abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
228
+ ranges = parser.range_all(Regexp.escape(predicate_variant))
229
+ if ranges.any?
230
+ ranges.each do |range|
231
+ sentence = parser.find_sentence(range)
232
+ if sentence
233
+ abstractor_abstraction_schema.abstractor_object_values.each do |abstractor_object_value|
234
+ abstractor_object_value.object_variants.each do |object_variant|
235
+ match = parser.match_sentence(sentence[:sentence], Regexp.escape(object_variant))
236
+ if match
237
+ scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
238
+ reject = (
239
+ Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], predicate_variant) ||
240
+ Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], predicate_variant) ||
241
+ Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], object_variant) ||
242
+ Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], object_variant)
243
+ )
244
+ if !reject
245
+ suggest(abstractor_abstraction, abstractor_abstraction_source, sentence[:sentence], sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], abstractor_object_value, nil, nil, nil)
204
246
  end
205
247
  end
206
248
  end
@@ -253,27 +295,25 @@ module Abstractor
253
295
  suggested_value.instance_of?(Abstractor::AbstractorObjectValue)
254
296
  end
255
297
 
256
- def create_unknown_abstractor_suggestion_name_only(about, abstractor_abstraction)
257
- abstractor_abstraction_sources.each do |abstractor_abstraction_source|
258
- abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
259
- abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
260
- parser = Abstractor::Parser.new(abstractor_text)
261
- #Create an 'unknown' suggestion based on match name only if we have not made a suggstion
262
- if abstractor_abstraction.abstractor_suggestions(true).empty?
263
- abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
264
- ranges = parser.range_all(Regexp.escape(predicate_variant))
265
- if ranges
266
- ranges.each do |range|
267
- sentence = parser.find_sentence(range)
268
- if sentence
269
- scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
270
- reject = (
271
- Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], predicate_variant) ||
272
- Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], predicate_variant)
273
- )
274
- if !reject
275
- suggest(abstractor_abstraction, abstractor_abstraction_source, predicate_variant.downcase, sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], nil, true, nil, nil)
276
- end
298
+ def create_unknown_abstractor_suggestion_name_only(about, abstractor_abstraction, abstractor_abstraction_source)
299
+ abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
300
+ abstractor_text = source[:source_type].find(source[:source_id]).send(source[:source_method])
301
+ parser = Abstractor::Parser.new(abstractor_text)
302
+ #Create an 'unknown' suggestion based on match name only if we have not made a suggstion
303
+ if abstractor_abstraction.abstractor_suggestions(true).empty?
304
+ abstractor_abstraction_schema.predicate_variants.each do |predicate_variant|
305
+ ranges = parser.range_all(Regexp.escape(predicate_variant))
306
+ if ranges
307
+ ranges.each do |range|
308
+ sentence = parser.find_sentence(range)
309
+ if sentence
310
+ scoped_sentence = Abstractor::NegationDetection.parse_negation_scope(sentence[:sentence])
311
+ reject = (
312
+ Abstractor::NegationDetection.negated_match_value?(scoped_sentence[:scoped_sentence], predicate_variant) ||
313
+ Abstractor::NegationDetection.manual_negated_match_value?(sentence[:sentence], predicate_variant)
314
+ )
315
+ if !reject
316
+ suggest(abstractor_abstraction, abstractor_abstraction_source, predicate_variant.downcase, sentence[:sentence], source[:source_id], source[:source_type].to_s, source[:source_method], nil, true, nil, nil)
277
317
  end
278
318
  end
279
319
  end
@@ -1,7 +1,7 @@
1
1
  module Abstractor
2
2
  module Setup
3
3
  def self.system
4
- puts 'Setting up AbstractorObjectType'
4
+ puts 'Setting up Abstractor::AbstractorObjectType'
5
5
  Abstractor::AbstractorObjectType.find_or_create_by_value('list')
6
6
  Abstractor::AbstractorObjectType.find_or_create_by_value('number')
7
7
  Abstractor::AbstractorObjectType.find_or_create_by_value('boolean')
@@ -10,21 +10,24 @@ module Abstractor
10
10
  Abstractor::AbstractorObjectType.find_or_create_by_value('date')
11
11
  Abstractor::AbstractorObjectType.find_or_create_by_value('dynamic list')
12
12
 
13
- puts 'Setting up AbstractorRuleType'
13
+ puts 'Setting up Abstractor::AbstractorRuleType'
14
14
  Abstractor::AbstractorRuleType.find_or_create_by_name_and_description(name: 'name/value', description:'search for value associated with name')
15
- Abstractor::AbstractorRuleType.find_or_create_by_name_and_description(name:'name', description: 'search for name match')
16
15
  Abstractor::AbstractorRuleType.find_or_create_by_name_and_description(name:'value', description: 'search for value match')
17
16
  Abstractor::AbstractorRuleType.find_or_create_by_name_and_description(name: 'unknown', description: 'do not try to abstract, always assign "unknown"')
18
- Abstractor::AbstractorRuleType.find_or_create_by_name_and_description(name:'custom', description: 'use whatever from_method returns as a value')
19
17
 
20
- puts 'Setting up AbstractorSuggestionStatus'
18
+ puts 'Setting up Abstractor::AbstractorSuggestionStatus'
21
19
  Abstractor::AbstractorSuggestionStatus.find_or_create_by_name('Needs review')
22
20
  Abstractor::AbstractorSuggestionStatus.find_or_create_by_name('Accepted')
23
21
  Abstractor::AbstractorSuggestionStatus.find_or_create_by_name('Rejected')
24
22
 
25
- puts 'Setting up AbstractorRelationType'
23
+ puts 'Setting up Abstractor::AbstractorRelationType'
26
24
  Abstractor::AbstractorRelationType.find_or_create_by_name('member_of')
27
25
  Abstractor::AbstractorRelationType.find_or_create_by_name('preceded_by')
26
+
27
+ puts 'Setting up Abstractor::AbstractorAbstractionSourceType'
28
+ Abstractor::AbstractorAbstractionSourceType.find_or_create_by_name('nlp suggestion')
29
+ Abstractor::AbstractorAbstractionSourceType.find_or_create_by_name('custom suggestion')
30
+ Abstractor::AbstractorAbstractionSourceType.find_or_create_by_name('indirect')
28
31
  end
29
32
  end
30
33
  end
@@ -1,3 +1,3 @@
1
1
  module Abstractor
2
- VERSION = '1.0.23'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -63,13 +63,13 @@ module Abstractor
63
63
  insert_into_file("#{Rails.root}/config/environments/development.rb", :after => /::Application.configure do\n/) do
64
64
  ' StanfordCoreNLP.use :english
65
65
  StanfordCoreNLP.model_files = {}
66
- StanfordCoreNLP.jar_path = "#{Rails.root}/lib/stanford-corenlp-full-2014-01-04/"
67
- StanfordCoreNLP.model_path = "#{Rails.root}/lib/stanford-corenlp-full-2014-01-04/"
66
+ StanfordCoreNLP.jar_path = "#{Rails.root}/lib/stanford-corenlp-full-2014-06-16/"
67
+ StanfordCoreNLP.model_path = "#{Rails.root}/lib/stanford-corenlp-full-2014-06-16/"
68
68
  StanfordCoreNLP.default_jars = [
69
69
  "joda-time.jar",
70
70
  "xom.jar",
71
- "stanford-corenlp-3.3.1.jar",
72
- "stanford-corenlp-3.3.1-models.jar",
71
+ "stanford-corenlp-3.4.jar",
72
+ "stanford-corenlp-3.4-models.jar",
73
73
  "jollyday.jar",
74
74
  "bridge.jar"
75
75
  ]
@@ -8,20 +8,20 @@ namespace :abstractor do
8
8
  Abstractor::Setup.system
9
9
  end
10
10
 
11
- desc "Setup Stanford CoreNLP library in lib/stanford-corenlp-full-2014-01-04/ directory"
11
+ desc "Setup Stanford CoreNLP library in lib/stanford-corenlp-full-2014-06-16/ directory"
12
12
  task :stanford_core_nlp => :environment do
13
13
  puts 'Please be patient...This could take a while.'
14
- file = "#{Rails.root}/lib/stanford-corenlp-full-2014-01-04.zip"
14
+ file = "#{Rails.root}/lib/stanford-corenlp-full-2014-06-16.zip"
15
15
  open(file, 'wb') do |fo|
16
- fo.print open('http://nlp.stanford.edu/software/stanford-corenlp-full-2014-01-04.zip').read
16
+ fo.print open('http://nlp.stanford.edu/software/stanford-corenlp-full-2014-06-16.zip').read
17
17
  end
18
18
 
19
- file = "#{Rails.root}/lib/stanford-corenlp-full-2014-01-04.zip"
19
+ file = "#{Rails.root}/lib/stanford-corenlp-full-2014-06-16.zip"
20
20
  destination = "#{Rails.root}/lib/"
21
21
  puts 'Unzipping...'
22
22
  unzip_file(file, destination)
23
23
 
24
- file = "#{Rails.root}/lib/stanford-corenlp-full-2014-01-04/bridge.jar"
24
+ file = "#{Rails.root}/lib/stanford-corenlp-full-2014-06-16/bridge.jar"
25
25
  open(file, 'wb') do |fo|
26
26
  fo.print open('https://github.com/louismullie/stanford-core-nlp/blob/master/bin/bridge.jar?raw=true').read
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.23
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Gurley, Yulia Bushmanova
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -438,6 +438,8 @@ files:
438
438
  - app/models/abstractor/abstractor_abstraction_schema_predicate_variant.rb
439
439
  - app/models/abstractor/abstractor_abstraction_schema_relation.rb
440
440
  - app/models/abstractor/abstractor_abstraction_source.rb
441
+ - app/models/abstractor/abstractor_abstraction_source_type.rb
442
+ - app/models/abstractor/abstractor_indirect_source.rb
441
443
  - app/models/abstractor/abstractor_object_type.rb
442
444
  - app/models/abstractor/abstractor_object_value.rb
443
445
  - app/models/abstractor/abstractor_object_value_variant.rb
@@ -484,6 +486,7 @@ files:
484
486
  - db/migrate/20140618140759_add_custom_method_to_abstractor_abstraction_sources.rb
485
487
  - db/migrate/20140618140828_add_custom_method_to_abstractor_suggestion_sources.rb
486
488
  - db/migrate/20140716184049_add_dynamic_list_method_to_abstractor_subjects.rb
489
+ - db/migrate/20140718014952_refactor_abstractor_rule_types.rb
487
490
  - db/seeds.rb
488
491
  - lib/abstractor.rb
489
492
  - lib/abstractor/abstractable.rb
@@ -501,6 +504,8 @@ files:
501
504
  - lib/abstractor/methods/models/abstractor_abstraction_schema_predicate_variant.rb
502
505
  - lib/abstractor/methods/models/abstractor_abstraction_schema_relation.rb
503
506
  - lib/abstractor/methods/models/abstractor_abstraction_source.rb
507
+ - lib/abstractor/methods/models/abstractor_abstraction_source_type.rb
508
+ - lib/abstractor/methods/models/abstractor_indirect_source.rb
504
509
  - lib/abstractor/methods/models/abstractor_object_type.rb
505
510
  - lib/abstractor/methods/models/abstractor_object_value.rb
506
511
  - lib/abstractor/methods/models/abstractor_object_value_variant.rb