Ejemplo n.º 1
0
  /**
   * ************************************************************************************************************
   * If we haven't managed to create a subject, try creating one with Patient. The result will be
   * "experiences" + the process verb in a noun form. This can be seen as a precursor of correct
   * passive voice.
   */
  private void doPassiveVoice() {
    List<CaseRole> caseRolesToUse =
        Lists.newArrayList(
            CaseRole.EXPERIENCER,
            CaseRole.MOVES,
            CaseRole.PATIENT,
            CaseRole.RESOURCE,
            CaseRole.ATTENDS);

    // Set subject.
    StringBuilder sBuild = new StringBuilder();
    for (CaseRole role : caseRolesToUse) {
      String obj = formulateNounPhraseForCaseRole(role, subject, kb);
      if (!obj.isEmpty()) {
        sBuild.append(" ").append(obj).append(" ");
        getCaseRolesScratchpad().removeAll(role);
        break;
      }
    }

    subject.setSurfaceForm(sBuild.toString().replaceAll("\\s+", " ").trim());

    // Set verb to "experiences" and the direct object to a noun form of the process.
    verb.setVerbAndDirectObject(this);
  }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
0
 /**
  * ************************************************************************************************************
  */
 void formulateNaturalVerb() {
   verb.formulateNaturalVerb(this);
 }