from src.rule_based_system.Rule import Rule from src.rule_based_system.Verdict import Verdict class UrlRule(Rule): url_extractor = None def __init__(self, url_extractor): self.url_extractor = url_extractor def get_verdict(self, comment_text: str) -> Verdict: urls = self.find_urls(comment_text) return Verdict(len(urls) == 0, urls) def find_urls(self, text: str) -> list: urls = self.url_extractor.find_urls(text) # url_extractor does not find url with spaces. Add extra check for urls like http:// goatse info if len(urls) == 0 and 'http' in text: urls = ['http'] return urls def is_strict(self) -> bool: return True @staticmethod def get_rule_description() -> str: return 'Url was mentioned in text'