-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor project directory
- Loading branch information
zp
committed
May 7, 2024
1 parent
a562b43
commit e74b8b1
Showing
51 changed files
with
535 additions
and
342 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tests/** linguist-detectable=false | ||
benchmark/** linguist-detectable=false | ||
*.xsl linguist-documentation=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
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 @@ | ||
# -*- coding:utf-8 -*- |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
beautifulsoup4 | ||
jieba | ||
ltp | ||
numpy | ||
rouge_score | ||
tabulate | ||
trafilatura | ||
readability-lxml | ||
newspaper3k | ||
goose3 | ||
justext | ||
gne |
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
File renamed without changes.
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 @@ | ||
# -*- coding:utf-8 -*- |
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,43 @@ | ||
# -*- coding:utf-8 -*- | ||
|
||
from magic_html.utils import * | ||
from magic_html.extractors.base_extractor import BaseExtractor | ||
from magic_html.extractors.title_extractor import TitleExtractor | ||
|
||
|
||
class ArticleExtractor(BaseExtractor): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def extract(self, html="", base_url="") -> dict: | ||
html = html.replace(" ", " ").replace(" ", " ") | ||
tree = load_html(html) | ||
if tree is None: | ||
raise ValueError | ||
|
||
title = TitleExtractor().process(tree) | ||
|
||
# base_url | ||
base_href = tree.xpath("//base/@href") | ||
|
||
if base_href and "http" in base_href[0]: | ||
base_url = base_href[0] | ||
|
||
# 标签转换, 增加数学标签处理 | ||
format_tree = self.convert_tags(tree, base_url=base_url) | ||
|
||
# 删除script style等标签及其内容 | ||
normal_tree = self.clean_tags(format_tree) | ||
|
||
subtree, xp_num, drop_list = self.xp_1_5(normal_tree) | ||
if xp_num == "others": | ||
subtree, drop_list = self.prune_unwanted_sections(normal_tree) | ||
body_html = self.get_content_html(subtree, xp_num, base_url) | ||
|
||
return { | ||
"xp_num": xp_num, | ||
"drop_list": drop_list, | ||
"html": body_html, | ||
"title": title, | ||
"base_url": base_url, | ||
} |
Oops, something went wrong.