-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from flairNLP/add-business-insider
Add Business Insider
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import datetime | ||
from typing import List, Optional | ||
|
||
from lxml.cssselect import CSSSelector | ||
from lxml.etree import XPath | ||
|
||
from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute | ||
from fundus.parser.utility import ( | ||
extract_article_body_with_selector, | ||
generic_author_parsing, | ||
generic_date_parsing, | ||
generic_topic_parsing, | ||
) | ||
|
||
|
||
class BusinessInsiderParser(ParserProxy): | ||
class V1(BaseParser): | ||
_summary_selector = CSSSelector("article div.bi-bulletpoints > p") | ||
_subheadline_selector = CSSSelector("article h2") | ||
|
||
_paragraph_selector = XPath( | ||
""" | ||
//article | ||
//div[contains(@class, 'article-body')] | ||
//p[ | ||
not( | ||
ancestor::*[@class='bi-bulletpoints'] or | ||
mark[@class='has-inline-color has-cyan-bluish-gray-color'] or | ||
@class='has-text-align-right' | ||
) | ||
] | ||
""" | ||
) | ||
|
||
@attribute | ||
def body(self) -> ArticleBody: | ||
return extract_article_body_with_selector( | ||
self.precomputed.doc, | ||
summary_selector=self._summary_selector, | ||
subheadline_selector=self._subheadline_selector, | ||
paragraph_selector=self._paragraph_selector, | ||
) | ||
|
||
@attribute | ||
def authors(self) -> List[str]: | ||
return generic_author_parsing(self.precomputed.ld.bf_search("author")) | ||
|
||
@attribute | ||
def publishing_date(self) -> Optional[datetime.datetime]: | ||
return generic_date_parsing(self.precomputed.ld.bf_search("datePublished")) | ||
|
||
@attribute | ||
def title(self) -> Optional[str]: | ||
return self.precomputed.ld.bf_search("headline") | ||
|
||
@attribute | ||
def topics(self) -> List[str]: | ||
return generic_topic_parsing(self.precomputed.meta.get("keywords")) or generic_topic_parsing( | ||
self.precomputed.ld.bf_search("keywords") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"V1": { | ||
"authors": [ | ||
"Matthew Loh" | ||
], | ||
"publishing_date": "2024-01-29 19:00:45+00:00", | ||
"title": "Wie groß ist Evergrande, Chinas strauchelnder Immobilienriese?", | ||
"topics": [ | ||
"China", | ||
"Immobilien", | ||
"Pleite", | ||
"Schulden" | ||
] | ||
} | ||
} |
Binary file added
BIN
+60.8 KB
tests/resources/parser/test_data/de/BusinessInsider_2024_01_29.html.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters