Example #1
0
  /**
   * Convenience class to realise any NLGElement as a sentence
   *
   * @param element
   * @return String realisation of the NLGElement
   */
  public String realiseSentence(NLGElement element) {
    NLGElement realised = null;
    if (element instanceof DocumentElement) realised = realise(element);
    else {
      DocumentElement sentence = new DocumentElement(DocumentCategory.SENTENCE, null);
      sentence.addComponent(element);
      realised = realise(sentence);
    }

    if (realised == null) return null;
    else return realised.getRealisation();
  }
  @Override
  public List<NLGElement> realise(List<NLGElement> elements) {
    List<NLGElement> realisedElements = new ArrayList<NLGElement>();
    NLGElement currentElement = null;
    NLGElement determiner = null;

    if (elements != null) {
      for (NLGElement eachElement : elements) {
        currentElement = realise(eachElement);
        if (currentElement != null) {
          realisedElements.add(realise(currentElement));
          if (determiner == null
              && DiscourseFunction.SPECIFIER.equals(
                  currentElement.getFeature(InternalFeature.DISCOURSE_FUNCTION))) {
            determiner = currentElement;
            determiner.setFeature(Feature.NUMBER, eachElement.getFeature(Feature.NUMBER));
            // MorphologyRules.doDeterminerMorphology(determiner,
            // currentElement.getRealisation());
          } else if (determiner != null) {

            if (currentElement instanceof ListElement) {
              NLGElement firstChild = ((ListElement) currentElement).getChildren().get(0);

              if (firstChild != null) {
                MorphologyRules.doDeterminerMorphology(determiner, firstChild.getRealisation());
              }
            } else {
              MorphologyRules.doDeterminerMorphology(determiner, currentElement.getRealisation());
            }

            determiner = null;
          }
        }
      }
    }
    return realisedElements;
  }