8000 add url boost for spectrum by Edouard360 · Pull Request #1 · feedly/python-readability · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

add url boost for spectrum #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion readability/readability.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def score_paragraphs(self):

def class_weight(self, e):
weight = 0
for feature in [e.get("class", None), e.get("id", None)]:
for feature in [e.get("class", None), e.get("id", None), e.get("data-post-url")]:
if feature:
if REGEXES["negativeRe"].search(feature):
weight -= 25
Expand All @@ -415,6 +415,9 @@ def class_weight(self, e):
if self.negative_keywords and self.negative_keywords.search(feature):
weight -= 25

if self.url in feature:
weight += 500

if self. BFA7 positive_keywords and self.positive_keywords.match("tag-" + e.tag):
weight += 25

Expand Down
1,261 changes: 1,261 additions & 0 deletions tests/samples/spectrum.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/test_article_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ def test_utf8_kanji(self):
sample = load_sample("utf-8-kanji.sample.html")
doc = Document(sample)
res = doc.summary()

def test_spectrum_ieee(self):
sample = load_sample("spectrum.html")
doc = Document(sample, url="https://spectrum.ieee.org/event-based-camera-chips")
first_sentence = "The pixels in event-based cameras"
self.assertIn(first_sentence, doc.summary())
0