Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated MDR Parser #370

Merged
merged 3 commits into from
Mar 8, 2024
Merged
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
14 changes: 12 additions & 2 deletions src/fundus/publishers/de/mdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Optional, Pattern

from lxml.cssselect import CSSSelector
from lxml.etree import XPath

from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute
from fundus.parser.utility import (
Expand All @@ -17,7 +18,13 @@
class MDRParser(ParserProxy):
class V1(BaseParser):
_author_substitution_pattern: Pattern[str] = re.compile(r"MDR \w*$|MDR \w*-\w*$|MDRfragt-Redaktionsteam|^von")
_paragraph_selector = CSSSelector("div.paragraph")
# regex examples: https://regex101.com/r/2DSjAz/1
_source_detection: str = r"^((MDR (AKTUELL ){0,1}\(([A-z]{2,3}(\/[A-z]{2,3})*|[A-z, ]{2,50}))\)|(Quell(e|en): (u.a. ){0,1}[A-z,]{3,4})|[A-z]{2,4}(, [A-z]{2,4}){0,3}( \([A-z]{2,4}\)){0,1}$|[A-z]{2,4}\/[A-z(), \/]{3,10}$)"
_paragraph_selector = XPath(
f"//div[@class='paragraph '] "
f"/p[not(re:test(em, '{_source_detection}') or re:test(text(), '{_source_detection}'))]",
namespaces={"re": "http://exslt.org/regular-expressions"},
)
_summary_selector = CSSSelector("p.einleitung")
_subheadline_selector = CSSSelector("div > .subtitle")
_author_selector = CSSSelector(".articleMeta > .author")
Expand All @@ -33,7 +40,10 @@ def body(self) -> ArticleBody:

@attribute
def topics(self) -> List[str]:
return generic_topic_parsing(self.precomputed.meta.get("news_keywords"))
if self.precomputed.meta.get("news_keywords") is not None:
return generic_topic_parsing(self.precomputed.meta.get("news_keywords"))
else:
return generic_topic_parsing(self.precomputed.meta.get("keywords"))

@attribute
def publishing_date(self) -> Optional[datetime.datetime]:
Expand Down
Loading