From 3c26fcf7016994ba437c4edfa0252bdc9c784f31 Mon Sep 17 00:00:00 2001 From: Kay Faraday Date: Fri, 13 Jan 2023 02:38:15 +0000 Subject: [PATCH] fix conjugation of verbs ending in `e`, move the conjugation to a separate file --- conjugate.py | 13 +++++++++++++ ljfbot.py | 14 ++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 conjugate.py diff --git a/conjugate.py b/conjugate.py new file mode 100644 index 0000000..d5725be --- /dev/null +++ b/conjugate.py @@ -0,0 +1,13 @@ +def conjugate(verb): + if verb[-2:] == 'ed' and verb[-3] not in {'a', 'e', 'i', 'o', 'u'}: + verb = verb[:-2] + if verb[-1] in {'a', 'i', 'o', 'u'}: + verb = verb + 'es' + elif verb[-1] != 'e' and (verb[-1] in {'s', 'x'} or verb[-2] in {'s', 'x'} or verb[-2:] == 'ch'): + verb = verb + 'es' + elif verb[-1] == 'y' and verb[-2] not in {'a', 'e', 'i', 'o', 'u'}: + verb = verb[:-1] + 'ies' + else: + verb = verb + 's' + + return verb diff --git a/ljfbot.py b/ljfbot.py index f89c1ce..2a51b15 100755 --- a/ljfbot.py +++ b/ljfbot.py @@ -1,8 +1,8 @@ #!/usr/bin/env python import random +from conjugate import conjugate from mastodon import Mastodon -import os import json5 as json with open('config.json') as f: @@ -25,17 +25,7 @@ postform = random.choice(( '{gender} who {verb}', )) gender = random.choice(('lgf', 'lbf', 'lef')) -verb = random.choice(verbs) -if verb[-2:] == 'ed' and verb[-3] not in {'a', 'e', 'i', 'o', 'u'}: - verb = verb[:-2] -if verb[-1] in {'a', 'i', 'o', 'u'}: - verb = verb + 'es' -elif verb[-1] in {'s', 'x'} or verb[-2] in {'s', 'x'} or verb[-2:] == 'ch': - verb = verb + 'es' -elif verb[-1] == 'y' and verb[-2] not in {'a', 'e', 'i', 'o', 'u'}: - verb = verb[:-1] + 'ies' -else: - verb = verb + 's' +verb = conjugate(random.choice(verbs)) adjective = random.choice(adjectives) content = postform.format(adjective=adjective, gender=gender, verb=verb) print(content)