Class: Html2rss::Scoring::ClusterScorer
- Inherits:
-
Object
- Object
- Html2rss::Scoring::ClusterScorer
- Defined in:
- lib/html2rss/scoring/cluster_scorer.rb
Overview
Scores DomClustering-style node groups (heading/time/date/word density). Sole home for cluster-group ranking weights.
Constant Summary collapse
- MIN_AVG_WORDS =
Minimum average visible words before a group is eligible.
5- HEADING_BONUS =
Bonus when any node has a heading or bold title class.
20- TIME_BONUS =
Bonus when any node has a time/datetime marker.
20- DATE_BONUS =
Bonus when any node has date-like visible text.
40
Instance Method Summary collapse
- #avg_words(nodes) ⇒ Float
-
#initialize ⇒ ClusterScorer
constructor
A new instance of ClusterScorer.
- #select_best_group(groups) ⇒ Array<SST::Node>
Constructor Details
#initialize ⇒ ClusterScorer
Returns a new instance of ClusterScorer.
18 19 20 21 |
# File 'lib/html2rss/scoring/cluster_scorer.rb', line 18 def initialize @text_words = {}.compare_by_identity @has_date = {}.compare_by_identity end |
Instance Method Details
#avg_words(nodes) ⇒ Float
42 43 44 |
# File 'lib/html2rss/scoring/cluster_scorer.rb', line 42 def avg_words(nodes) nodes.sum { |n| text_words(n) } / nodes.size.to_f end |
#select_best_group(groups) ⇒ Array<SST::Node>
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/html2rss/scoring/cluster_scorer.rb', line 26 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 |