diff --git a/setup.py b/setup.py index 3503a0f..3dd205f 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='2.0.0', + version='2.0.1', zip_safe=False, description='The NLG tool for Finnish', long_description=long_description, diff --git a/syntaxmaker/phrase.py b/syntaxmaker/phrase.py index ae62092..18fac62 100644 --- a/syntaxmaker/phrase.py +++ b/syntaxmaker/phrase.py @@ -4,14 +4,11 @@ import copy import re, sys +unicode = str + class Phrase: def __init__(self, head, structure, morphology={}): - if (sys.version_info > (3, 0)): - # Python 3 - self.new_python = True - else: - # Python 2 - self.new_python = False + self.new_python = True self.parent = None self.head = Head(head, structure["head"]) self.components = copy.deepcopy(structure["components"]) @@ -33,13 +30,17 @@ def __init__(self, head, structure, morphology={}): def resolve_agreement(self): forms = {} for key in self.agreement: - if key == "parent": + if key == "parent" and self.parent is not None: morphology = self.parent.morphology - elif key.startswith("parent->"): + elif key.startswith("parent->")and self.parent is not None: key_p = key[8:] morphology = self.parent.components[key_p].morphology - else: + elif key in self.components: morphology = self.components[key].morphology + else: + r = {"CASE": "Nom", "NUM": "SG", "PERS": "3"} + r.update(self.morphology) + return r for agreement_type in self.agreement[key]: forms[agreement_type] = morphology[agreement_type] return forms @@ -47,6 +48,12 @@ def resolve_agreement(self): def to_string(self, received_governance = {}): self.morphology.update(received_governance) string_representation = "" + if "dir_object" in self.components: + if type(self.components["dir_object"]) is not str: + if "NUM" in self.components["dir_object"].morphology and self.components["dir_object"].morphology["NUM"] == "PL": + if "dir_object" in self.governance: + if self.governance["dir_object"]["CASE"] == "Gen": + self.governance["dir_object"]["CASE"] = "Par" for item in self.order: if item == "head": head_word = self.head.get_form(self.morphology, self.resolve_agreement()) diff --git a/testi.py b/testi.py index d427526..4ecc392 100644 --- a/testi.py +++ b/testi.py @@ -25,14 +25,17 @@ print vp """ -vp = create_verb_pharse("uneksia") -subject = create_phrase("NP", "rantaleijona", {u"PERS": "3", u"NUM": "PL"}) -dobject = create_phrase("NP", "aalto", {u"PERS": "3", u"NUM": "PL"}) -dobject.components["attribute"] = create_phrase("AP", "korkea") + +vp = create_verb_pharse("antaa") +subject = create_phrase("NP", "hevonen", {"NUM": "PL"}) + +dobject = create_phrase("NP", "lahja", {"NUM": "PL"}) +dobject.components["attribute"] = create_phrase("AP", "mahtava") dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin") + +indobject = create_phrase("NP", "lehmä") vp.components["subject"] = subject vp.components["dir_object"] = dobject -turn_vp_into_prefect(vp) -turn_vp_into_passive(vp) -set_vp_mood_and_tense(vp, tense="PAST") +vp.components["indir_object"] = indobject + print(vp) \ No newline at end of file diff --git a/travis_test.py b/travis_test.py index e9eb364..a6b0b38 100644 --- a/travis_test.py +++ b/travis_test.py @@ -62,6 +62,39 @@ def test_pot(self): set_vp_mood_and_tense(vp, mood="POTN") self.assertEqual(str(vp) , "rantaleijonat uneksinevat erittäin korkeista aalloista") + def test_total_plural(self): + vp = create_verb_pharse("antaa") + subject = create_phrase("NP", "hevonen", {"NUM": "PL"}) + + dobject = create_phrase("NP", "lahja", {"NUM": "PL"}) + dobject.components["attribute"] = create_phrase("AP", "hyvä") + dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin") + + indobject = create_phrase("NP", "lehmä") + vp.components["subject"] = subject + vp.components["dir_object"] = dobject + vp.components["indir_object"] = indobject + self.assertEqual(str(vp) , "hevoset antavat erittäin hyviä lahjoja lehmälle") + + def test_total_plural_neg(self): + vp = create_verb_pharse("antaa") + subject = create_phrase("NP", "hevonen", {"NUM": "PL"}) + + dobject = create_phrase("NP", "lahja", {"NUM": "PL"}) + dobject.components["attribute"] = create_phrase("AP", "hyvä") + dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin") + + indobject = create_phrase("NP", "lehmä") + vp.components["subject"] = subject + vp.components["dir_object"] = dobject + vp.components["indir_object"] = indobject + negate_verb_pharse(vp) + self.assertEqual(str(vp) , "hevoset eivät anna erittäin hyviä lahjoja lehmälle") + + def test_adj(self): + ap = create_adjective_phrase("kaunis", degree="Comp") + self.assertEqual(str(ap), "kauniimpi") + def test_cond(self): vp = copy.deepcopy(self.vp) set_vp_mood_and_tense(vp, mood="COND")