Last active
December 11, 2015 04:49
-
-
Save addrummond/4548031 to your computer and use it in GitHub Desktop.
This is a script for generating the strong paradigm for the Icelandic adjective 'kaldur' ('cold') according to the DM analysis given in a forthcoming paper on the Movement Theory of Control by me and Norbert Hornstein.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import sys | |
from itertools import * | |
from sets import * | |
vocab_items = [(x[0], Set(x[1])) for x in | |
(u'kalt', ()), | |
(u'kaldur', ('+A', '+B')), | |
(u'köld', ('-B',)), | |
(u'kaldan', ('-pl', '+acc', '+A', '+B')), | |
(u'kalda', ('-pl', '+acc', '+A', '-B')), | |
(u'köldum', ('+dat', '+A', '+B')), | |
(u'kaldri', ('-pl', '+dat', '-B')), | |
(u'köldu', ('+dat', '-A', '+B')), | |
(u'kaldrar', ('-pl', '+gen', '-B')), | |
(u'kalds', ('-pl', '+gen', '+A', '+B')), | |
(u'kaldir', ('+pl', '+A', '+B')), | |
(u'kaldar', ('+pl', '+A', '-B')), | |
(u'kaldra', ('+pl', '+gen', '+A', '-B')), | |
] | |
impoverishment_rules = [(Set(x[0]), Set(x[1])) for x in | |
(('+gen',), ('+A',)), | |
(('+pl', '+gen'), ('-B',)), | |
(('+pl', '-A'), ('-B',)), | |
(('+pl', '+dat'), ('+A', '+B', '-pl')), | |
(('+pl', '+acc', '+B'), ('-pl', '-B')) | |
] | |
def proper_subset(specification1, specification2): | |
left = False | |
right = False | |
for x in specification1: | |
if x not in specification2: | |
left = True | |
break | |
for x in specification2: | |
if x not in specification1: | |
right = True | |
break | |
return right and not left | |
def check_match(specification, item): | |
for f in specification: | |
if f not in item: | |
return False | |
return True | |
def apply_impoverishment_rule(rule, item_specification): | |
item_specification = [x for x in item_specification] | |
applied = False | |
if check_match(rule[0], item_specification): | |
applied = True | |
for f in rule[1]: | |
ff = (f[0] == '+' and '-' or '+') + f[1:] | |
if ff in item_specification: | |
i = item_specification.index(ff) | |
item_specification[i] = f | |
elif f not in item_specification: | |
item_specification.add(f) | |
return tuple(item_specification), applied | |
def filter_by_order(vocab_items): | |
lattice_levels = [[vocab_items[0]]] | |
for it in islice(vocab_items, 1, None): | |
inserted = False | |
for j in xrange(len(lattice_levels)): | |
if proper_subset(it[1], lattice_levels[j][0]): | |
inserted = True | |
if j == 0: | |
lattice_levels.insert(0, [it]) | |
else: | |
lattice_levels[j-1].append(it) | |
break | |
if not inserted: | |
for it2 in lattice_levels[-1]: | |
if proper_subset(it2[1], it[1]): | |
inserted = True | |
lattice_levels.append([it]) | |
break | |
if not inserted: | |
lattice_levels[-1].append(it) | |
return lattice_levels[-1] | |
def execute(impoverishment_rules, vocab_items, item_specification): | |
for r in impoverishment_rules: | |
item_specification, applied = apply_impoverishment_rule(r, item_specification) | |
matching = filter_by_order([x for x in vocab_items if check_match(x[1], item_specification)]) | |
if len(matching) > 1: | |
print "\n\nAmbiguity:", matching | |
return None, False | |
if len(matching) == 0: | |
return None, False | |
return matching[0], True | |
def print_icelandic_table(): | |
for pl in [['-pl'], ['+pl']]: | |
print (pl[0][0] == '-' and "[Singular]" or "[Plural] ") + " MASC FEM NEUTER" | |
for case in [['+nom'], ['+acc'], ['+dat'], ['+gen']]: | |
sys.stdout.write(case[0][1:].upper() + (" " * (11-len(case[0][1:])))) | |
for gender in [('masc', ['+A', '+B']), ('fem', ['+A', '-B']), ('neuter', ['-A', '+B'])]: | |
fs = [x for x in pl] | |
fs.extend(gender[1]) | |
fs.extend(case) | |
fs = tuple(fs) | |
x, ok = execute(impoverishment_rules, vocab_items, fs) | |
if not ok: | |
return | |
sys.stdout.write(x[0]) | |
if gender[0] != 'neuter': | |
sys.stdout.write(" " * (11-len(x[0]))) | |
else: | |
print_icelandic_table() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment