nosdigitalmedia's picture
Attempt to set up application
4e0f321
raw
history blame contribute delete
961 Bytes
import re
from src.rule_based_system.Rule import Rule
from src.rule_based_system.TextLengthRule import TEXT_SIZE_LIMIT
from src.rule_based_system.Verdict import Verdict
class PersonalDetailsRule(Rule):
def __init__(self, regexes: list, strict: bool):
self.regexes = regexes
self.strict = strict
def get_verdict(self, comment_text: str) -> Verdict:
comment_text = comment_text[0:TEXT_SIZE_LIMIT]
personal_details = self.find_personal_details(comment_text)
return Verdict(len(personal_details) == 0, personal_details)
def find_personal_details(self, text: str) -> list:
details = []
for regex in self.regexes:
matches = re.findall(regex, text)
details += matches
return details
def is_strict(self) -> bool:
return self.strict
@staticmethod
def get_rule_description() -> str:
return 'Personal details were mentioned in text'