The NuGram dynamic grammar language

757 views 23 slides Jun 16, 2010
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

Details the extensions to W3C's SRGS ABNF format for dynamic grammars supported by the NuGram Platform.


Slide Content

The NuGram Dynamic Grammar Language Supported by NuGram 2.2 June 16th, 2010

Background Extension to W3C’s SRGS ABNF format Supported by a complete development environment – NuGram IDE Dynamic grammars are deployable on NuGram Server Copyright © 2010 Nu Echo Inc.

Expressions Constants null , false , true Strings Ex: “ abc ” , “John Smith” , “05/30/2010” Numbers Ex: 10 , 325.64 Variables Must be a legal Java identifier Top-level variables are provided by the instantiation context Copyright © 2010 Nu Echo Inc.

Expressions Properties Syntax : obj . propertyName Property name must be a valid Java identifier Method calls Syntax : obj . methodName ( arguments… ) Arguments are comma-separate Array elements Syntax : obj [ indexValue ] Copyright © 2010 Nu Echo Inc.

Expressions Comparison operators == != Logical operators ! (negation) && (conjunction) || (disjunction) Copyright © 2010 Nu Echo Inc.

Dynamic Words Syntax @word ( Expressions… ) Values of all expressions are concatenated Example Copyright © 2010 Nu Echo Inc. Template @word ( name.firstname ) JSON Context {"name" : {" firstname " : " dominique "} } Resulting expansion dominique

Dynamic Rule References Syntax @ref ( Expressions… ) Values of all expressions are concatenated Resulting value must start with “#” for a local rule reference Example Copyright © 2010 Nu Echo Inc. Template @ref (“ name.grxml?id =“ name.id) JSON Context {"name" : {"id" : "1234"} } Resulting expansion $< name.grxml?id =1234>

Dynamic Tags Syntax @tag ( Expressions… ) Values of all expressions are concatenated Example Copyright © 2010 Nu Echo Inc. Template @tag (“id = '“ name.id “';”) JSON Context {"name" : {"id" : "1234"} } Resulting expansion {id = '1234';}

Iterations Syntax @for ( var : Expression ) Expansions… @end Repeats the expansions for each value in the collection resulting from evaluating Expression. Copyright © 2010 Nu Echo Inc.

Iterations Example Copyright © 2010 Nu Echo Inc. Template @for (name : names) @word (name) @end JSON Context {"names" : [" yves ", " dominique ", " gilles "] } Resulting expansion yves dominique gilles

Dynamic Sequences Syntax @ seq Expansions… @end All direct expansions become part of the sequence Copyright © 2010 Nu Echo Inc.

Dynamic sequences Example Copyright © 2010 Nu Echo Inc. Template @ seq @for (digit : digits.split (“,”)) @word digit @end @tag (“ out.digits = '” digits.replaceAll (“,”, “”) “'”) @end JSON Context {"digits" : "1,2,3"} Resulting expansion ( 1 2 3 { out.digits = '123'} )

Dynamic Choices Syntax @alt Expansions… @end All direct expansions become alternative choices Copyright © 2010 Nu Echo Inc.

Dynamic Choices Example 1 Copyright © 2010 Nu Echo Inc. Template @alt @for (name : names) @word (name) @end @end JSON Context {"names" : [" yves ", " dominique ", " gilles "] } Resulting expansion yves | dominique | gilles

Example 2 Beware : @alt and @for may produce unexpected results Template @alt @for (entry : entries) @word (entry.name) @tag ("out.id = '" entry.id "'") @end @end JSON Context {"entries" : [{"name": " yves ", "id":"225"}, {"name": " dominique ", "id":"231"}] } Resulting expansion yves | {out.id = '225'} | dominique | {out.id = '231'} Dynamic Choices Copyright © 2010 Nu Echo Inc.

Template @alt @for (entry : entries) ( @word (entry.name) @tag ("out.id = '" entry.id "'") ) @end @end JSON Context {"entries" : [{"name": " yves ", "id":"225"}, {"name": " dominique ", "id":"231"}] } Resulting expansion ( yves {out.id = '225'} ) | ( dominique {out.id = '231'} ) Example 2 (cont'd) Solution: use grouping Dynamic Choices Copyright © 2010 Nu Echo Inc.

Local Variable Definitions Syntax @ var Ident = Expression : Expansions… @end Ident is visible for the Expansions Multiple variables can be declared at once Example @ var firstname = name.firstname , lastname = name.lastname : ( [@ word lastname ] [ @word firstname ] @word lastname ) @end Copyright © 2010 Nu Echo Inc.

Conditionals Syntax @if ( Expression ) Expansions… @ elseif ( Expression ) Expansions… @else Expansions… @end A single branch of the conditional is executed @ elseif and @else branches are optional There can be more than one @ elseif , but a single @else Copyright © 2010 Nu Echo Inc.

Macros Definitions Syntax @define Ident ( Parameters ): Expansions… @end Parameters are comma-separated identifiers Can only appear as a top-level form Example @define fullname (name) : [ @word name.firstname] @word name.lastname @end Copyright © 2010 Nu Echo Inc.

Macros Invocations Syntax @call Ident ( Expressions… ) Arguments are comma-separated Example @for (name : names) @call fullname (name) @end Copyright © 2010 Nu Echo Inc.

Dynamic Rules Syntax @rule Expression = Expansions… @end All direct expansions become alternative choices Especially useful inside a top-level @for Example @for (typeSet : addresses.getStreetTypes()) @rule typeSet.getUniqueId() = @call streetTypes(typeSet) @end @end Copyright © 2010 Nu Echo Inc.

Dynamic Headers Syntax mode @string Expression ; root @string Expression ; language @string Expression ; lexicon @string Expression ; meta “ string ” is @string Expression ; tag-format @string Expression ; Expression must evaluate to a string Useful for engine-specific headers Copyright © 2010 Nu Echo Inc.

Conditional Headers Syntax Add a @when clause at the end of the header form Example lexicon <mylexicon.xml> @when engine == “ osr ”; tag-format < swi -semantics/1.0> @when engine == “ osr ”; meta “ com.nuecho.generation.omit -tags” is “true” @when engine != “ osr ”; Copyright © 2010 Nu Echo Inc.