abstractor 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Rakefile +1 -5
- data/app/assets/javascripts/abstractor/abstractor.js +1 -1
- data/app/views/abstractor/abstractor_abstractions/_fields.html.haml +3 -3
- data/db/migrate/20140618140759_add_custom_method_to_abstractor_abstraction_sources.rb +5 -0
- data/db/migrate/20140618140828_add_custom_method_to_abstractor_suggestion_sources.rb +5 -0
- data/lib/abstractor/abstractable.rb +3 -4
- data/lib/abstractor/methods/models/abstractor_abstraction.rb +1 -1
- data/lib/abstractor/methods/models/abstractor_abstraction_source.rb +1 -1
- data/lib/abstractor/methods/models/abstractor_subject.rb +223 -172
- data/lib/abstractor/methods/models/abstractor_suggestion_source.rb +1 -1
- data/lib/abstractor/version.rb +1 -1
- metadata +4 -22
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDdjMTlhOGQ5ZDUwZTFiYzllM2VlMjJiMTlmN2Q1ZmM4MTExYmZkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDFiZTgwYWM3MjhjMTk4ZTc4MWVmNmNjYjMzMDRjY2YyZjM2Mjk4MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmE5Yzk3YzIzZjM1MTY1M2I4NjZmYTNlNzMwZTBmYjE2NGNhOTViYTBiZTgx
|
10
|
+
M2RkOTRhZmMwZjY2ZGZiODVhNGFlNjMyYWIwNWY3OWM1YWRkY2ZjZmI3OTY4
|
11
|
+
OGM1N2UzNjNjMmEyNDhmZDRlMDBhNDNkMjExNjk3MWE3ZDMwM2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWVhNWJiZGYxN2M5YWU3YzU5YmUyZDEwZWZlMWRhZDExMmVkOTdkMzQ0NTNl
|
14
|
+
ZmI0ZmU4NjZmZjY3NTUwYWM4ZDMyY2FlNWVhZDI2MTBjMmI3OGM0ZmRiN2Nh
|
15
|
+
ZWJmOGM4YmE5NWUwNzM0YjcwZDEyZDQ2YjAwMWQ3YWM4OTk5MmY=
|
data/Rakefile
CHANGED
@@ -4,7 +4,6 @@ begin
|
|
4
4
|
require 'cucumber/rake/task'
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
require 'rubygems/package_task'
|
7
|
-
require 'nubic/gem_tasks'
|
8
7
|
end
|
9
8
|
|
10
9
|
gemspec = eval(File.read('abstractor.gemspec'), binding, 'abstractor.gemspec')
|
@@ -27,7 +26,4 @@ namespace :cucumber do
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
task :cucumber => 'cucumber:features'
|
31
|
-
Nubic::GemTasks::DeployGemTask.new("pkg/#{gemspec.file_name}")
|
32
|
-
task "deploy:gem" => :repackage
|
33
|
-
Bundler::GemHelper.install_tasks
|
29
|
+
task :cucumber => 'cucumber:features'
|
@@ -74,7 +74,7 @@ Abstractor.AbstractionUI = function(){
|
|
74
74
|
};
|
75
75
|
|
76
76
|
Abstractor.AbstractionSuggestionUI = function(){
|
77
|
-
$(document).on('change', '
|
77
|
+
$(document).on('change', '.abstractor_suggestion_status_selection', function() {
|
78
78
|
$(this).closest('form').submit();
|
79
79
|
});
|
80
80
|
|
@@ -49,8 +49,9 @@
|
|
49
49
|
.column-3
|
50
50
|
- values = Abstractor::AbstractorSuggestionStatus.all.sort_by(&:name).map{|s| [s.name, s.id] }
|
51
51
|
- values.each do |value|
|
52
|
-
|
53
|
-
= f.
|
52
|
+
- id = "abstractor_suggestion_abstractor_suggestion_status_id_#{value.last}_#{abstractor_suggestion.id}"
|
53
|
+
= f.radio_button :abstractor_suggestion_status_id, value.last, id: id, class: 'abstractor_suggestion_status_selection'
|
54
|
+
= f.label :abstractor_suggestion_status_id, value.first, value: value.last, for: id
|
54
55
|
%br
|
55
56
|
= f.radio_button :abstractor_suggestion_status_id, '', {:style => 'display:none;' }
|
56
57
|
%hr
|
@@ -65,5 +66,4 @@
|
|
65
66
|
- abstractable_from_column = about.send(from_method)
|
66
67
|
- unless abstractable_from_column.nil?
|
67
68
|
= abstractable_from_column.clone
|
68
|
-
|
69
69
|
.clear
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Abstractor
|
2
2
|
module Abstractable
|
3
3
|
def self.included(base)
|
4
|
-
base.send(:include, InstanceMethods)
|
5
|
-
base.extend(ClassMethods)
|
6
4
|
base.class_eval do
|
7
5
|
has_many :abstractor_abstractions, class_name: Abstractor::AbstractorAbstraction, as: :about
|
8
6
|
|
@@ -10,6 +8,8 @@ module Abstractor
|
|
10
8
|
|
11
9
|
accepts_nested_attributes_for :abstractor_abstractions, allow_destroy: false
|
12
10
|
end
|
11
|
+
base.send(:include, InstanceMethods)
|
12
|
+
base.extend(ClassMethods)
|
13
13
|
end
|
14
14
|
|
15
15
|
module InstanceMethods
|
@@ -56,7 +56,7 @@ module Abstractor
|
|
56
56
|
if !only_unreviewed || (only_unreviewed && abstractor_abstraction.unreviewed?)
|
57
57
|
abstractor_abstraction.abstractor_suggestions.each do |abstractor_suggestion|
|
58
58
|
abstractor_suggestion.abstractor_suggestion_sources.destroy_all
|
59
|
-
abstractor_suggestion.abstractor_suggestion_object_value.destroy
|
59
|
+
abstractor_suggestion.abstractor_suggestion_object_value.destroy if abstractor_suggestion.abstractor_suggestion_object_value
|
60
60
|
abstractor_suggestion.destroy
|
61
61
|
end
|
62
62
|
abstractor_abstraction.destroy
|
@@ -89,7 +89,6 @@ module Abstractor
|
|
89
89
|
# @param [Hash] options the options to filter the objects returned
|
90
90
|
# @option options [Boolean] :grouped Filters the list of Abstactor::AbstractorSubject objects to grouped and non-grouped. Defaults to nil which returns all objects.
|
91
91
|
# @return ActiveRecord::Relation list of Abstactor::AbstractorSubject objects
|
92
|
-
|
93
92
|
def abstractor_subjects(options = {})
|
94
93
|
options = { grouped: nil }.merge(options)
|
95
94
|
subjects = Abstractor::AbstractorSubject.where(subject_type: self.to_s)
|
@@ -25,8 +25,8 @@ module Abstractor
|
|
25
25
|
# Hooks
|
26
26
|
base.send :after_save, :review_matching_suggestions#, :if => lambda {|abstractor_abstraction| abstractor_abstraction.value_changed?}
|
27
27
|
|
28
|
-
base.send :extend, ClassMethods
|
29
28
|
base.send(:include, InstanceMethods)
|
29
|
+
base.extend(ClassMethods)
|
30
30
|
end
|
31
31
|
|
32
32
|
module InstanceMethods
|
@@ -10,7 +10,7 @@ module Abstractor
|
|
10
10
|
base.send :has_many, :abstractor_suggestion_sources
|
11
11
|
base.send :has_many, :abstractor_abstractions, :through => :abstractor_suggestion_sources
|
12
12
|
|
13
|
-
base.send :attr_accessible, :abstractor_subject, :abstractor_subject_id, :deleted_at, :from_method
|
13
|
+
base.send :attr_accessible, :abstractor_subject, :abstractor_subject_id, :deleted_at, :from_method, :custom_method
|
14
14
|
end
|
15
15
|
|
16
16
|
def normalize_from_method_to_sources(about)
|
@@ -20,77 +20,118 @@ module Abstractor
|
|
20
20
|
|
21
21
|
|
22
22
|
base.send :attr_accessible, :abstractor_abstraction_schema, :abstractor_abstraction_schema_id, :abstractor_rule_type, :abstractor_rule_type_id, :subject_type
|
23
|
+
base.send(:include, InstanceMethods)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
module InstanceMethods
|
27
|
+
##
|
28
|
+
# Creates or finds and instance of an Abstactor::AbstractorAbstraction.
|
29
|
+
# The method will create instances of Abstractor::AbstractorSuggestion and
|
30
|
+
# Abstractor::AbstractorSuggestionSource for the abstractable entity
|
31
|
+
# passed via the about parameter.
|
32
|
+
#
|
33
|
+
# The Abstractor::AbstractorSubject#abstractor_rule_type attribute determines the abstraction strategy:
|
34
|
+
#
|
35
|
+
# * 'name/value': attempts to search for non-negated sentences mentioning of an Abstractor::AbstractorAbstractionSchema#predicate and an Abstractor::AbstractorObjectValue
|
36
|
+
# * 'value': attempts to search for non-negated sentences mentioning an Abstractor::AbstractorObjectValue
|
37
|
+
# * '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
|
+
#
|
40
|
+
# @param [ActiveRecord::Base] about the entity abstract. An instnace of the class specified in the Abstractor::AbstractorSubject#subject_type attribute.
|
41
|
+
# @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
|
45
|
+
when 'name/value'
|
46
|
+
abstract_name_value(about, abstractor_abstraction)
|
47
|
+
when 'value'
|
48
|
+
abstract_value(about, abstractor_abstraction)
|
49
|
+
when 'unknown'
|
50
|
+
abstract_unknown(about, abstractor_abstraction)
|
51
|
+
when 'custom'
|
52
|
+
abstract_custom(about, abstractor_abstraction)
|
53
|
+
end
|
35
54
|
end
|
36
|
-
end
|
37
55
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
61
|
+
# 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.
|
64
|
+
#
|
65
|
+
# @param [ActiveRecord::Base] about the entity to abstraction
|
66
|
+
# @param [Abstractor::AbstractorAbstraction] abstractor_abstraction the instance of an abstractor abstraction
|
67
|
+
# @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)
|
75
|
+
end
|
41
76
|
end
|
42
|
-
end
|
43
77
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
48
82
|
end
|
49
|
-
end
|
50
83
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
89
|
+
end
|
56
90
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
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
|
63
|
-
when 'postgresql'
|
64
|
-
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
|
65
|
-
end
|
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)
|
66
96
|
|
67
|
-
|
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
|
68
106
|
|
69
|
-
|
70
|
-
case adapter
|
71
|
-
when 'sqlserver'
|
72
|
-
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
|
73
|
-
when 'sqlite3'
|
74
|
-
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
|
75
|
-
when 'postgresql'
|
76
|
-
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
|
77
|
-
end
|
107
|
+
abstractor_object_values = abstractor_object_value_variants.map(&:abstractor_object_value).uniq
|
78
108
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
118
|
+
|
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
|
94
135
|
end
|
95
136
|
end
|
96
137
|
end
|
@@ -99,67 +140,67 @@ module Abstractor
|
|
99
140
|
end
|
100
141
|
end
|
101
142
|
end
|
102
|
-
end
|
103
143
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
110
151
|
end
|
111
|
-
end
|
112
152
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
126
166
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
131
172
|
end
|
132
173
|
end
|
133
174
|
end
|
134
175
|
end
|
135
176
|
end
|
136
177
|
end
|
137
|
-
end
|
138
178
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
163
204
|
end
|
164
205
|
end
|
165
206
|
end
|
@@ -170,59 +211,69 @@ module Abstractor
|
|
170
211
|
end
|
171
212
|
end
|
172
213
|
end
|
173
|
-
end
|
174
214
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
215
|
+
def suggest(abstractor_abstraction, abstractor_abstraction_source, match_value, sentence_match_value, source_id, source_type, source_method, suggested_value, unknown, not_applicable, custom_method)
|
216
|
+
match_value.strip! unless match_value.nil?
|
217
|
+
sentence_match_value.strip! unless sentence_match_value.nil?
|
218
|
+
if abstractor_object_value?(suggested_value)
|
219
|
+
abstractor_object_value = suggested_value
|
220
|
+
suggested_value = suggested_value.value
|
221
|
+
end
|
222
|
+
abstractor_suggestion = abstractor_abstraction.detect_abstractor_suggestion(suggested_value) unless suggested_value.nil?
|
223
|
+
if !abstractor_suggestion
|
224
|
+
abstractor_suggestion_status_needs_review = Abstractor::AbstractorSuggestionStatus.where(name: 'Needs review').first
|
225
|
+
abstractor_suggestion = Abstractor::AbstractorSuggestion.create(
|
226
|
+
abstractor_abstraction: abstractor_abstraction,
|
227
|
+
abstractor_suggestion_status: abstractor_suggestion_status_needs_review,
|
228
|
+
suggested_value: suggested_value,
|
229
|
+
unknown: unknown,
|
230
|
+
not_applicable: not_applicable
|
231
|
+
)
|
232
|
+
|
233
|
+
abstractor_suggestion.abstractor_suggestion_object_value = Abstractor::AbstractorSuggestionObjectValue.new(abstractor_object_value: abstractor_object_value) if abstractor_object_value
|
234
|
+
end
|
235
|
+
|
236
|
+
abstractor_suggestion_source = abstractor_suggestion.detect_abstractor_suggestion_source(abstractor_abstraction_source, sentence_match_value, source_id, source_type)
|
237
|
+
if !abstractor_suggestion_source
|
238
|
+
Abstractor::AbstractorSuggestionSource.create(
|
239
|
+
abstractor_abstraction_source: abstractor_abstraction_source,
|
240
|
+
abstractor_suggestion: abstractor_suggestion,
|
241
|
+
match_value: match_value,
|
242
|
+
sentence_match_value: sentence_match_value,
|
243
|
+
source_id: source_id,
|
244
|
+
source_type: source_type,
|
245
|
+
source_method: source_method,
|
246
|
+
custom_method: custom_method
|
247
|
+
)
|
248
|
+
end
|
249
|
+
abstractor_suggestion
|
189
250
|
end
|
190
251
|
|
191
|
-
|
192
|
-
|
193
|
-
Abstractor::AbstractorSuggestionSource.create(
|
194
|
-
abstractor_abstraction_source: abstractor_abstraction_source,
|
195
|
-
abstractor_suggestion: abstractor_suggestion,
|
196
|
-
match_value: match_value,
|
197
|
-
sentence_match_value: sentence_match_value,
|
198
|
-
source_id: source_id,
|
199
|
-
source_type: source_type,
|
200
|
-
source_method: source_method
|
201
|
-
)
|
252
|
+
def abstractor_object_value?(suggested_value)
|
253
|
+
suggested_value.instance_of?(Abstractor::AbstractorObjectValue)
|
202
254
|
end
|
203
|
-
abstractor_suggestion
|
204
|
-
end
|
205
255
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
226
277
|
end
|
227
278
|
end
|
228
279
|
end
|
@@ -231,27 +282,27 @@ module Abstractor
|
|
231
282
|
end
|
232
283
|
end
|
233
284
|
end
|
234
|
-
end
|
235
285
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
286
|
+
def create_unknown_abstractor_suggestion(about, abstractor_abstraction, abstractor_abstraction_source)
|
287
|
+
#Create an 'unknown' suggestion based on matching nothing only if we have not made a suggstion
|
288
|
+
abstractor_abstraction_source.normalize_from_method_to_sources(about).each do |source|
|
289
|
+
if abstractor_abstraction.abstractor_suggestions(true).empty?
|
290
|
+
suggest(abstractor_abstraction, abstractor_abstraction_source, nil, nil, source[:source_id], source[:source_type].to_s, source[:source_method], nil, true, nil, nil)
|
291
|
+
end
|
241
292
|
end
|
242
293
|
end
|
243
|
-
end
|
244
294
|
|
245
|
-
|
246
|
-
|
247
|
-
|
295
|
+
def groupable?
|
296
|
+
!abstractor_subject_group_member.nil?
|
297
|
+
end
|
248
298
|
|
249
|
-
|
299
|
+
private
|
250
300
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
301
|
+
def object_variants(abstractor_object_value, abstractor_object_value_variants)
|
302
|
+
aovv = abstractor_object_value_variants.select { |abstractor_object_value_variant| abstractor_object_value_variant.abstractor_object_value_id == abstractor_object_value.id }
|
303
|
+
[abstractor_object_value.value].concat(aovv.map(&:value))
|
304
|
+
end
|
305
|
+
end
|
255
306
|
end
|
256
307
|
end
|
257
308
|
end
|
@@ -9,7 +9,7 @@ module Abstractor
|
|
9
9
|
base.send :belongs_to, :abstractor_abstraction_source
|
10
10
|
base.send :belongs_to, :abstractor_suggestion
|
11
11
|
|
12
|
-
base.send :attr_accessible, :abstractor_abstraction_source, :abstractor_abstraction_source_id, :abstractor_suggestion, :abstractor_suggestion_id, :source_id, :source_type, :source_method, :match_value, :deleted_at, :sentence_match_value
|
12
|
+
base.send :attr_accessible, :abstractor_abstraction_source, :abstractor_abstraction_source_id, :abstractor_suggestion, :abstractor_suggestion_id, :source_id, :source_type, :source_method, :match_value, :deleted_at, :sentence_match_value, :custom_method
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/abstractor/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.22
|
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-06-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -344,26 +344,6 @@ dependencies:
|
|
344
344
|
- - ! '>='
|
345
345
|
- !ruby/object:Gem::Version
|
346
346
|
version: 2.2.1
|
347
|
-
- !ruby/object:Gem::Dependency
|
348
|
-
name: nubic-gem-tasks
|
349
|
-
requirement: !ruby/object:Gem::Requirement
|
350
|
-
requirements:
|
351
|
-
- - ~>
|
352
|
-
- !ruby/object:Gem::Version
|
353
|
-
version: 1.0.0
|
354
|
-
- - ! '>='
|
355
|
-
- !ruby/object:Gem::Version
|
356
|
-
version: 1.0.0
|
357
|
-
type: :development
|
358
|
-
prerelease: false
|
359
|
-
version_requirements: !ruby/object:Gem::Requirement
|
360
|
-
requirements:
|
361
|
-
- - ~>
|
362
|
-
- !ruby/object:Gem::Version
|
363
|
-
version: 1.0.0
|
364
|
-
- - ! '>='
|
365
|
-
- !ruby/object:Gem::Version
|
366
|
-
version: 1.0.0
|
367
347
|
- !ruby/object:Gem::Dependency
|
368
348
|
name: yard
|
369
349
|
requirement: !ruby/object:Gem::Requirement
|
@@ -501,6 +481,8 @@ files:
|
|
501
481
|
- db/migrate/20131227213427_create_abstractor_suggestions.rb
|
502
482
|
- db/migrate/20131228041944_create_abstractor_suggestion_object_values.rb
|
503
483
|
- db/migrate/20131228041945_create_abstractor_suggestion_sources.rb
|
484
|
+
- db/migrate/20140618140759_add_custom_method_to_abstractor_abstraction_sources.rb
|
485
|
+
- db/migrate/20140618140828_add_custom_method_to_abstractor_suggestion_sources.rb
|
504
486
|
- db/seeds.rb
|
505
487
|
- lib/abstractor.rb
|
506
488
|
- lib/abstractor/abstractable.rb
|