コード例 #1
0
  /**
   * This method performs the morphology for adjectives.
   *
   * @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 doAdjectiveMorphology(InflectedWordElement element, WordElement baseWord) {

    String realised = null;
    Object patternValue = element.getFeature(Feature.PATTERN);

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

    if (element.getFeatureAsBoolean(Feature.IS_COMPARATIVE).booleanValue()) {
      realised = element.getFeatureAsString(LexicalFeature.COMPARATIVE);

      if (realised == null && baseWord != null) {
        realised = baseWord.getFeatureAsString(LexicalFeature.COMPARATIVE);
      }
      if (realised == null) {
        if (Pattern.REGULAR_DOUBLE.equals(patternValue)) {
          realised = buildDoubleCompAdjective(baseForm);
        } else {
          realised = buildRegularComparative(baseForm);
        }
      }
    } else if (element.getFeatureAsBoolean(Feature.IS_SUPERLATIVE).booleanValue()) {

      realised = element.getFeatureAsString(LexicalFeature.SUPERLATIVE);

      if (realised == null && baseWord != null) {
        realised = baseWord.getFeatureAsString(LexicalFeature.SUPERLATIVE);
      }
      if (realised == null) {
        if (Pattern.REGULAR_DOUBLE.equals(patternValue)) {
          realised = buildDoubleSuperAdjective(baseForm);
        } else {
          realised = buildRegularSuperlative(baseForm);
        }
      }
    } 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;
  }
コード例 #2
0
  /**
   * 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;
  }