Skip to content

Commit

Permalink
Fixed retrieval of pronoun agreement based on verb phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdj committed Mar 14, 2019
1 parent 83a878a commit 5e96a95
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
23 changes: 17 additions & 6 deletions src/simplenlg/morphology/dutch/MorphologyRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions src/simplenlg/morphology/english/NonStaticMorphologyRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 5e96a95

Please sign in to comment.