Fix accusatory count

main
Bob Mottram 2020-06-14 10:21:37 +01:00
parent 6d2269b41f
commit b6fd9f211f
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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 = '<p>Help someone to protect doing something real and decent, if you are able<br /><a href=\"https://www.permaculturenews.org/2020/06/09/hey-big-boy-fence-that-dream/\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">permaculturenews.org/2020/06/0</span><span class=\"invisible\">9/hey-big-boy-fence-that-dream/</span></a></p>'
assert(not isAccusatory(testStr, None, 3))
def runAllTests():