|
28 | 28 | import simplenlg.features.Pattern;
|
29 | 29 | import simplenlg.features.Person;
|
30 | 30 | import simplenlg.features.Tense;
|
31 |
| -import simplenlg.framework.InflectedWordElement; |
32 |
| -import simplenlg.framework.LexicalCategory; |
33 |
| -import simplenlg.framework.NLGElement; |
34 |
| -import simplenlg.framework.PhraseCategory; |
35 |
| -import simplenlg.framework.StringElement; |
36 |
| -import simplenlg.framework.WordElement; |
| 31 | +import simplenlg.framework.*; |
37 | 32 | import simplenlg.morphology.MorphologyRulesInterface;
|
| 33 | +import simplenlg.phrasespec.SPhraseSpec; |
38 | 34 |
|
39 | 35 | /**
|
40 | 36 | * This is a dynamic version of the abstract class MorphologyRules, with
|
@@ -760,17 +756,61 @@ public NLGElement doPronounMorphology(InflectedWordElement element) {
|
760 | 756 | .booleanValue()) {
|
761 | 757 | Object genderValue = element.getFeature(LexicalFeature.GENDER);
|
762 | 758 | Object personValue = element.getFeature(Feature.PERSON);
|
| 759 | + Object numberValue = element.getFeature(Feature.NUMBER); |
| 760 | + int numberIndex = element.isPlural() ? 1 : 0; |
| 761 | + |
| 762 | + boolean reflexive = element.getFeatureAsBoolean(LexicalFeature.REFLEXIVE); |
| 763 | + NLGElement parent = element.getParent(); |
| 764 | + |
| 765 | + // agree the reflexive pronoun with the subject |
| 766 | + if (reflexive && parent != null) { |
| 767 | + NLGElement grandParent = parent.getParent(); |
| 768 | + |
| 769 | + if (grandParent != null && grandParent.getCategory().equalTo(PhraseCategory.VERB_PHRASE)) { |
| 770 | + |
| 771 | + // Get the subject |
| 772 | + NLGElement subject = grandParent; |
| 773 | + boolean hasFoundSubject = false; |
| 774 | + while (!hasFoundSubject) { |
| 775 | + subject = subject.getParent(); |
| 776 | + for (NLGElement child : subject.getChildren()) { |
| 777 | + if (DiscourseFunction.SUBJECT.equals(child.getFeature(InternalFeature.DISCOURSE_FUNCTION))) { |
| 778 | + subject = child; |
| 779 | + hasFoundSubject = true; |
| 780 | + } |
| 781 | + } |
| 782 | + } |
| 783 | + |
| 784 | + genderValue = subject.getFeature(LexicalFeature.GENDER); |
| 785 | + personValue = subject.getFeature(Feature.PERSON); |
| 786 | + numberValue = subject.getFeature(Feature.NUMBER); |
| 787 | + numberIndex = NumberAgreement.PLURAL.equals(numberValue) ? 1 |
| 788 | + : 0; |
| 789 | + |
| 790 | + // If the verb phrase is in imperative form, |
| 791 | + // the reflexive pronoun can only be in 2S, 1P or 2P. |
| 792 | + if (grandParent.getFeature(Feature.FORM) == Form.IMPERATIVE) { |
| 793 | + if (numberValue == NumberAgreement.PLURAL) { |
| 794 | + if (personValue != Person.FIRST && personValue != Person.SECOND) { |
| 795 | + personValue = Person.SECOND; |
| 796 | + } |
| 797 | + } else { |
| 798 | + personValue = Person.SECOND; |
| 799 | + } |
| 800 | + } |
| 801 | + } |
| 802 | + } |
| 803 | + if (!(personValue instanceof Person)) personValue = Person.THIRD; |
| 804 | + if (!(numberValue instanceof NumberAgreement)) numberValue = NumberAgreement.SINGULAR; |
763 | 805 |
|
764 | 806 | // way of getting discourseValue changed by vaudrypl
|
765 |
| - NLGElement parent = element.getParent(); |
766 | 807 | Object discourseValue = element.getFeature(InternalFeature.DISCOURSE_FUNCTION);
|
767 | 808 | if (discourseValue == DiscourseFunction.SUBJECT && parent != null
|
768 | 809 | && parent.isA(PhraseCategory.NOUN_PHRASE)) {
|
769 | 810 | discourseValue = parent.getFeature(InternalFeature.DISCOURSE_FUNCTION);
|
770 | 811 | }
|
771 | 812 | if (!(discourseValue instanceof DiscourseFunction)) discourseValue = DiscourseFunction.SUBJECT;
|
772 | 813 |
|
773 |
| - int numberIndex = element.isPlural() ? 1 : 0; |
774 | 814 | int genderIndex = (genderValue instanceof Gender) ? ((Gender) genderValue)
|
775 | 815 | .ordinal()
|
776 | 816 | : 2;
|
|
0 commit comments