Gender detection from profile tag

merge-requests/30/head
Bob Mottram 2021-03-03 13:37:18 +00:00
parent d96cdd6c85
commit 5b2986d685
17 changed files with 99 additions and 20 deletions

View File

@ -2195,7 +2195,8 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str,
speakerName = \ speakerName = \
getDisplayName(baseDir, postJsonObject['actor'], personCache) getDisplayName(baseDir, postJsonObject['actor'], personCache)
gender = getGenderFromBio(baseDir, postJsonObject['actor'], personCache) gender = getGenderFromBio(baseDir, postJsonObject['actor'],
personCache, translate)
if not speakerName: if not speakerName:
return return
if announcingActor: if announcingActor:

View File

@ -381,5 +381,8 @@
"mentioning": "ذكر", "mentioning": "ذكر",
"sad face": "وجه حزين", "sad face": "وجه حزين",
"thinking emoji": "التفكير الرموز التعبيرية", "thinking emoji": "التفكير الرموز التعبيرية",
"laughing": "يضحك" "laughing": "يضحك",
"gender": "جنس تذكير أو تأنيث",
"He/Him": "هو",
"She/Her": "هي"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "esmentant", "mentioning": "esmentant",
"sad face": "cara trista", "sad face": "cara trista",
"thinking emoji": "emoji pensant", "thinking emoji": "emoji pensant",
"laughing": "rient" "laughing": "rient",
"gender": "gènere",
"He/Him": "Ell",
"She/Her": "Ella"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "sôn", "mentioning": "sôn",
"sad face": "wyneb trist", "sad face": "wyneb trist",
"thinking emoji": "meddwl emoji", "thinking emoji": "meddwl emoji",
"laughing": "chwerthin" "laughing": "chwerthin",
"gender": "rhyw",
"He/Him": "Ef",
"She/Her": "Hi/Ei"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "Erwähnen", "mentioning": "Erwähnen",
"sad face": "trauriges Gesicht", "sad face": "trauriges Gesicht",
"thinking emoji": "Emowji denken", "thinking emoji": "Emowji denken",
"laughing": "Lachen" "laughing": "Lachen",
"gender": "geschlecht",
"He/Him": "Er/ihm",
"She/Her": "Sie"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "mentioning", "mentioning": "mentioning",
"sad face": "sad face", "sad face": "sad face",
"thinking emoji": "thinking emowji", "thinking emoji": "thinking emowji",
"laughing": "laughing" "laughing": "laughing",
"gender": "gender",
"He/Him": "He/Him",
"She/Her": "She/Her"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "mencionar", "mentioning": "mencionar",
"sad face": "cara triste", "sad face": "cara triste",
"thinking emoji": "pensando emowji", "thinking emoji": "pensando emowji",
"laughing": "risa" "laughing": "risa",
"gender": "género",
"He/Him": "El",
"She/Her": "Ella"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "mentionnant", "mentioning": "mentionnant",
"sad face": "visage triste", "sad face": "visage triste",
"thinking emoji": "penser emowji", "thinking emoji": "penser emowji",
"laughing": "en riant" "laughing": "en riant",
"gender": "le genre",
"He/Him": "Il/Lui",
"She/Her": "Elle"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "ag lua", "mentioning": "ag lua",
"sad face": "aghaidh brónach", "sad face": "aghaidh brónach",
"thinking emoji": "ag smaoineamh emowji", "thinking emoji": "ag smaoineamh emowji",
"laughing": "ag gáire" "laughing": "ag gáire",
"gender": "inscne",
"He/Him": "Sé/Eisean",
"She/Her": "Sí"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "उल्लेख", "mentioning": "उल्लेख",
"sad face": "उदास चेहरा", "sad face": "उदास चेहरा",
"thinking emoji": "सोच रहे हैं इमोजी", "thinking emoji": "सोच रहे हैं इमोजी",
"laughing": "हस रहा" "laughing": "हस रहा",
"gender": "लिंग",
"He/Him": "वह/उसे",
"She/Her": "वह/उसकी"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "menzionando", "mentioning": "menzionando",
"sad face": "faccia triste", "sad face": "faccia triste",
"thinking emoji": "pensiero emoji", "thinking emoji": "pensiero emoji",
"laughing": "ridendo" "laughing": "ridendo",
"gender": "genere",
"He/Him": "Lui",
"She/Her": "Lei"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "言及する", "mentioning": "言及する",
"sad face": "悲しい顔", "sad face": "悲しい顔",
"thinking emoji": "絵文字を考える", "thinking emoji": "絵文字を考える",
"laughing": "笑い" "laughing": "笑い",
"gender": "性別",
"He/Him": "彼",
"She/Her": "彼女"
} }

View File

@ -377,5 +377,8 @@
"mentioning": "mentioning", "mentioning": "mentioning",
"sad face": "sad face", "sad face": "sad face",
"thinking emoji": "thinking emowji", "thinking emoji": "thinking emowji",
"laughing": "laughing" "laughing": "laughing",
"gender": "gender",
"He/Him": "He/Him",
"She/Her": "She/Her"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "mencionando", "mentioning": "mencionando",
"sad face": "rosto triste", "sad face": "rosto triste",
"thinking emoji": "pensando emowji", "thinking emoji": "pensando emowji",
"laughing": "rindo" "laughing": "rindo",
"gender": "gênero",
"He/Him": "Ele",
"She/Her": "Ela"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "упоминание", "mentioning": "упоминание",
"sad face": "грустное лицо", "sad face": "грустное лицо",
"thinking emoji": "думающий смайлик", "thinking emoji": "думающий смайлик",
"laughing": "смеющийся" "laughing": "смеющийся",
"gender": "Пол",
"He/Him": "Он/Его",
"She/Her": "Она/Ее"
} }

View File

@ -381,5 +381,8 @@
"mentioning": "提及", "mentioning": "提及",
"sad face": "悲伤的脸", "sad face": "悲伤的脸",
"thinking emoji": "思维表情符号", "thinking emoji": "思维表情符号",
"laughing": "笑" "laughing": "笑",
"gender": "",
"He/Him": "",
"She/Her": ""
} }

View File

@ -669,7 +669,8 @@ def getDisplayName(baseDir: str, actor: str, personCache: {}) -> str:
return nameFound return nameFound
def getGenderFromBio(baseDir: str, actor: str, personCache: {}) -> str: def getGenderFromBio(baseDir: str, actor: str, personCache: {},
translate: {}) -> str:
"""Tries to ascertain gender from bio description """Tries to ascertain gender from bio description
""" """
if '/statuses/' in actor: if '/statuses/' in actor:
@ -678,7 +679,21 @@ def getGenderFromBio(baseDir: str, actor: str, personCache: {}) -> str:
return None return None
bioFound = None bioFound = None
if personCache[actor].get('actor'): if personCache[actor].get('actor'):
if personCache[actor]['actor'].get('summary'): # is gender defined as a profile tag?
if personCache[actor]['actor'].get('attachment'):
tagsList = personCache[actor]['actor']['attachment']
if isinstance(tagsList, list):
for tag in tagsList:
if not isinstance(tag, dict):
continue
if not tag.get('name') or not tag.get('value'):
continue
if tag['name'].lower() == \
translate['gender'].lower():
bioFound = tag['value']
break
# if not then use the bio
if not bioFound and personCache[actor]['actor'].get('summary'):
bioFound = personCache[actor]['actor']['summary'] bioFound = personCache[actor]['actor']['summary']
else: else:
# Try to obtain from the cached actors # Try to obtain from the cached actors
@ -687,14 +702,32 @@ def getGenderFromBio(baseDir: str, actor: str, personCache: {}) -> str:
if os.path.isfile(cachedActorFilename): if os.path.isfile(cachedActorFilename):
actorJson = loadJson(cachedActorFilename, 1) actorJson = loadJson(cachedActorFilename, 1)
if actorJson: if actorJson:
if actorJson.get('summary'): # is gender defined as a profile tag?
if actorJson.get('attachment'):
tagsList = actorJson['attachment']
if isinstance(tagsList, list):
for tag in tagsList:
if not isinstance(tag, dict):
continue
if not tag.get('name') or not tag.get('value'):
continue
if tag['name'].lower() == \
translate['gender'].lower():
bioFound = tag['value']
break
# if not then use the bio
if not bioFound and actorJson.get('summary'):
bioFound = actorJson['summary'] bioFound = actorJson['summary']
if not bioFound: if not bioFound:
return None return None
gender = 'They/Them' gender = 'They/Them'
bioFoundOrig = bioFound bioFoundOrig = bioFound
bioFound = bioFound.lower() bioFound = bioFound.lower()
if 'him' in bioFound or 'male' in bioFound: if translate['He/Him'] in bioFound:
gender = 'He/Him'
elif translate['She/Her'] in bioFound:
gender = 'She/Her'
elif 'him' in bioFound or 'male' in bioFound:
gender = 'He/Him' gender = 'He/Him'
elif 'her' in bioFound or 'she' in bioFound or \ elif 'her' in bioFound or 'she' in bioFound or \
'fem' in bioFound or 'woman' in bioFound: 'fem' in bioFound or 'woman' in bioFound: