Skip to content

Commit

Permalink
none keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
yindaheng98 committed Dec 16, 2023
1 parent dff4006 commit 50626b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions dblp_crawler/keyword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def add_word_rules(self, *words: str) -> None:
self.add_rule_list(*list(set(word, ) for word in words))

def match(self, sentence: str) -> bool:
if len(self.rules) <= 0 and len(self.words) <= 0:
return True # 没有规则就全过
sentence = sentence.lower()
words = set(re.findall(r"\w+", sentence))
for rule in self.rules: # 只要有一个rule能匹配上就返回True
Expand All @@ -29,6 +31,8 @@ def match(self, sentence: str) -> bool:
return False

def match_words(self, sentence: str) -> bool:
if len(self.rules) <= 0 and len(self.words) <= 0:
return True # 没有规则就全过
sentence = sentence.lower()
# 所有rule全切成一个个单词,只要包含其中一个单词就返回True
return len(set(re.findall(r"\w+", sentence)).intersection(self.words)) > 0
Expand Down
4 changes: 2 additions & 2 deletions dblp_crawler/keyword/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from . import Keywords


def add_argument(parser: argparse.ArgumentParser, *flags, dest: str = 'keyword', required=True) -> None:
def add_argument(parser: argparse.ArgumentParser, *flags, dest: str = 'keyword') -> None:
if len(flags) <= 0:
flags = ['-k', '--keyword']
parser.add_argument(
*flags, dest=dest, action='append', required=required,
*flags, dest=dest, action='append', required=False, default=[],
help=f'Specify keyword rules.'
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='dblp_crawler',
version='1.8.14',
version='1.8.15',
author='yindaheng98',
author_email='[email protected]',
url='https://github.com/yindaheng98/dblp-crawler',
Expand Down

0 comments on commit 50626b1

Please sign in to comment.