Beispiel #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);
  }
Beispiel #2
0
  /**
   * ************************************************************************************************************
   * Put the "direct object" of this process into natural language.
   */
  void formulateNaturalDirectObject() {
    StringBuilder sBuild = new StringBuilder();

    VerbProperties verbProperties = new VerbPropertiesSimpleImpl();
    List<CaseRole> caseRolesToUse =
        verbProperties.getCaseRolesForGrammarRole(
            getVerb().getVerb(), SVOElement.SVOGrammarPosition.DIRECT_OBJECT);

    // It's possible that the direct object slot has already been filled, e.g. by the verb if we
    // didn't know how
    // to translate the process into natural language. Since only one direct object is allowed, in
    // this case we need to
    // precede any objects formulated here with a prefix, and add the data to the indirect object
    // list.
    String prefix = "";
    SVOElement element = directObject;
    if (!directObject.getSurfaceForm().isEmpty()) {
      prefix = "on ";
      element = new SVOElement(SVOGrammarPosition.INDIRECT_OBJECT);
      indirectObjects.add(element);
    }

    for (CaseRole role : caseRolesToUse) {
      String obj = formulateNounPhraseForCaseRole(role, directObject, kb);
      if (!obj.isEmpty()) {
        sBuild.append(prefix).append(" ").append(obj).append(" ");
        getCaseRolesScratchpad().removeAll(role);
        break;
      }
    }

    element.setSurfaceForm(sBuild.toString().replaceAll("\\s+", " ").trim());
  }
Beispiel #3
0
  /**
   * ************************************************************************************************************
   */
  private String concatenateIndirectObjects() {
    StringBuilder sBuild = new StringBuilder();

    for (SVOElement element : indirectObjects) {
      sBuild.append(element.getSurfaceForm()).append(" ");
    }

    return sBuild.toString().trim();
  }
Beispiel #4
0
  /**
   * ************************************************************************************************************
   * Put the subject of this process into natural language.
   */
  void formulateNaturalSubject() {
    StringBuilder sBuild = new StringBuilder();

    VerbProperties verbProperties = new VerbPropertiesSimpleImpl();
    List<CaseRole> caseRolesToUse =
        verbProperties.getCaseRolesForGrammarRole(
            getVerb().getVerb(), SVOElement.SVOGrammarPosition.SUBJECT);

    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());
  }