From b6fd9f211f9c6332b6a83fdb3a77644865236367 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Jun 2020 10:21:37 +0100 Subject: [PATCH] Fix accusatory count --- semantic.py | 7 +++++-- tests.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/semantic.py b/semantic.py index 2cb44e3b..6a491dfe 100644 --- a/semantic.py +++ b/semantic.py @@ -10,7 +10,7 @@ __status__ = "Production" def isAccusatory(content: str, translate: {}, threshold=3) -> bool: """Indicates whether the given content is an accusatory post """ - words = ('you', 'your', "you're", 'if you', 'you are') + words = ('your', "you're", 'if you', 'you are', 'you') if translate: wordsTranslated = [] @@ -31,7 +31,10 @@ def isAccusatory(content: str, translate: {}, threshold=3) -> bool: contentLower = content.lower() ctr = 0 for wrd in wordsTranslated: - ctr += contentLower.count(wrd + ' ') + wordCount = contentLower.count(wrd + ' ') + if wordCount > 0: + ctr += wordCount + contentLower = contentLower.replace(wrd + ' ', '') if ctr >= threshold: return True return False diff --git a/tests.py b/tests.py index 56294f3e..76d50ecc 100644 --- a/tests.py +++ b/tests.py @@ -1794,6 +1794,8 @@ def testAccusatory(): assert(not isAccusatory(testStr, None, 3)) testStr = "If you x, and you're y then you are z" assert(isAccusatory(testStr, None, 3)) + testStr = '

Help someone to protect doing something real and decent, if you are able
https://www.permaculturenews.org/2020/06/09/hey-big-boy-fence-that-dream/

' + assert(not isAccusatory(testStr, None, 3)) def runAllTests():