From 18b80efcb7592b4dd738eefcf614ec4d918e817f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 16 Jun 2020 21:33:17 +0100 Subject: [PATCH] Remove experimental semantics --- inbox.py | 1 - posts.py | 1 - semantic.py | 74 ----------------------------------------------------- tests.py | 12 --------- 4 files changed, 88 deletions(-) delete mode 100644 semantic.py diff --git a/inbox.py b/inbox.py index 7cc7d923..0d0aca1d 100644 --- a/inbox.py +++ b/inbox.py @@ -62,7 +62,6 @@ from question import questionUpdateVotes from media import replaceYouTube from git import isGitPatch from git import receiveGitPatch -from semantic import labelAccusatoryPost def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: diff --git a/posts.py b/posts.py index 349acb6a..bdac26f1 100644 --- a/posts.py +++ b/posts.py @@ -52,7 +52,6 @@ from config import getConfigParam from blocking import isBlocked from filters import isFiltered from git import convertPostToPatch -from semantic import labelAccusatoryPost from jsonldsig import jsonldSign # try: # from BeautifulSoup import BeautifulSoup diff --git a/semantic.py b/semantic.py deleted file mode 100644 index 86911449..00000000 --- a/semantic.py +++ /dev/null @@ -1,74 +0,0 @@ -__filename__ = "semantic.py" -__author__ = "Bob Mottram" -__license__ = "AGPL3+" -__version__ = "1.1.0" -__maintainer__ = "Bob Mottram" -__email__ = "bob@freedombone.net" -__status__ = "Production" - - -def isAccusatory(content: str, translate: {}, threshold=5) -> bool: - """Indicates whether the given content is an accusatory post - """ - words = ('your', "you're", 'if you', 'you are', 'you') - - if translate: - wordsTranslated = [] - for wrd in words: - translated = translate[wrd] - if '|' not in translated: - if translated not in wordsTranslated: - wordsTranslated.append(translated) - else: - # handle differing genders - words2 = translated.split('|') - for wrd2 in words2: - if wrd2.strip() not in wordsTranslated: - wordsTranslated.append(translated) - else: - wordsTranslated = words - - contentLower = content.lower() - ctr = 0 - for wrd in wordsTranslated: - wordCount = contentLower.count(wrd + ' ') - if wordCount > 0: - ctr += wordCount - contentLower = contentLower.replace(wrd + ' ', '') - if ctr >= threshold: - return True - return False - - -def labelAccusatoryPost(postJsonObject: {}, translate: {}, threshold=3): - """If a post is accusatory and it doesn't mention anyone - specific and isn't a reply and it doesn't have a content - warning then add a default 'accusatory' content warning - """ - if not postJsonObject.get('object'): - return - if not isinstance(postJsonObject['object'], dict): - return - if not postJsonObject['object'].get('content'): - return - if not postJsonObject['object'].get('type'): - return - if postJsonObject['object']['type'] == 'Article': - return - if postJsonObject['object'].get('inReplyTo'): - return - if not isinstance(postJsonObject['object']['content'], str): - return - if '@' in postJsonObject['object']['content']: - return - if not isAccusatory(postJsonObject['object']['content'], - translate, threshold): - return - cwStr = translate['Accusatory'] - if postJsonObject['object'].get('summary'): - if cwStr not in postJsonObject['object']['summary']: - postJsonObject['object']['summary'] = \ - cwStr + ', ' + postJsonObject['object']['summary'] - else: - postJsonObject['object']['summary'] = cwStr - postJsonObject['object']['sensitive'] = True diff --git a/tests.py b/tests.py index 8d9b4efa..d062c337 100644 --- a/tests.py +++ b/tests.py @@ -70,7 +70,6 @@ from content import removeLongWords from content import replaceContentDuplicates from content import removeTextFormatting from theme import setCSSparam -from semantic import isAccusatory from jsonldsig import testSignJsonld from jsonldsig import jsonldVerify @@ -1792,16 +1791,6 @@ def testRecentPostsCache(): assert len(recentPostsCache['html'].items()) == maxRecentPosts -def testAccusatory(): - print('testAccusatory') - testStr = 'This is not an accusatory post' - assert(not isAccusatory(testStr, None, 3)) - testStr = "If you x, and you're y then you are z" - assert(isAccusatory(testStr, None, 3)) - testStr = "If x, and if you are y then z" - assert(not isAccusatory(testStr, None, 3)) - - def testRemoveTextFormatting(): print('testRemoveTextFormatting') testStr = '

Text without formatting

' @@ -1873,7 +1862,6 @@ def runAllTests(): print('Running tests...') testJsonld() testRemoveTextFormatting() - testAccusatory() testWebLinks() testRecentPostsCache() testTheme()