Class: Html2rss::AutoSource::Segmenter
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Segmenter
- Defined in:
- lib/html2rss/auto_source/segmenter.rb,
lib/html2rss/auto_source/segmenter/list.rb,
lib/html2rss/auto_source/segmenter/cluster.rb,
lib/html2rss/auto_source/segmenter/semantic.rb,
lib/html2rss/auto_source/segmenter/primary_link.rb
Overview
Discovers candidate content segments from an SST::Document.
Strategies:
:semantic— leaf article/section/li/tr/div containers with a primary link:list— repeated tag_path anchors walked to a shared container boundary:cluster— class / structure clustering for anchorless card grids
Defined Under Namespace
Modules: Cluster, List, Semantic Classes: PrimaryLink
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#link_resolver ⇒ Object
readonly
Returns the value of attribute link_resolver.
-
#minimum_selector_frequency ⇒ Object
readonly
Returns the value of attribute minimum_selector_frequency.
-
#noise_policy ⇒ Object
readonly
Returns the value of attribute noise_policy.
-
#permit_unanchored ⇒ Object
readonly
Returns the value of attribute permit_unanchored.
-
#use_top_selectors ⇒ Object
readonly
Returns the value of attribute use_top_selectors.
Class Method Summary collapse
-
.call(document, base_url:, strategy:, **opts) ⇒ Array<Segment>
rubocop:disable Style/ArgumentsForwarding -- keep named opts for YARD @option.
Instance Method Summary collapse
- #call ⇒ Array<Segment>
- #index ⇒ SST::Index
-
#initialize(document, base_url:, strategy:, **opts) ⇒ Segmenter
constructor
A new instance of Segmenter.
Constructor Details
#initialize(document, base_url:, strategy:, **opts) ⇒ Segmenter
Returns a new instance of Segmenter.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 36 def initialize(document, base_url:, strategy:, **opts) raise ArgumentError, 'document must be SST::Document' unless document.is_a?(SST::Document) raise ArgumentError, "unknown strategy: #{strategy.inspect}" unless Segment::STRATEGIES.include?(strategy) @document = document @base_url = base_url @strategy = strategy @permit_unanchored = opts.fetch(:permit_unanchored, false) @minimum_selector_frequency = opts.fetch(:minimum_selector_frequency, 2) @use_top_selectors = opts.fetch(:use_top_selectors, 5) @link_resolver = opts[:link_resolver] || Scoring::LinkResolver.new(base_url) @noise_policy = LinkDestination::NoisePolicy.new(link_resolver: @link_resolver, index: document.index) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def base_url @base_url end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def document @document end |
#link_resolver ⇒ Object (readonly)
Returns the value of attribute link_resolver.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def link_resolver @link_resolver end |
#minimum_selector_frequency ⇒ Object (readonly)
Returns the value of attribute minimum_selector_frequency.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def minimum_selector_frequency @minimum_selector_frequency end |
#noise_policy ⇒ Object (readonly)
Returns the value of attribute noise_policy.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def noise_policy @noise_policy end |
#permit_unanchored ⇒ Object (readonly)
Returns the value of attribute permit_unanchored.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def permit_unanchored @permit_unanchored end |
#use_top_selectors ⇒ Object (readonly)
Returns the value of attribute use_top_selectors.
59 60 61 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 59 def use_top_selectors @use_top_selectors end |
Class Method Details
.call(document, base_url:, strategy:, **opts) ⇒ Array<Segment>
rubocop:disable Style/ArgumentsForwarding -- keep named opts for YARD @option
23 24 25 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 23 def self.call(document, base_url:, strategy:, **opts) new(document, base_url:, strategy:, **opts).call end |
Instance Method Details
#call ⇒ Array<Segment>
51 52 53 54 55 56 57 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 51 def call case @strategy when :semantic then Semantic.call(self) when :list then List.call(self) when :cluster then Cluster.call(self) end end |
#index ⇒ SST::Index
63 |
# File 'lib/html2rss/auto_source/segmenter.rb', line 63 def index = document.index |