-
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 #340 from flairNLP/add_braunschweiger_zeitung
Addition of Braunschweiger Zeitung
- Loading branch information
Showing
6 changed files
with
126 additions
and
7 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,62 @@ | ||
import datetime | ||
import re | ||
from typing import List, Optional, Pattern | ||
|
||
from lxml.etree import XPath | ||
|
||
from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute | ||
from fundus.parser.utility import ( | ||
apply_substitution_pattern_over_list, | ||
extract_article_body_with_selector, | ||
generic_author_parsing, | ||
generic_date_parsing, | ||
generic_topic_parsing, | ||
) | ||
|
||
|
||
class BSZParser(ParserProxy): | ||
class V1(BaseParser): | ||
_author_substitution_pattern: Pattern[str] = re.compile(r"FUNKE Mediengruppe") | ||
_paragraph_selector = XPath( | ||
"//div[@class='article-body']//p[not(not(text()) or @rel='author' or em[@class='print'] or contains(@class, 'font-sans'))]" | ||
) | ||
_summary_selector = XPath("//div[@class='article-body']//p[contains(@class, 'font-sans')]") | ||
_subheadline_selector = XPath( | ||
"//div[@class='article-body']//h3[not(" | ||
"contains(text(), 'Alle Artikel der Serie')" | ||
" or contains(text(), 'Mehr zum Thema')" | ||
" or contains(text(), 'weitere Videos')" | ||
" or contains(text(), 'Auch interessant')" | ||
" or contains(text(), 'Weitere News'))]" | ||
) | ||
|
||
@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 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("news_keywords")) | ||
|
||
@attribute | ||
def authors(self) -> List[str]: | ||
return apply_substitution_pattern_over_list( | ||
generic_author_parsing(self.precomputed.ld.bf_search("author")), self._author_substitution_pattern | ||
) | ||
|
||
@attribute | ||
def publishing_date(self) -> Optional[datetime.datetime]: | ||
return generic_date_parsing(self.precomputed.ld.bf_search("datePublished")) | ||
|
||
@attribute(validate=False) | ||
def free_access(self) -> bool: | ||
return self.precomputed.ld.bf_search("isAccessibleForFree") == "True" |
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,14 @@ | ||
{ | ||
"V1": { | ||
"authors": [ | ||
"Stefan Lienert" | ||
], | ||
"publishing_date": "2024-01-29 18:09:51+00:00", | ||
"title": "Heide-Park: Eröffnungstermin für neue Attraktion steht fest", | ||
"topics": [ | ||
"Freizeitpark", | ||
"Soltau", | ||
"Heide-Park Soltau" | ||
] | ||
} | ||
} |
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