Conjugate in the Spanish imperfect / Conjugue en el imperfecto de indicativo
Retina, 100 82 bytes
\B[^a]r$
I
r$
b
^vI$
veI
^sI$
er
$
a
$
$_s $_ $_mos $_is $_n
T`l`L`.(?=[^I]amos )
Try it online. Unfortunately, due to the use of $_
it's not possible to modify the code to run all tests at once, so you'll have to copy in the individual verbs. I'm working on a new feature that will make this possible though.
Explanation
\B[^a]r$
I
We start by turning all endings which aren't ar
into I
, provided the input isn't the irregular verb ir
. That takes care of the -er
, -ir
, -ír
conjugations, messes up the irregular verbs ser
and ver
(but shortens them in the process), and leaves only ir
and -ar
with a trailing r
.
r$
b
If the word still ends in r
, we replace that with a b
. We've now covered all standard conjugations as well as the irregular verb ir
.
^vI$
veI
This fixes the irregular verb ver
which has been turned into vI
in the first stage.
^sI$
er
This fixes the irregular verb ser
which has been turned into sI
in the first stage. Now we've modified all possible stems correctly. All that's left to do is append all the possible endings, and then fix the accent for the first person plural in some cases.
$
a
First we append an a
to the stem, because that's always part of all endings.
$
$_s $_ $_mos $_is $_n
This makes use of the rarely seen $_
which inserts the entire string into the substitution (regardless of what was matched). This is actually very useful when duplicating strings, as are $`
and $'
, which are also quite underappreciated.
Before this stage, we've got the first person singular in the string. We now append the other conjugations, by matching the end of the string with $
and building the other forms by appending the appropriate suffixes to the first person singular.
T`l`L`.(?=[^I]amos )
Finally, we fix the accent for the first person plural if applicable. This only needs to be done for a vowel, two characters in front of the -amos
unless the character in between is I
. So we match such a character and then use a transliteration stage to convert lower to upper case. This makes use of the new character classes l
and L
which I only added yesterday. They expand to a-z
and A-Z
respectively, so that new feature saves 4 bytes here.
Python 3, 154 232 bytes
M=input()
Q={'ser':'er','ver':'veI','ir':'ib'}.get(M)
H=[(Q if Q else M[:-2]+("ab"if M[-2:]=="ar"else"I"))+j for j in"a as a amos ais an".split(' ')]
if M[-2:]=="ar":H[3]=M[:-2]+"Abamos"
if Q in['er','ib']:H[3]=H[3].title()
print(H)
Fixed the missing capitals in irregular verbs.
Ungolfed
M=input()
Q={'ser':'er','ver':'veI','ir':'ib'}.get(M)
H=[]
for j in "a as a amos ais an".split(' '):
if Q:
F = Q
else:
if M[-2:] == "ar":
F = M[:-2] + "ab"
else:
F = M[:-2] + "I"
H += [F + j]
if M[-2:] == "ar":
H[3] = M[:-2] + "Abamos"
if Q in ['er', 'ib']:
H[3] = H[3].title()
print(H)