Remove experimental semantics

main
Bob Mottram 2020-06-16 21:33:17 +01:00
parent 12c7035d50
commit 18b80efcb7
4 changed files with 0 additions and 88 deletions

View File

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

View File

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

View File

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

View File

@ -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 = '<p>Text without formatting</p>'
@ -1873,7 +1862,6 @@ def runAllTests():
print('Running tests...')
testJsonld()
testRemoveTextFormatting()
testAccusatory()
testWebLinks()
testRecentPostsCache()
testTheme()