From deaea0885e52f9b3a0f25eddd381008391464e9d Mon Sep 17 00:00:00 2001 From: Aline Ribeiro Date: Thu, 23 Apr 2020 12:26:10 -0700 Subject: [PATCH 1/5] Remove underscore extraction for resource tags --- app/services/resource_recommendations.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/services/resource_recommendations.rb b/app/services/resource_recommendations.rb index e55cb26886..56fb58fdbc 100644 --- a/app/services/resource_recommendations.rb +++ b/app/services/resource_recommendations.rb @@ -9,9 +9,7 @@ def initialize(moment) def call @moment_keywords = MomentKeywords.new(@moment).call all_resources.select do |resource| - tags = resource['tags'].flat_map do |tag| - tag.tr('_', '-') - end + tags = resource['tags'] (tags & @moment_keywords).any? end end From dcd7956b1e18e6de2a0d864948048e0aba487df3 Mon Sep 17 00:00:00 2001 From: Aline Ribeiro Date: Thu, 23 Apr 2020 15:15:49 -0700 Subject: [PATCH 2/5] Match moment keywords with respective resources --- app/controllers/moments_controller.rb | 10 +++++----- app/services/moment_keywords.rb | 1 + app/services/resource_recommendations.rb | 23 ++++++++++++----------- app/views/moments/show.html.erb | 5 +---- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index b0f54cec2b..a8c197661f 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -26,12 +26,12 @@ def index def show show_with_comments(@moment) @resources = ResourceRecommendations.new(@moment).call - @matched_tags = ResourceRecommendations.new(@moment).matched_tags + # @matched_tags = ResourceRecommendations.new(@moment).matched_tags @moment_keywords = MomentKeywords.new(@moment).call - @filter_tags = @matched_tags.map do |t| - "filter[]=#{t}&" - end - @filter_tags = @filter_tags.join() + # @filter_tags = @matched_tags.map do |t| + # "filter[]=#{t}&" + # end + # @filter_tags = @filter_tags.join() end # GET /moments/new diff --git a/app/services/moment_keywords.rb b/app/services/moment_keywords.rb index f52087f420..72766f7b98 100644 --- a/app/services/moment_keywords.rb +++ b/app/services/moment_keywords.rb @@ -15,6 +15,7 @@ def call extract(@moment.fix)) remove_special_chars downcase_keywords + @moment_keywords = @moment_keywords.join(' ') end private diff --git a/app/services/resource_recommendations.rb b/app/services/resource_recommendations.rb index 56fb58fdbc..f2b78afa8e 100644 --- a/app/services/resource_recommendations.rb +++ b/app/services/resource_recommendations.rb @@ -9,20 +9,21 @@ def initialize(moment) def call @moment_keywords = MomentKeywords.new(@moment).call all_resources.select do |resource| - tags = resource['tags'] - (tags & @moment_keywords).any? + resource['tags'].any? do |tag| + @moment_keywords.match?(tag) + end end end - def matched_tags - @moment_keywords = MomentKeywords.new(@moment).call - resource_tags = all_resources.flat_map do |resource| - resource['tags'].map do |tag| - tag.tr('_', '-') - end - end - matched_tags = (@moment_keywords & resource_tags) - end + # def matched_tags + # @moment_keywords = MomentKeywords.new(@moment).call + # resource_tags = all_resources.flat_map do |resource| + # resource['tags'].map do |tag| + # tag.tr('_', '-') + # end + # end + # matched_tags = (@moment_keywords & resource_tags) + # end private diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index 029ce6b041..02fee137ba 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -47,15 +47,12 @@
<%= label_tag "What resources could help?" %>
    - <% @resources.take(3).each do |item| %> + <% @resources.each do |item| %>
  • <%= link_to item['name'], item['link'] %>
  • <%end %>
  • <%= link_to 'More...', "/resources?#{@filter_tags}" %>
-
- <%= "Tags:" "#{@filter_tags}" %> -
<%= "Moment keywords:" "#{@moment_keywords}" %> <% end %> From 00e9e8ea607ab2256438e7911ec6ed763b889c0d Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Thu, 23 Apr 2020 15:26:07 -0700 Subject: [PATCH 3/5] Made moment_keywords unique --- app/services/moment_keywords.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/moment_keywords.rb b/app/services/moment_keywords.rb index 72766f7b98..a376a4f990 100644 --- a/app/services/moment_keywords.rb +++ b/app/services/moment_keywords.rb @@ -15,7 +15,7 @@ def call extract(@moment.fix)) remove_special_chars downcase_keywords - @moment_keywords = @moment_keywords.join(' ') + @moment_keywords = @moment_keywords.uniq.join(' ') end private From 9bb44e96f60be5d729b905c48499f28ca8128e05 Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Thu, 23 Apr 2020 15:38:09 -0700 Subject: [PATCH 4/5] Modified matched_tags to supply filter_tags --- app/controllers/moments_controller.rb | 10 +++++----- app/services/resource_recommendations.rb | 18 +++++++++--------- app/views/moments/show.html.erb | 1 + 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index a8c197661f..b0f54cec2b 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -26,12 +26,12 @@ def index def show show_with_comments(@moment) @resources = ResourceRecommendations.new(@moment).call - # @matched_tags = ResourceRecommendations.new(@moment).matched_tags + @matched_tags = ResourceRecommendations.new(@moment).matched_tags @moment_keywords = MomentKeywords.new(@moment).call - # @filter_tags = @matched_tags.map do |t| - # "filter[]=#{t}&" - # end - # @filter_tags = @filter_tags.join() + @filter_tags = @matched_tags.map do |t| + "filter[]=#{t}&" + end + @filter_tags = @filter_tags.join() end # GET /moments/new diff --git a/app/services/resource_recommendations.rb b/app/services/resource_recommendations.rb index f2b78afa8e..0b91b1d3f9 100644 --- a/app/services/resource_recommendations.rb +++ b/app/services/resource_recommendations.rb @@ -15,15 +15,15 @@ def call end end - # def matched_tags - # @moment_keywords = MomentKeywords.new(@moment).call - # resource_tags = all_resources.flat_map do |resource| - # resource['tags'].map do |tag| - # tag.tr('_', '-') - # end - # end - # matched_tags = (@moment_keywords & resource_tags) - # end + def matched_tags + @moment_keywords = MomentKeywords.new(@moment).call + resource_tags = all_resources.flat_map do |resource| + resource['tags'].select do |tag| + @moment_keywords.match?(tag) + end + end + resource_tags + end private diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index 02fee137ba..d137b09f0c 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -53,6 +53,7 @@
  • <%= link_to 'More...', "/resources?#{@filter_tags}" %>
  • + <%= @filter_tags %> <%= "Moment keywords:" "#{@moment_keywords}" %> <% end %> From 182c054715d32932edf7a7391876fa870e09a5d2 Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Thu, 23 Apr 2020 16:21:16 -0700 Subject: [PATCH 5/5] Added uniq to tags and cleaned code --- app/controllers/moments_controller.rb | 4 ++-- app/services/moment_keywords.rb | 3 +-- app/services/resource_recommendations.rb | 15 +++++++-------- app/views/moments/show.html.erb | 2 -- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index b0f54cec2b..b612f37a3f 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -28,10 +28,10 @@ def show @resources = ResourceRecommendations.new(@moment).call @matched_tags = ResourceRecommendations.new(@moment).matched_tags @moment_keywords = MomentKeywords.new(@moment).call - @filter_tags = @matched_tags.map do |t| + @filter_tags = @matched_tags.uniq.map do |t| "filter[]=#{t}&" end - @filter_tags = @filter_tags.join() + @filter_tags = @filter_tags.join end # GET /moments/new diff --git a/app/services/moment_keywords.rb b/app/services/moment_keywords.rb index a376a4f990..b7b43a5903 100644 --- a/app/services/moment_keywords.rb +++ b/app/services/moment_keywords.rb @@ -15,7 +15,7 @@ def call extract(@moment.fix)) remove_special_chars downcase_keywords - @moment_keywords = @moment_keywords.uniq.join(' ') + @moment_keywords = @moment_keywords.join(' ') end private @@ -37,7 +37,6 @@ def extract(array) def remove_special_chars @moment_keywords = @moment_keywords.flatten.each do |keyword| - # keyword.gsub!(/[\-_]/, ' ') keyword.gsub!(/[^\p{Alpha} -]/, '') end end diff --git a/app/services/resource_recommendations.rb b/app/services/resource_recommendations.rb index 0b91b1d3f9..de53445f41 100644 --- a/app/services/resource_recommendations.rb +++ b/app/services/resource_recommendations.rb @@ -10,25 +10,24 @@ def call @moment_keywords = MomentKeywords.new(@moment).call all_resources.select do |resource| resource['tags'].any? do |tag| - @moment_keywords.match?(tag) + @moment_keywords.match?(tag) end end end def matched_tags @moment_keywords = MomentKeywords.new(@moment).call - resource_tags = all_resources.flat_map do |resource| - resource['tags'].select do |tag| - @moment_keywords.match?(tag) - end - end - resource_tags + resource_tags = all_resources.flat_map do |resource| + resource['tags'].select do |tag| + @moment_keywords.match?(tag) + end + end + resource_tags end private def all_resources - # JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json'))) resources = JSON.parse(File.read('doc/pages/resources.json')) resources.each do |item| item['tags'].map! { |tag| I18n.t("pages.resources.tags.#{tag}") } diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index d137b09f0c..22fb1edc5e 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -53,8 +53,6 @@
  • <%= link_to 'More...', "/resources?#{@filter_tags}" %>
  • - <%= @filter_tags %> - <%= "Moment keywords:" "#{@moment_keywords}" %> <% end %>