next up previous contents
Next: Mini-interpreter (parsing only) Up: Running and Debugging ALE Previous: Executing Grammars: Parsing   Contents


Executing Grammars: Generation

[Code]
The generator can be used with the predicate gen/1,3predicate. It can take a single description argument:
  | ?- gen((sentence,
            sem:(pred:decl,
                 args:[(pred:call_up,
                        args:[pred:mary,pred:john])]))).

  CATEGORY: 

  sentence
  SEM sem
      ARGS arg_ne_list
           HD sem
              ARGS arg_ne_list
                   HD sem
                      ARGS arg_list
                      PRED mary
                   TL arg_ne_list
                      HD sem
                         ARGS arg_list
                         PRED john
                      TL e_list
              PRED call_up
           TL e_list
      PRED decl


  STRING: 
  mary calls john up 

  ANOTHER?  y.

  STRING: 
  mary calls up john 

  ANOTHER?  y.

  no
Notice the extra set of parentheses necessary to make the whole description a single argument for gen/1.

gen can also take three arguments:

  gen(Ref,SVs,Iqs)
where Ref, SVs and Iqs are the three parts of ALE's internal representation of a feature structure as defined in the last section. This alternative is most useful when the feature structure has been generated before by another process, like parsing, or retrieved from a database.
  | ?- rec([john,calls,mary,up],Ref,SVs,Iqs),gen(Ref,SVs,Iqs).

  CATEGORY: 

  sentence
  SEM sem
      ARGS arg_ne_list
           HD sem
              ARGS arg_ne_list
                   HD sem
                      ARGS e_list
                      PRED john
                   TL arg_ne_list
                      HD sem
                         ARGS e_list
                         PRED mary
                      TL e_list
              PRED call_up
           TL e_list
      PRED decl


  STRING: 
  john calls mary up 

  ANOTHER?  n.

  Iqs = [],
  SVs = sentence(_O-sem(_N-arg_ne_list(_M-sem(_L-arg_ne_list(_K-
  sem(_J-e_list,_I-john),_H-arg_ne_list(_G-sem(_F-e_list,_E-mary),
  _D-e_list)),_C-call_up),_B-e_list),_A-decl)) ? 

  yes
In both cases, ALE will print the input feature structure and then will generate and display all possible string solutions through backtracking.

It is also possible to bind the string to a variable, using gen/4 : [Code]

  gen(Ref,SVs,Iqs,Ws).
Ws will non-deterministically be bound to the word lists that constitute valid solutions to the generation problem. This can be used as input to rec/1, for example.
  | ?- rec([john,calls,mary,up],Ref,SVs,Iqs),gen(Ref,SVs,Iqs,Ws).

  Iqs = [],
  SVs = sentence(_O-sem(_N-arg_ne_list(_M-sem(_L-arg_ne_list(_K-
  sem(_J-e_list,_I-john),_H-arg_ne_list(_G-sem(_F-e_list,_E-mary),
  _D-e_list)),_C-call_up),_B-e_list),_A-decl)),
  Ws = [john,calls,mary,up] ? ;

  Iqs = [],
  SVs = sentence(_O-sem(_N-arg_ne_list(_M-sem(_L-arg_ne_list(_K-
  sem(_J-e_list,_I-john),_H-arg_ne_list(_G-sem(_F-e_list,_E-mary),
  _D-e_list)),_C-call_up),_B-e_list),_A-decl)),
  Ws = [john,calls,up,mary] ? ;

  Iqs = [],
  SVs = s(_L-finite,_K-sem(_J-arg_ne_list(_I-sem(_H-e_list,_G-john),
  _F-arg_ne_list(_E-sem(_D-e_list,_C-mary),_B-e_list)),_A-call_up)),
  Ws = [john,calls,mary,up] ? ;

  Iqs = [],
  SVs = s(_L-finite,_K-sem(_J-arg_ne_list(_I-sem(_H-e_list,_G-john),
  _F-arg_ne_list(_E-sem(_D-e_list,_C-mary),_B-e_list)),_A-call_up)),
  Ws = [john,calls,up,mary] ? ;

no
The last two solutions in the example above are generated because the input string, john calls mary up, can be parsed both as a sentence type and as an s type.


next up previous contents
Next: Mini-interpreter (parsing only) Up: Running and Debugging ALE Previous: Executing Grammars: Parsing   Contents
TRALE User's Manual