Instantly share code, notes, and snippets.

@johl johl/
Last active Dec 16, 2015

What would you like to do?
from __future__ import print_function
import json
import re
import sys
import urllib2
if len(sys.argv) < 2:
sys.exit('Abfrage mit: %s Substantiv' % sys.argv[0])
substantiv = sys.argv[1]
r = urllib2.urlopen(
'' +
'format=json' +
'&action=query' +
'&prop=revisions' +
'&rvprop=content' +
'&titles=' +
except urllib2.URLError, e:
sys.exit('Problem beim Zugriff auf Wiktionary.')
content = json.loads(r)
page = content['query']['pages'][content['query']['pages'].keys()[0]]
if 'revisions' not in page.keys():
'Substantiv nicht im deutschsprachigen Wiktionary verzeichnet.'
wikitext = (page['revisions'][0]['*'])
match =
'===\s?{{Wortart\|Substantiv\|Deutsch}},\s?' +
'{{([mfn])([mfn])?([mfn])?}}' +
'(,\s?{{([mfn])}}(,\s?{{([mfn])}})?)*' +
if match is None:
sys.exit('Kein Substantiv!')
genera = filter(lambda x: re.match('^[mfn]$', x),
filter(lambda x: x is not None, match.groups()))
m = ["der " + substantiv for genus in genera if genus == "m"]
f = ["die " + substantiv for genus in genera if genus == "f"]
n = ["das " + substantiv for genus in genera if genus == "n"]
artikel = m + f + n
map(print, artikel)

This comment has been minimized.

Copy link
Owner Author

johl commented May 4, 2013

$ python Knoblauch
der Knoblauch
$ python Ketchup
der Ketchup
das Ketchup
$ python Joghurt
der Joghurt
das Joghurt
die Joghurt
$ python finden
Kein Substantiv!
$ python djshdjhsdowhdowde
Substantiv nicht im deutschsprachigen Wiktionary verzeichnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment