Esempio n. 1
0
  /**
   * ************************************************************************************************************
   * Attempt to perform natural language generation on this object.
   *
   * @return a sentence in natural language, or empty string on failure
   */
  public String toNaturalLanguage() {

    formulateNaturalSubject();
    formulateNaturalVerb();
    formulateNaturalDirectObject();
    formulateNaturalIndirectObject();

    if (subject.getSurfaceForm().isEmpty()) {
      reset();
      doPassiveVoice();
    }

    // If no subject, perform no NLG.
    if (subject.getSurfaceForm().isEmpty()) {
      return "";
    }

    String indirectObjectStr = concatenateIndirectObjects();
    String cleanedStr =
        (subject.getSurfaceForm()
            + " "
            + verb.getSurfaceForm()
            + " "
            + directObject.getSurfaceForm()
            + " "
            + indirectObjectStr);

    return cleanedStr.replaceAll("\\s+", " ").trim();
  }