bluesearch.database.topic_rule module

Implementation of the TopicRule data structure.

class TopicRule(level: str | None = None, source: str | ArticleSource | None = None, pattern: str | re.Pattern | None = None)[source]

Bases: object

Rule for accepting/rejecting an article based on topic matching criteria.

Parameters
  • level – Level of the topic information to match, must be “article” or “journal”. Passing None will match any level.

  • source – Article source, must be a valid ArticleSource (e.g. “arxiv”, “pmc”, …). Passing None will match any source.

  • pattern – Regular expression for matching the topic names of a given article. Passing None will match the name of any topic.

match(topic_info: bluesearch.database.topic_info.TopicInfo) bool[source]

Determine whether a topic_info matches the rule.

Note that the keys (topic sources) of the topic_info.article_topics and topic_info.journal_topics dictionaries are completely disregarded. And all the values (lists) are simply concatenated.

check_topic_rules(topic_info: bluesearch.database.topic_info.TopicInfo, topic_rules_accept: Iterable[bluesearch.database.topic_rule.TopicRule], topic_rules_reject: Iterable[bluesearch.database.topic_rule.TopicRule]) bool[source]

Check whether the topic info of an article satisfies given topic rules.

The topic_info needs to satisfy both of the below conditions to be accepted: * At least one rule within topic_rules_accept is satisfied * No rules in topic_rules_reject are satisfied

Parameters
  • topic_info – Topic info to accept or reject.

  • topic_rules_accept – List of topic rules to accept a given topic_info.

  • topic_rules_reject – List of topic rules to reject a given topic_info.

Returns

If True, the topic info matches satisfies both conditions explained above. If False, at least one of the conditions is not satisfied.

Return type

bool