Examples of NLGElement


Examples of simplenlg.framework.NLGElement

  /** Set the indirect object of a clause (assumes this is the only direct indirect object)
   *
   * @param indirectObject
   */
  public void setIndirectObject(Object indirectObject) {
    NLGElement indirectObjectPhrase;
    if (indirectObject instanceof PhraseElement || indirectObject instanceof CoordinatedPhraseElement)
      indirectObjectPhrase = (NLGElement) indirectObject;
    else
      indirectObjectPhrase = getFactory().createNounPhrase(indirectObject);

    indirectObjectPhrase.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.INDIRECT_OBJECT);
    setComplement(indirectObjectPhrase);
  }
View Full Code Here

Examples of simplenlg.framework.NLGElement

   
    if (modifier == null)
      return;
   
    // get modifier as NLGElement if possible
    NLGElement modifierElement = null;
    if (modifier instanceof NLGElement)
      modifierElement = (NLGElement) modifier;
    else if (modifier instanceof String) {
      String modifierString = (String)modifier;
      if (modifierString.length() > 0 && !modifierString.contains(" "))
View Full Code Here

Examples of simplenlg.framework.NLGElement

  public void setAdjective(Object adjective) {
    if (adjective instanceof NLGElement)
      setHead(adjective);
    else {
      // create noun as word
      NLGElement adjectiveElement = getFactory().createWord(adjective, LexicalCategory.ADJECTIVE);

      // set head of NP to nounElement
      setHead(adjectiveElement);
    }
  }
View Full Code Here

Examples of simplenlg.framework.NLGElement

  public NLGElement realise(NLGElement element) {
    if (this.debug) {
      System.out.println("INITIAL TREE\n"); //$NON-NLS-1$
      System.out.println(element.printTree(null));
    }
    NLGElement postSyntax = this.syntax.realise(element);
    if (this.debug) {
      System.out.println("\nPOST-SYNTAX TREE\n"); //$NON-NLS-1$
      System.out.println(postSyntax.printTree(null));
    }
    NLGElement postMorphology = this.morphology.realise(postSyntax);
    if (this.debug) {
      System.out.println("\nPOST-MORPHOLOGY TREE\n"); //$NON-NLS-1$
      System.out.println(postMorphology.printTree(null));
    }     
       
   
    NLGElement postOrthography = this.orthography.realise(postMorphology);
    if (this.debug) {
      System.out.println("\nPOST-ORTHOGRAPHY TREE\n"); //$NON-NLS-1$
      System.out.println(postOrthography.printTree(null));
    }
   
    NLGElement postFormatter = null;
    if (this.formatter != null) {
      postFormatter = this.formatter.realise(postOrthography);
      if (this.debug) {
        System.out.println("\nPOST-FORMATTER TREE\n"); //$NON-NLS-1$
        System.out.println(postFormatter.printTree(null));
      }
    } else {
      postFormatter = postOrthography;
    }
   
View Full Code Here

Examples of simplenlg.framework.NLGElement

  /** 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();
  }
View Full Code Here

Examples of simplenlg.framework.NLGElement

    // Do nothing
  }

  @Override
  public NLGElement realise(NLGElement element) {
    NLGElement realisedComponent = null;
    StringBuffer realisation = new StringBuffer();
   
    if (element != null) {
      ElementCategory category = element.getCategory();
      List<NLGElement> components = element.getChildren();

      //NB: The order of the if-statements below is important!
     
      // check if this is a canned text first
      if (element instanceof StringElement) {
        realisation.append(element.getRealisation());

      } else if (category instanceof DocumentCategory) {
        // && element instanceof DocumentElement
        String title = element instanceof DocumentElement ? ((DocumentElement) element)
            .getTitle()
            : null;
        // String title = ((DocumentElement) element).getTitle();

        switch ((DocumentCategory) category) {

        case DOCUMENT:
        case SECTION:
        case LIST:
          if (title != null) {
            realisation.append(title).append('\n');
          }
          for (NLGElement eachComponent : components) {
            realisedComponent = realise(eachComponent);
            if (realisedComponent != null) {
              realisation.append(realisedComponent
                  .getRealisation());
            }
          }
          break;

        case PARAGRAPH:
          if (null != components && 0 < components.size()) {
            realisedComponent = realise(components.get(0));
            if (realisedComponent != null) {
              realisation.append(realisedComponent
                  .getRealisation());
            }
            for (int i = 1; i < components.size(); i++) {
              if (realisedComponent != null) {
                realisation.append(' ');
              }
              realisedComponent = realise(components.get(i));
              if (realisedComponent != null) {
                realisation.append(realisedComponent
                    .getRealisation());
              }
            }
          }
          realisation.append("\n\n");
          break;

        case SENTENCE:
          realisation.append(element.getRealisation());
          break;

        case LIST_ITEM:
          // cch fix
          //realisation.append(" * ").append(element.getRealisation()); //$NON-NLS-1$
          realisation.append(" * "); //$NON-NLS-1$

          for (NLGElement eachComponent : components) {
            realisedComponent = realise(eachComponent);
           
            if (realisedComponent != null) {
              realisation.append(realisedComponent
                  .getRealisation())
             
              if(components.indexOf(eachComponent) < components.size()-1) {
                realisation.append(' ');
              }
            }
          }
          //finally, append newline
          realisation.append("\n");
          break;
        }

        // also need to check if element is a listelement (items can
        // have embedded lists post-orthography) or a coordinate
      } else if (element instanceof ListElement || element instanceof CoordinatedPhraseElement) {
        for (NLGElement eachComponent : components) {
          realisedComponent = realise(eachComponent);
          if (realisedComponent != null) {
            realisation.append(realisedComponent.getRealisation()).append(' ');
          }
        }       
      }
    }
   
View Full Code Here

Examples of simplenlg.framework.NLGElement

   *            the <code>List</code> of coordinates in the
   *            <code>CoordinatedPhraseElement</code>
   */
  private static void raiseSpecifier(List<NLGElement> children) {
    boolean allMatch = true;
    NLGElement child = children.get(0);
    NLGElement specifier = null;
    String test = null;

    if (child != null) {
      specifier = child.getFeatureAsElement(InternalFeature.SPECIFIER);

      if (specifier != null) {
        // AG: this assumes the specifier is an InflectedWordElement or
        // phrase.
        // it could be a Wordelement, in which case, we want the
        // baseform
        test = (specifier instanceof WordElement) ? ((WordElement) specifier)
            .getBaseForm()
            : specifier
                .getFeatureAsString(LexicalFeature.BASE_FORM);
      }

      if (test != null) {
        int index = 1;

        while (index < children.size() && allMatch) {
          child = children.get(index);

          if (child == null) {
            allMatch = false;

          } else {
            specifier = child
                .getFeatureAsElement(InternalFeature.SPECIFIER);
            String childForm = (specifier instanceof WordElement) ? ((WordElement) specifier)
                .getBaseForm()
                : specifier
                    .getFeatureAsString(LexicalFeature.BASE_FORM);

            if (!test.equals(childForm)) {
              allMatch = false;
            }
View Full Code Here

Examples of simplenlg.framework.NLGElement

   *            the stack of auxiliary verbs.
   */
  private static void realiseAuxiliaries(SyntaxProcessor parent,
      ListElement realisedElement, Stack<NLGElement> auxiliaryRealisation) {

    NLGElement aux = null;
    NLGElement currentElement = null;
    while (!auxiliaryRealisation.isEmpty()) {
      aux = auxiliaryRealisation.pop();
      currentElement = parent.realise(aux);
      if (currentElement != null) {
        realisedElement.addComponent(currentElement);
        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION,
            DiscourseFunction.AUXILIARY);
      }
    }
  }
View Full Code Here

Examples of simplenlg.framework.NLGElement

   */
  private static void realiseMainVerb(SyntaxProcessor parent,
      PhraseElement phrase, Stack<NLGElement> mainVerbRealisation,
      ListElement realisedElement) {

    NLGElement currentElement = null;
    NLGElement main = null;

    while (!mainVerbRealisation.isEmpty()) {
      main = mainVerbRealisation.pop();
      main.setFeature(Feature.INTERROGATIVE_TYPE, phrase
          .getFeature(Feature.INTERROGATIVE_TYPE));
      currentElement = parent.realise(main);

      if (currentElement != null) {
        realisedElement.addComponent(currentElement);
View Full Code Here

Examples of simplenlg.framework.NLGElement

    ListElement indirects = new ListElement();
    ListElement directs = new ListElement();
    ListElement unknowns = new ListElement();
    Object discourseValue = null;
    NLGElement currentElement = null;

    for (NLGElement complement : phrase
        .getFeatureAsElementList(InternalFeature.COMPLEMENTS)) {

      discourseValue = complement
          .getFeature(InternalFeature.DISCOURSE_FUNCTION);
      currentElement = parent.realise(complement);
      if (currentElement != null) {
        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION,
            DiscourseFunction.COMPLEMENT);

        if (DiscourseFunction.INDIRECT_OBJECT.equals(discourseValue)) {
          indirects.addComponent(currentElement);
        } else if (DiscourseFunction.OBJECT.equals(discourseValue)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.