User:MewBot/caverbformbot.py
Jump to navigation
Jump to search
#!/usr/bin/env python
#coding: utf-8
# Copyright CodeCat 2010 - 2013
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import wikipedia, re
from formbot import *
class CAVerbFormBot(GenericFormBot):
"""A form bot for Catalan verb forms."""
def __init__(self, head, cleanupCat, simulation = False, force = False, verbose = False):
GenericFormBot.__init__(
self, head, [
'ca-conj-ar',
u'ca-conj-re',
u'ca-conj-er',
u'ca-conj-dre',
u'ca-conj-ure-ïa',
u'ca-conj-ure-via',
u'ca-conj-ure-ia',
u'ca-conj-ir',
u'ca-conj-ir-pure'], 'ca', 'Catalan',
cleanupCat, simulation, force, verbose)
def generateEntries(self, template, params):
"""Overrides base class method."""
if 'refl' in params:
return None
# Add the bot=1 parameter and expand the template, which will return a machine-readable version of the table
params["bot"] = "1"
templatestring = makeTemplate(template, params)
wikipedia.output(templatestring)
contents = wikipedia.getSite('en', 'wiktionary').getExpandedString(templatestring)
# Convert the returned wikitext into a dictionary
contents = string.split(string.strip(contents), '\n')
forms = {}
for line in contents:
match = re.match(ur"^\* ([^=]+)=(.+)", line)
if not match:
wikipedia.output("Template generated invalid output, aborting...")
return None
forms[match.group(1)] = match.group(2)
# Make a dictionary of lists of the definitions, with the word as key
# That way we automatically group cases where two forms are identical
definitions = {}
# Non-finite forms
definitions.setdefault(forms['pres_part'], []).append('{{ca-verb form of|t=pres|m=ptc|' + self._head + '}}')
definitions.setdefault(forms['past_part'], []).append('{{ca-verb form of|t=past|m=ptc|' + self._head + '}}')
# Present indicative
definitions.setdefault(forms['pres_ind_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=pres|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pres_ind_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=pres|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pres_ind_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=pres|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pres_ind_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=pres|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pres_ind_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=pres|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pres_ind_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=pres|m=ind|' + self._head + '}}')
# Imperfect indicative
definitions.setdefault(forms['impf_ind_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=impf|m=ind|' + self._head + '}}')
definitions.setdefault(forms['impf_ind_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=impf|m=ind|' + self._head + '}}')
definitions.setdefault(forms['impf_ind_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=impf|m=ind|' + self._head + '}}')
definitions.setdefault(forms['impf_ind_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=impf|m=ind|' + self._head + '}}')
definitions.setdefault(forms['impf_ind_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=impf|m=ind|' + self._head + '}}')
definitions.setdefault(forms['impf_ind_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=impf|m=ind|' + self._head + '}}')
# Future indicative
definitions.setdefault(forms['futr_ind_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=futr|m=ind|' + self._head + '}}')
definitions.setdefault(forms['futr_ind_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=futr|m=ind|' + self._head + '}}')
definitions.setdefault(forms['futr_ind_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=futr|m=ind|' + self._head + '}}')
definitions.setdefault(forms['futr_ind_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=futr|m=ind|' + self._head + '}}')
definitions.setdefault(forms['futr_ind_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=futr|m=ind|' + self._head + '}}')
definitions.setdefault(forms['futr_ind_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=futr|m=ind|' + self._head + '}}')
# Preterite indicative
definitions.setdefault(forms['pret_ind_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=pret|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pret_ind_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=pret|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pret_ind_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=pret|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pret_ind_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=pret|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pret_ind_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=pret|m=ind|' + self._head + '}}')
definitions.setdefault(forms['pret_ind_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=pret|m=ind|' + self._head + '}}')
# Conditional
definitions.setdefault(forms['cond_1sg'], []).append('{{ca-verb form of|p=1|n=sg|m=cond|' + self._head + '}}')
definitions.setdefault(forms['cond_2sg'], []).append('{{ca-verb form of|p=2|n=sg|m=cond|' + self._head + '}}')
definitions.setdefault(forms['cond_3sg'], []).append('{{ca-verb form of|p=3|n=sg|m=cond|' + self._head + '}}')
definitions.setdefault(forms['cond_1pl'], []).append('{{ca-verb form of|p=1|n=pl|m=cond|' + self._head + '}}')
definitions.setdefault(forms['cond_2pl'], []).append('{{ca-verb form of|p=2|n=pl|m=cond|' + self._head + '}}')
definitions.setdefault(forms['cond_3pl'], []).append('{{ca-verb form of|p=3|n=pl|m=cond|' + self._head + '}}')
# Present subjunctive
definitions.setdefault(forms['pres_sub_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=pres|m=sub|' + self._head + '}}')
definitions.setdefault(forms['pres_sub_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=pres|m=sub|' + self._head + '}}')
definitions.setdefault(forms['pres_sub_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=pres|m=sub|' + self._head + '}}')
definitions.setdefault(forms['pres_sub_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=pres|m=sub|' + self._head + '}}')
definitions.setdefault(forms['pres_sub_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=pres|m=sub|' + self._head + '}}')
definitions.setdefault(forms['pres_sub_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=pres|m=sub|' + self._head + '}}')
# Imperfect subjunctive
definitions.setdefault(forms['impf_sub_1sg'], []).append('{{ca-verb form of|p=1|n=sg|t=impf|m=sub|' + self._head + '}}')
definitions.setdefault(forms['impf_sub_2sg'], []).append('{{ca-verb form of|p=2|n=sg|t=impf|m=sub|' + self._head + '}}')
definitions.setdefault(forms['impf_sub_3sg'], []).append('{{ca-verb form of|p=3|n=sg|t=impf|m=sub|' + self._head + '}}')
definitions.setdefault(forms['impf_sub_1pl'], []).append('{{ca-verb form of|p=1|n=pl|t=impf|m=sub|' + self._head + '}}')
definitions.setdefault(forms['impf_sub_2pl'], []).append('{{ca-verb form of|p=2|n=pl|t=impf|m=sub|' + self._head + '}}')
definitions.setdefault(forms['impf_sub_3pl'], []).append('{{ca-verb form of|p=3|n=pl|t=impf|m=sub|' + self._head + '}}')
# Imperative
definitions.setdefault(forms['impr_2sg'], []).append('{{ca-verb form of|p=2|n=sg|m=impr|' + self._head + '}}')
definitions.setdefault(forms['impr_3sg'], []).append('{{ca-verb form of|p=3|n=sg|m=impr|' + self._head + '}}')
definitions.setdefault(forms['impr_1pl'], []).append('{{ca-verb form of|p=1|n=pl|m=impr|' + self._head + '}}')
definitions.setdefault(forms['impr_2pl'], []).append('{{ca-verb form of|p=2|n=pl|m=impr|' + self._head + '}}')
definitions.setdefault(forms['impr_3pl'], []).append('{{ca-verb form of|p=3|n=pl|m=impr|' + self._head + '}}')
return self.zipEntries(definitions, '===Verb===\n{{head|ca|verb form}}\n\n')