Class: Html2rss::Scoring::ContainerAssessor
- Inherits:
-
Object
- Object
- Html2rss::Scoring::ContainerAssessor
- Defined in:
- lib/html2rss/scoring/container_assessor.rb
Overview
Observes an SST container and builds typed Observation score inputs.
Constant Summary collapse
- PUBLISH_ITEMPROPS =
Microdata itemprop values treated as publish/update markers.
%w[datePublished dateModified].freeze
Instance Method Summary collapse
- #call(container, selected_anchor, destination_facts:) ⇒ Observation
-
#initialize(text_classifier: LinkDestination::TextClassifier.new, content_token_regexp: LinkResolver::CONTENT_TOKEN_REGEXP, junk_token_regexp: LinkResolver::JUNK_TOKEN_REGEXP) ⇒ ContainerAssessor
constructor
A new instance of ContainerAssessor.
Constructor Details
#initialize(text_classifier: LinkDestination::TextClassifier.new, content_token_regexp: LinkResolver::CONTENT_TOKEN_REGEXP, junk_token_regexp: LinkResolver::JUNK_TOKEN_REGEXP) ⇒ ContainerAssessor
Returns a new instance of ContainerAssessor.
14 15 16 17 18 19 20 |
# File 'lib/html2rss/scoring/container_assessor.rb', line 14 def initialize(text_classifier: LinkDestination::TextClassifier.new, content_token_regexp: LinkResolver::CONTENT_TOKEN_REGEXP, junk_token_regexp: LinkResolver::JUNK_TOKEN_REGEXP) @text_classifier = text_classifier @content_token_regexp = content_token_regexp @junk_token_regexp = junk_token_regexp end |
Instance Method Details
#call(container, selected_anchor, destination_facts:) ⇒ Observation
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/html2rss/scoring/container_assessor.rb', line 27 def call(container, selected_anchor, destination_facts:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength title = entry_title(container, selected_anchor) tokens = "#{container.attrs.class_attr} #{container.attrs.id}" Observation.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?(container.visible_text, title), article_container: container.name == :article, content_tokens: tokens.match?(@content_token_regexp), junk_tokens: tokens.match?(@junk_token_regexp), 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 |