Upload
nu-echo-inc
View
1.250
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Details the extensions to W3C's SRGS ABNF format for dynamic grammars supported by the NuGram Platform.
Citation preview
The NuGram Dynamic Grammar Language
Supported by NuGram 2.2June 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 yvesdominiquegilles
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 2Beware: @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
Syntaxmode @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.