コード例 #1
0
  /**
   * The main method for realising noun phrases.
   *
   * @param parent the <code>SyntaxProcessor</code> that called this method.
   * @param phrase the <code>PhraseElement</code> to be realised.
   * @return the realised <code>NLGElement</code>.
   */
  static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase) {
    ListElement realisedElement = null;

    if (phrase != null && !phrase.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) {
      realisedElement = new ListElement();

      if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL).booleanValue()) {
        realisedElement.addComponent(createPronoun(parent, phrase));

      } else {
        realiseSpecifier(phrase, parent, realisedElement);
        realisePreModifiers(phrase, parent, realisedElement);
        realiseHeadNoun(phrase, parent, realisedElement);
        PhraseHelper.realiseList(
            parent,
            realisedElement,
            phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS),
            DiscourseFunction.COMPLEMENT);

        PhraseHelper.realiseList(
            parent, realisedElement, phrase.getPostModifiers(), DiscourseFunction.POST_MODIFIER);
      }
    }

    return realisedElement;
  }
コード例 #2
0
  /**
   * Realises the head noun of the noun phrase.
   *
   * @param phrase the <code>PhraseElement</code> representing this noun phrase.
   * @param parent the parent <code>SyntaxProcessor</code> that will do the realisation of the
   *     complementiser.
   * @param realisedElement the current realisation of the noun phrase.
   */
  private static void realiseHeadNoun(
      PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) {
    NLGElement headElement = phrase.getHead();

    if (headElement != null) {
      headElement.setFeature(Feature.ELIDED, phrase.getFeature(Feature.ELIDED));
      headElement.setFeature(LexicalFeature.GENDER, phrase.getFeature(LexicalFeature.GENDER));
      headElement.setFeature(InternalFeature.ACRONYM, phrase.getFeature(InternalFeature.ACRONYM));
      headElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));
      headElement.setFeature(Feature.PERSON, phrase.getFeature(Feature.PERSON));
      headElement.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE));
      headElement.setFeature(Feature.PASSIVE, phrase.getFeature(Feature.PASSIVE));
      NLGElement currentElement = parent.realise(headElement);
      currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT);
      realisedElement.addComponent(currentElement);
    }
  }
コード例 #3
0
  /**
   * Realises the specifier of the noun phrase.
   *
   * @param phrase the <code>PhraseElement</code> representing this noun phrase.
   * @param parent the parent <code>SyntaxProcessor</code> that will do the realisation of the
   *     complementiser.
   * @param realisedElement the current realisation of the noun phrase.
   */
  private static void realiseSpecifier(
      PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) {
    NLGElement specifierElement = phrase.getFeatureAsElement(InternalFeature.SPECIFIER);

    if (specifierElement != null
        && !phrase.getFeatureAsBoolean(InternalFeature.RAISED).booleanValue()
        && !phrase.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) {

      if (!specifierElement.isA(LexicalCategory.PRONOUN)) {
        specifierElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER));
      }

      NLGElement currentElement = parent.realise(specifierElement);

      if (currentElement != null) {
        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SPECIFIER);
        realisedElement.addComponent(currentElement);
      }
    }
  }
コード例 #4
0
  @Override
  public NLGElement realise(NLGElement element) {
    NLGElement realisedElement = null;
    if (element instanceof InflectedWordElement) {
      realisedElement = doMorphology((InflectedWordElement) element);
    } else if (element instanceof StringElement) {
      realisedElement = element;
    } else if (element instanceof WordElement) {
      // AG: now retrieves the default spelling variant, not the baseform
      // String baseForm = ((WordElement) element).getBaseForm();
      String defaultSpell = ((WordElement) element).getDefaultSpellingVariant();

      if (defaultSpell != null) {
        realisedElement = new StringElement(defaultSpell);
      }
    } else if (element instanceof DocumentElement) {
      List<NLGElement> children = element.getChildren();
      ((DocumentElement) element).setComponents(realise(children));
      realisedElement = element;
    } else if (element instanceof ListElement) {
      realisedElement = new ListElement();
      ((ListElement) realisedElement).addComponents(realise(element.getChildren()));
    } else if (element instanceof CoordinatedPhraseElement) {
      List<NLGElement> children = element.getChildren();
      ((CoordinatedPhraseElement) element).clearCoordinates();

      if (children != null && children.size() > 0) {
        ((CoordinatedPhraseElement) element).addCoordinate(realise(children.get(0)));
        for (int index = 1; index < children.size(); index++) {
          ((CoordinatedPhraseElement) element).addCoordinate(realise(children.get(index)));
        }
        realisedElement = element;
      }
    } else if (element != null) {
      realisedElement = element;
    }
    return realisedElement;
  }
コード例 #5
0
  @Override
  public NLGElement realise(NLGElement element) {
    NLGElement realisedElement = null;

    if (element != null && !element.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) {

      if (element instanceof DocumentElement) {
        List<NLGElement> children = element.getChildren();
        ((DocumentElement) element).setComponents(realise(children));
        realisedElement = element;

      } else if (element instanceof PhraseElement) {
        realisedElement = realisePhraseElement((PhraseElement) element);

      } else if (element instanceof ListElement) {
        realisedElement = new ListElement();
        ((ListElement) realisedElement).addComponents(realise(element.getChildren()));

      } else if (element instanceof InflectedWordElement) {
        String baseForm = ((InflectedWordElement) element).getBaseForm();
        ElementCategory category = element.getCategory();

        if (this.lexicon != null && baseForm != null) {
          WordElement word = ((InflectedWordElement) element).getBaseWord();

          if (word == null) {
            if (category instanceof LexicalCategory) {
              word = this.lexicon.lookupWord(baseForm, (LexicalCategory) category);
            } else {
              word = this.lexicon.lookupWord(baseForm);
            }
          }

          if (word != null) {
            ((InflectedWordElement) element).setBaseWord(word);
          }
        }

        realisedElement = element;

      } else if (element instanceof WordElement) {
        // AG: need to check if it's a word element, in which case it
        // needs to be marked for inflection
        InflectedWordElement infl = new InflectedWordElement((WordElement) element);

        // the inflected word inherits all features from the base word
        for (String feature : element.getAllFeatureNames()) {
          infl.setFeature(feature, element.getFeature(feature));
        }

        realisedElement = realise(infl);

      } else if (element instanceof CoordinatedPhraseElement) {
        realisedElement = CoordinatedPhraseHelper.realise(this, (CoordinatedPhraseElement) element);

      } else {
        realisedElement = element;
      }
    }

    // Remove the spurious ListElements that have only one element.
    if (realisedElement instanceof ListElement) {
      if (((ListElement) realisedElement).size() == 1) {
        realisedElement = ((ListElement) realisedElement).getFirst();
      }
    }
    return realisedElement;
  }