Package simplenlg.framework

Examples of simplenlg.framework.NLGElement


      lexCat = (LexicalCategory) cat;
    }

    // String baseForm = getBaseWord(wordElement);
    String baseForm = wordElement.getBase();
    NLGElement word = null;

    if (baseForm != null) {
      word = factory.createWord(baseForm, lexCat);

      if (word instanceof InflectedWordElement
View Full Code Here


   
    if (phrases.size() >= 2) {
      List<NLGElement> removed = new ArrayList<NLGElement>();

      for (int i = 0; i < phrases.size(); i++) {
        NLGElement current = phrases.get(i);

        if (removed.contains(current)) {
          continue;
        }

        for (int j = i + 1; j < phrases.size(); j++) {
          NLGElement next = phrases.get(j);
          NLGElement aggregated = apply(current, next);

          if (aggregated != null) {
            current = aggregated;
            removed.add(next);
          }
View Full Code Here

   *
   * @param phrase
   * @return aggregated result
   */
  public NLGElement apply(NLGElement phrase) {
    NLGElement result = null;

    if (phrase instanceof CoordinatedPhraseElement) {     
      List<NLGElement> children = ((CoordinatedPhraseElement) phrase).getChildren();
      List<NLGElement> aggregated = apply(children);

      if(aggregated.size() == 1) {
        result = aggregated.get(0);
     
      } else {
        result = this.factory.createCoordinatedPhrase();

        for (NLGElement agg : aggregated) {
          ((CoordinatedPhraseElement) result).addCoordinate(agg);
        }       
      }     
    }

   
    if(result != null) {
      for(String feature: phrase.getAllFeatureNames()) {
        result.setFeature(feature, phrase.getFeature(feature));
      }
    }
   
    return result;
  }
View Full Code Here

   * @return the <code>NLGElement</code> representing the realised clause.
   */
  static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase) {
    ListElement realisedElement = null;
    NLGFactory phraseFactory = phrase.getFactory();
    NLGElement splitVerb = null;
    boolean interrogObj = false;

    if (phrase != null) {
      realisedElement = new ListElement();
      NLGElement verbElement = phrase
          .getFeatureAsElement(InternalFeature.VERB_PHRASE);

      if (verbElement == null) {
        verbElement = phrase.getHead();
      }

      checkSubjectNumberPerson(phrase, verbElement);
      checkDiscourseFunction(phrase);
      copyFrontModifiers(phrase, verbElement);
      addComplementiser(phrase, parent, realisedElement);
      addCuePhrase(phrase, parent, realisedElement);

      if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE)) {
        Object inter = phrase.getFeature(Feature.INTERROGATIVE_TYPE);
        interrogObj = InterrogativeType.WHAT_OBJECT.equals(inter)
            || InterrogativeType.WHO_OBJECT.equals(inter);
        splitVerb = realiseInterrogative(phrase, parent,
            realisedElement, phraseFactory, verbElement);
      } else {
        PhraseHelper
            .realiseList(
                parent,
                realisedElement,
                phrase
                    .getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS),
                DiscourseFunction.FRONT_MODIFIER);
      }

      addSubjectsToFront(phrase, parent, realisedElement, splitVerb);

      NLGElement passiveSplitVerb = addPassiveComplementsNumberPerson(
          phrase, parent, realisedElement, verbElement);

      if (passiveSplitVerb != null) {
        splitVerb = passiveSplitVerb;
      }
View Full Code Here

      SyntaxProcessor parent, ListElement realisedElement,
      NLGFactory phraseFactory) {

    if (InterrogativeType.WHO_INDIRECT_OBJECT.equals(phrase
        .getFeature(Feature.INTERROGATIVE_TYPE))) {
      NLGElement word = phraseFactory.createWord(
          "to", LexicalCategory.PREPOSITION); //$NON-NLS-1$
      realisedElement.addComponent(parent.realise(word));
    }
  }
View Full Code Here

   * @param realisedElement
   *            the current realisation of the clause.
   */
  private static void addInterrogativeFrontModifiers(PhraseElement phrase,
      SyntaxProcessor parent, ListElement realisedElement) {
    NLGElement currentElement = null;
    if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE)) {
      for (NLGElement subject : phrase
          .getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS)) {
        currentElement = parent.realise(subject);
        if (currentElement != null) {
          currentElement.setFeature(
              InternalFeature.DISCOURSE_FUNCTION,
              DiscourseFunction.FRONT_MODIFIER);

          realisedElement.addComponent(currentElement);
        }
View Full Code Here

   *            the phrase factory to be used.
   */
  private static void addPassiveSubjects(PhraseElement phrase,
      SyntaxProcessor parent, ListElement realisedElement,
      NLGFactory phraseFactory) {
    NLGElement currentElement = null;

    if (phrase.getFeatureAsBoolean(Feature.PASSIVE).booleanValue()) {
      List<NLGElement> allSubjects = phrase
          .getFeatureAsElementList(InternalFeature.SUBJECTS);

      if (allSubjects.size() > 0
          || phrase.hasFeature(Feature.INTERROGATIVE_TYPE)) {
        realisedElement.addComponent(parent.realise(phraseFactory
            .createPrepositionPhrase("by"))); //$NON-NLS-1$
      }

      for (NLGElement subject : allSubjects) {

        subject.setFeature(Feature.PASSIVE, true);
        if (subject.isA(PhraseCategory.NOUN_PHRASE)
            || subject instanceof CoordinatedPhraseElement) {
          currentElement = parent.realise(subject);
          if (currentElement != null) {
            currentElement.setFeature(
                InternalFeature.DISCOURSE_FUNCTION,
                DiscourseFunction.SUBJECT);
            realisedElement.addComponent(currentElement);
          }
        }
View Full Code Here

      SyntaxProcessor parent, ListElement realisedElement,
      NLGElement splitVerb, NLGElement verbElement, boolean whObj) {

    setVerbFeatures(phrase, verbElement);

    NLGElement currentElement = parent.realise(verbElement);
    if (currentElement != null) {
      if (splitVerb == null) {
        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION,
            DiscourseFunction.VERB_PHRASE);

        realisedElement.addComponent(currentElement);

      } else {
        if (currentElement instanceof ListElement) {
          List<NLGElement> children = currentElement.getChildren();
          currentElement = children.get(0);
          currentElement.setFeature(
              InternalFeature.DISCOURSE_FUNCTION,
              DiscourseFunction.VERB_PHRASE);
          realisedElement.addComponent(currentElement);
          realisedElement.addComponent(splitVerb);

          for (int eachChild = 1; eachChild < children.size(); eachChild++) {
            currentElement = children.get(eachChild);
            currentElement.setFeature(
                InternalFeature.DISCOURSE_FUNCTION,
                DiscourseFunction.VERB_PHRASE);
            realisedElement.addComponent(currentElement);
          }
        } else {
          currentElement.setFeature(
              InternalFeature.DISCOURSE_FUNCTION,
              DiscourseFunction.VERB_PHRASE);

          if (whObj) {
            realisedElement.addComponent(currentElement);
View Full Code Here

  private static NLGElement addPassiveComplementsNumberPerson(
      PhraseElement phrase, SyntaxProcessor parent,
      ListElement realisedElement, NLGElement verbElement) {
    Object passiveNumber = null;
    Object passivePerson = null;
    NLGElement currentElement = null;
    NLGElement splitVerb = null;
    NLGElement verbPhrase = phrase
        .getFeatureAsElement(InternalFeature.VERB_PHRASE);

    if (phrase.getFeatureAsBoolean(Feature.PASSIVE).booleanValue()
        && verbPhrase != null
        && !InterrogativeType.WHAT_OBJECT.equals(phrase
            .getFeature(Feature.INTERROGATIVE_TYPE))) {

      // complements of a clause are stored in the VPPhraseSpec
      for (NLGElement subject : verbPhrase
          .getFeatureAsElementList(InternalFeature.COMPLEMENTS)) {

        // AG: complement needn't be an NP
        // subject.isA(PhraseCategory.NOUN_PHRASE) &&
        if (DiscourseFunction.OBJECT.equals(subject
View Full Code Here

   * Elide the rightmost constituents in the phrase list, that is, all phrases
   * except the first.
   */
  public void elideRightmost() {
    for (int i = 1; i < this.phrases.size(); i++) {
      NLGElement phrase = this.phrases.get(i);

      if (phrase != null) {
        phrase.setFeature(Feature.ELIDED, true);
      }
    }
  }
View Full Code Here

TOP

Related Classes of simplenlg.framework.NLGElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.