Class: Html2rss::AutoSource::Discovery::DomClustering::GroupScorer
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Discovery::DomClustering::GroupScorer
- Defined in:
- lib/html2rss/auto_source/discovery/dom_clustering/group_scorer.rb
Overview
Scores candidate DOM groups using heading, time, date, and word-count signals.
Instance Method Summary collapse
-
#avg_words(nodes) ⇒ Float
Average visible word count across nodes.
-
#initialize ⇒ GroupScorer
constructor
A new instance of GroupScorer.
-
#select_best_group(groups) ⇒ Array<Nokogiri::XML::Node>
Nodes from the highest-scoring group.
Constructor Details
#initialize ⇒ GroupScorer
Returns a new instance of GroupScorer.
10 11 12 13 |
# File 'lib/html2rss/auto_source/discovery/dom_clustering/group_scorer.rb', line 10 def initialize @text_words = {}.compare_by_identity @has_date = {}.compare_by_identity end |
Instance Method Details
#avg_words(nodes) ⇒ Float
Returns average visible word count across nodes.
33 34 35 |
# File 'lib/html2rss/auto_source/discovery/dom_clustering/group_scorer.rb', line 33 def avg_words(nodes) nodes.sum { |n| text_words(n) } / nodes.size.to_f end |
#select_best_group(groups) ⇒ Array<Nokogiri::XML::Node>
Returns nodes from the highest-scoring group.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/html2rss/auto_source/discovery/dom_clustering/group_scorer.rb', line 17 def select_best_group(groups) best_nodes = [] best_score = -1 groups.each_value do |nodes| score = score_group(nodes) next if score.negative? (best_nodes = nodes) && (best_score = score) if score > best_score end best_nodes end |