/**
   * Creates the appropriate pronoun if the subject of the noun phrase is pronominal.
   *
   * @param parent the parent <code>SyntaxProcessor</code> that will do the realisation of the
   *     complementiser.
   * @param phrase the <code>PhraseElement</code> representing this noun phrase.
   * @return the <code>NLGElement</code> representing the pronominal.
   */
  private static NLGElement createPronoun(SyntaxProcessor parent, PhraseElement phrase) {

    String pronoun = "it"; // $NON-NLS-1$
    NLGFactory phraseFactory = phrase.getFactory();
    Object personValue = phrase.getFeature(Feature.PERSON);

    if (Person.FIRST.equals(personValue)) {
      pronoun = "I"; // $NON-NLS-1$
    } else if (Person.SECOND.equals(personValue)) {
      pronoun = "you"; // $NON-NLS-1$
    } else {
      Object genderValue = phrase.getFeature(LexicalFeature.GENDER);
      if (Gender.FEMININE.equals(genderValue)) {
        pronoun = "she"; // $NON-NLS-1$
      } else if (Gender.MASCULINE.equals(genderValue)) {
        pronoun = "he"; // $NON-NLS-1$
      }
    }
    // AG: createWord now returns WordElement; so we embed it in an
    // inflected word element here
    NLGElement element;
    NLGElement proElement = phraseFactory.createWord(pronoun, LexicalCategory.PRONOUN);

    if (proElement instanceof WordElement) {
      element = new InflectedWordElement((WordElement) proElement);
      element.setFeature(
          LexicalFeature.GENDER, ((WordElement) proElement).getFeature(LexicalFeature.GENDER));
      // Ehud - also copy over person
      element.setFeature(Feature.PERSON, ((WordElement) proElement).getFeature(Feature.PERSON));
    } else {
      element = proElement;
    }

    element.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SPECIFIER);
    element.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE));
    element.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));

    if (phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION)) {
      element.setFeature(
          InternalFeature.DISCOURSE_FUNCTION,
          phrase.getFeature(InternalFeature.DISCOURSE_FUNCTION));
    }

    return element;
  }
  /**
   * This method performs the morphology for verbs.
   *
   * @param element the <code>InflectedWordElement</code>.
   * @param baseWord the <code>WordElement</code> as created from the lexicon entry.
   * @return a <code>StringElement</code> representing the word after inflection.
   */
  public NLGElement doVerbMorphology(InflectedWordElement element, WordElement baseWord) {

    String realised = null;
    Object numberValue = element.getFeature(Feature.NUMBER);
    Object personValue = element.getFeature(Feature.PERSON);
    Object tenseValue = element.getFeature(Feature.TENSE);
    Object formValue = element.getFeature(Feature.FORM);
    Object patternValue = element.getFeature(Feature.PATTERN);

    // base form from baseWord if it exists, otherwise from element
    String baseForm = getBaseForm(element, baseWord);

    if (element.isNegated() || Form.BARE_INFINITIVE.equals(formValue)) {
      realised = baseForm;
    } else if (Form.PRESENT_PARTICIPLE.equals(formValue)) {
      realised = element.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE);

      if (realised == null && baseWord != null) {
        realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE);
      }
      if (realised == null) {
        if (Pattern.REGULAR_DOUBLE.equals(patternValue)) {
          realised = buildDoublePresPartVerb(baseForm);
        } else {
          realised = buildRegularPresPartVerb(baseForm);
        }
      }
    } else if (Tense.PAST.equals(tenseValue) || Form.PAST_PARTICIPLE.equals(formValue)) {
      if (Form.PAST_PARTICIPLE.equals(formValue)) {
        realised = element.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE);

        if (realised == null && baseWord != null) {
          realised = baseWord.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE);
        }
        if (realised == null) {
          if ("be".equalsIgnoreCase(baseForm)) { // $NON-NLS-1$
            realised = "been"; // $NON-NLS-1$
          } else if (Pattern.REGULAR_DOUBLE.equals(patternValue)) {
            realised = buildDoublePastVerb(baseForm);
          } else {
            realised = buildRegularPastVerb(baseForm, numberValue);
          }
        }
      } else {
        realised = element.getFeatureAsString(LexicalFeature.PAST);

        if (realised == null && baseWord != null) {
          realised = baseWord.getFeatureAsString(LexicalFeature.PAST);
        }
        if (realised == null) {
          if (Pattern.REGULAR_DOUBLE.equals(patternValue)) {
            realised = buildDoublePastVerb(baseForm);
          } else {
            realised = buildRegularPastVerb(baseForm, numberValue);
          }
        }
      }
    } else if ((numberValue == null || NumberAgreement.SINGULAR.equals(numberValue))
        && (personValue == null || Person.THIRD.equals(personValue))
        && (tenseValue == null || Tense.PRESENT.equals(tenseValue))) {

      realised = element.getFeatureAsString(LexicalFeature.PRESENT3S);

      if (realised == null && baseWord != null && !"be".equalsIgnoreCase(baseForm)) { // $NON-NLS-1$
        realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT3S);
      }
      if (realised == null) {
        realised = buildPresent3SVerb(baseForm);
      }
    } else {
      if ("be".equalsIgnoreCase(baseForm)) { // $NON-NLS-1$
        if (Person.FIRST.equals(personValue)
            && (NumberAgreement.SINGULAR.equals(numberValue) || numberValue == null)) {
          realised = "am"; // $NON-NLS-1$
        } else {
          realised = "are"; // $NON-NLS-1$
        }
      } else {
        realised = baseForm;
      }
    }
    // vaudrypl added element as 2nd argument
    StringElement realisedElement = new StringElement(realised, element);
    realisedElement.setFeature(
        InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION));
    return realisedElement;
  }