User:MewBot/nladjformbot.py

From Wiktionary, the free dictionary
Jump to navigation Jump to search
#!/usr/bin/env python
#coding: utf-8

# Copyright CodeCat 2010, 2011

# 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/>.

# This script is based on parts from
# http://en.wiktionary.org/wiki/User:SemperBlottoBot/verbs

import wikipedia, re
from formbot import *


class NLAdjectiveFormBot(GenericFormBot):
	"""A form bot for Dutch adjective forms."""
	
	def __init__(self, head, cleanupCat, simulation = False, force = False, verbose = False):
		GenericFormBot.__init__(
			self, head, ['nl-decl-adj', 'nl-decl-adj-nc'], 'nl', 'Dutch',
			cleanupCat, simulation, force, verbose)
	
	
	def generateEntries(self, template, params):
		"""Overrides base class method."""
		
		if template == 'nl-decl-adj':
			return self.decline(params)
		elif template == 'nl-decl-adj-nc':
			params[3] = '-'
			params[4] = '-'
			return self.decline(params)
		else:
			return None
	
	
	def decline(self, params):
		"""Decline a Dutch adjective using {{nl-decl-adj}}."""
		
		# Make a dictionary of lists of the entries, with the word as key
		# That way we automatically group cases where two forms are identical
		forms = {}
		
		if 1 not in params or params[1] != '-':
			infl = params.get(1, self._head + 'e')
			forms.setdefault(infl, []).append('{{nl-adj-form|f=infl|' + self._head + '}}')
		else:
			infl = self._head + 'e'
		
		if 2 not in params or params[2] != '-':
			part = params.get(2, self._head + 's')
			forms.setdefault(part, []).append('{{nl-adj-form|f=part|' + self._head + '}}')
		else:
			part = self._head + 's'
		
		if 3 not in params or params[3] != '-':
			comp = params.get(3, infl + 'r')
			forms.setdefault(comp, []).append('{{nl-adj-form|d=comp|' + self._head + '}}')
			
			if 1 not in params or params[1] != '-':
				inflComp = comp + 'e'
				forms.setdefault(inflComp, []).append('{{nl-adj-form|f=infl|d=comp|' + self._head + '}}')
			
			partComp = comp + 's'
			forms.setdefault(partComp, []).append('{{nl-adj-form|f=part|d=comp|' + self._head + '}}')
		
		if 4 not in params or params[4] != '-':
			sup = params.get(4, part + 't')
			forms.setdefault(sup, []).append('{{nl-adj-form|d=sup|' + self._head + '}}')
			
			inflSup = sup + 'e'
			forms.setdefault(inflSup, []).append('{{nl-adj-form|f=infl|d=sup|' + self._head + '}}')
		
		forms = self.zipEntries(forms, '==={0}===\n{{{{head|{1}|{2} form}}}}\n\n'.format('Adjective', self._langCode, 'adjective'))
		
		return forms