Class: Summarization::Base
- Inherits:
-
Object
- Object
- Summarization::Base
- Defined in:
- lib/summarization/base.rb
Class Method Summary collapse
- .available_strategies ⇒ Object
- .can_request_summary_for?(user) ⇒ Boolean
- .can_see_summary?(target, user) ⇒ Boolean
- .find_strategy(strategy_model) ⇒ Object
- .selected_strategy ⇒ Object
Instance Method Summary collapse
-
#configuration_hint ⇒ Object
If we don’t meet the conditions to enable this strategy, we’ll display this hint as an error to admins.
-
#correctly_configured? ⇒ Boolean
Some strategies could require other conditions to work correctly, like site settings.
-
#display_name ⇒ Object
Strategy name to display to admins in the available strategies dropdown.
-
#model ⇒ Object
Returns the string we’ll store in the selected strategy site setting.
-
#summarize(content) ⇒ Object
The idea behind this method is “give me a collection of texts, and I’ll handle the summarization to the best of my capabilities.”.
Class Method Details
.available_strategies ⇒ Object
11 12 13 |
# File 'lib/summarization/base.rb', line 11 def available_strategies DiscoursePluginRegistry.summarization_strategies end |
.can_request_summary_for?(user) ⇒ Boolean
34 35 36 37 38 39 40 41 42 |
# File 'lib/summarization/base.rb', line 34 def can_request_summary_for?(user) return false unless user user_group_ids = user.group_ids SiteSetting.custom_summarization_allowed_groups_map.any? do |group_id| user_group_ids.include?(group_id) end end |
.can_see_summary?(target, user) ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'lib/summarization/base.rb', line 25 def can_see_summary?(target, user) return false if SiteSetting.summarization_strategy.blank? has_cached_summary = SummarySection.exists?(target: target, meta_section_id: nil) return has_cached_summary if user.nil? has_cached_summary || can_request_summary_for?(user) end |
.find_strategy(strategy_model) ⇒ Object
15 16 17 |
# File 'lib/summarization/base.rb', line 15 def find_strategy(strategy_model) available_strategies.detect { |s| s.model == strategy_model } end |
.selected_strategy ⇒ Object
19 20 21 22 23 |
# File 'lib/summarization/base.rb', line 19 def selected_strategy return if SiteSetting.summarization_strategy.blank? find_strategy(SiteSetting.summarization_strategy) end |
Instance Method Details
#configuration_hint ⇒ Object
If we don’t meet the conditions to enable this strategy, we’ll display this hint as an error to admins.
60 61 62 |
# File 'lib/summarization/base.rb', line 60 def configuration_hint raise NotImplemented end |
#correctly_configured? ⇒ Boolean
Some strategies could require other conditions to work correctly, like site settings. This method gets called when admins attempt to select it, checking if we met those conditions.
49 50 51 |
# File 'lib/summarization/base.rb', line 49 def correctly_configured? raise NotImplemented end |
#display_name ⇒ Object
Strategy name to display to admins in the available strategies dropdown.
54 55 56 |
# File 'lib/summarization/base.rb', line 54 def display_name raise NotImplemented end |
#model ⇒ Object
Returns the string we’ll store in the selected strategy site setting.
91 92 93 |
# File 'lib/summarization/base.rb', line 91 def model raise NotImplemented end |
#summarize(content) ⇒ Object
The idea behind this method is “give me a collection of texts, and I’ll handle the summarization to the best of my capabilities.”. It’s important to emphasize the “collection of texts” part, which implies it’s not tied to any model and expects the “content” to be a hash instead.
context to help the strategy produce a better result. Keys present in the content hash:
- resource_path (optional): Helps the strategy build links to the content in the summary (e.g. "/t/-/:topic_id/POST_NUMBER")
- content_title (optional): Provides guidance about what the content is about.
- contents (required): Array of hashes with content to summarize (e.g. [{ poster: "asd", id: 1, text: "This is a text" }])
All keys are required.
will get called with partial summarized text as its generated.
86 87 88 |
# File 'lib/summarization/base.rb', line 86 def summarize(content) raise NotImplemented end |