From 5e96a9508f1998b0dbba8c169f3c53dfbadc4c7c Mon Sep 17 00:00:00 2001 From: Ruud de Jong Date: Thu, 14 Mar 2019 10:57:13 +0100 Subject: [PATCH] Fixed retrieval of pronoun agreement based on verb phrase --- .../morphology/dutch/MorphologyRules.java | 23 ++++++++++++++----- .../english/NonStaticMorphologyRules.java | 15 ++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/simplenlg/morphology/dutch/MorphologyRules.java b/src/simplenlg/morphology/dutch/MorphologyRules.java index 50fdff9..647388b 100644 --- a/src/simplenlg/morphology/dutch/MorphologyRules.java +++ b/src/simplenlg/morphology/dutch/MorphologyRules.java @@ -1581,17 +1581,28 @@ public NLGElement doPronounMorphology(InflectedWordElement element) { if (!(gender instanceof Gender) || gender == Gender.NEUTER) gender = Gender.MASCULINE; Object person = element.getFeature(Feature.PERSON); - Object number = element.getFeature(Feature.NUMBER); + Object number = element.getFeature(Feature.NUMBER); + // agree the reflexive pronoun with the subject if (reflexive && parent != null) { - NLGElement grandParent = parent.getParent().getParent(); - if (grandParent != null && grandParent.getCategory().equalTo(PhraseCategory.VERB_PHRASE)) { - person = grandParent.getFeature(Feature.PERSON); - number = grandParent.getFeature(Feature.NUMBER); + NLGElement verbPhrase = null; + NLGElement grandParent = parent.getParent(); + NLGElement grandGrandParent = null; + + if (grandParent != null && grandParent.getCategory().equalTo(PhraseCategory.VERB_PHRASE)) { + verbPhrase = grandParent; + grandGrandParent = grandParent.getParent(); + } + if (grandGrandParent != null && grandGrandParent.getCategory().equalTo(PhraseCategory.VERB_PHRASE)) { + verbPhrase = grandGrandParent; + } + if (verbPhrase != null) { + person = verbPhrase.getFeature(Feature.PERSON); + number = verbPhrase.getFeature(Feature.NUMBER); // If the verb phrase is in imperative form, // the reflexive pronoun can only be in 2S, 1P or 2P. - if (grandParent.getFeature(Feature.FORM) == Form.IMPERATIVE) { + if (verbPhrase.getFeature(Feature.FORM) == Form.IMPERATIVE) { if (number == NumberAgreement.PLURAL) { if (person != Person.FIRST && person != Person.SECOND) { person = Person.SECOND; diff --git a/src/simplenlg/morphology/english/NonStaticMorphologyRules.java b/src/simplenlg/morphology/english/NonStaticMorphologyRules.java index b64d79c..5d6136b 100644 --- a/src/simplenlg/morphology/english/NonStaticMorphologyRules.java +++ b/src/simplenlg/morphology/english/NonStaticMorphologyRules.java @@ -770,14 +770,19 @@ public NLGElement doPronounMorphology(InflectedWordElement element) { // Get the subject NLGElement subject = grandParent; + NLGElement ancestor = grandParent; boolean hasFoundSubject = false; while (!hasFoundSubject) { - subject = subject.getParent(); - for (NLGElement child : subject.getChildren()) { - if (DiscourseFunction.SUBJECT.equals(child.getFeature(InternalFeature.DISCOURSE_FUNCTION))) { - subject = child; - hasFoundSubject = true; + ancestor = ancestor.getParent(); + if (ancestor != null) { + for (NLGElement child : ancestor.getChildren()) { + if (DiscourseFunction.SUBJECT.equals(child.getFeature(InternalFeature.DISCOURSE_FUNCTION))) { + subject = child; + hasFoundSubject = true; + } } + } else { + hasFoundSubject = true; } }