Interface Generator<T,R>

Type Parameters:
T - the terminal token type of the grammar
R - the result type of the generator
All Known Implementing Classes:
DerivationTreeGenerator, SentenceGenerator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Generator<T,R>
Generator interface for generating sentences/derivation trees from a given grammar.
Since:
7.1
Version:
7.1
  • Method Summary

    Modifier and Type
    Method
    Description
    generate(Cfg<? extends T> cfg)
    Generates a new sentence from the given grammar.
    default <R1> Generator<T,R1>
    map(Function<? super R,? extends R1> f)
    Maps the generated result from type R to type R1.
    static <T> List<Cfg.Symbol<T>>
    select(Cfg.NonTerminal<T> rule, Cfg<T> cfg, SymbolIndex index)
    Standard algorithm for selecting a list of alternative symbols from the given rule.
  • Method Details

    • generate

      R generate(Cfg<? extends T> cfg)
      Generates a new sentence from the given grammar. If the generation of the sentence fails, an empty list is returned.
      Parameters:
      cfg - the generating grammar
      Returns:
      a newly created result
    • map

      default <R1> Generator<T,R1> map(Function<? super R,? extends R1> f)
      Maps the generated result from type R to type R1.
      Type Parameters:
      R1 - the target type
      Parameters:
      f - the mapping function
      Returns:
      a new generator with target type R1
      Throws:
      NullPointerException - if the mapping function is null
    • select

      static <T> List<Cfg.Symbol<T>> select(Cfg.NonTerminal<T> rule, Cfg<T> cfg, SymbolIndex index)
      Standard algorithm for selecting a list of alternative symbols from the given rule.
      Type Parameters:
      T - the terminal type
      Parameters:
      rule - the rule to select the alternative from
      cfg - the grammar to select the alternative from
      index - the symbol selection strategy
      Returns:
      the selected symbols
      Throws:
      NullPointerException - if one of the arguments is null