Class: Html2rss::AutoSource::LinkHeuristics::ContainerAssessor
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::LinkHeuristics::ContainerAssessor
- Defined in:
- lib/html2rss/auto_source/link_heuristics/container_assessor.rb
Overview
Turns container DOM observations into ContainerSignals inputs.
Owns publish markers, headings, visible text, and class/id tokens so LinkHeuristics can keep eligibility policy and ContainerSignals can keep scoring without re-reading the DOM.
Constant Summary collapse
- CONTENT_TOKEN_REGEXP =
Token pattern for content-like class/id markers on containers.
begin words = PathClassifier::SEGMENT_SETS.fetch(:content) /(?:^|\s|[-_])(#{Regexp.union(words.to_a).source})(?:\s|[-_]|$)/i end.freeze
- JUNK_TOKEN_REGEXP =
Token pattern for junk/utility class/id markers on containers.
begin words = PathClassifier::SEGMENT_SETS.fetch(:utility) /(?:^|\s|[-_])(#{Regexp.union(words.to_a).source})(?:\s|[-_]|$)/i end.freeze
Instance Method Summary collapse
-
#call(container, selected_anchor, destination_facts:) ⇒ ContainerSignals
Observes a container and builds ranking signals, including hard-junk.
-
#initialize(text_classifier:) ⇒ ContainerAssessor
constructor
A new instance of ContainerAssessor.
Constructor Details
#initialize(text_classifier:) ⇒ ContainerAssessor
Returns a new instance of ContainerAssessor.
26 27 28 |
# File 'lib/html2rss/auto_source/link_heuristics/container_assessor.rb', line 26 def initialize(text_classifier:) @text_classifier = text_classifier end |
Instance Method Details
#call(container, selected_anchor, destination_facts:) ⇒ ContainerSignals
Observes a container and builds ranking signals, including hard-junk.
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/html2rss/auto_source/link_heuristics/container_assessor.rb', line 38 def call(container, selected_anchor, destination_facts:) title = entry_title(container, selected_anchor) tokens = container_tokens(container) ContainerSignals.new( title_word_count: word_count(title), path_length: destination_facts&.url&.path.to_s.length, content_path: destination_facts&.content_path, publish_marker: publish_marker?(container), descriptive_context: descriptive_context?(visible_text(container), title), article_container: container.name == 'article', content_tokens: content_tokens?(tokens), junk_tokens: junk_tokens?(tokens), utility_prefix_title: @text_classifier.utility_prefix?(title), recommended_title: @text_classifier.recommended?(title), utility_path: destination_facts&.utility_path, strong_post_suffix: destination_facts&.strong_post_suffix, shallow: destination_facts&.shallow, high_confidence_junk_path: destination_facts&.high_confidence_junk_path, high_confidence_utility_destination: destination_facts&.high_confidence_utility_destination, selected_anchor_present: !selected_anchor.nil? ) end |