Contenu connexe
Similaire à The NuGram dynamic grammar language (20)
The NuGram dynamic grammar language
- 2. 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.
- 3. Expressions Constants null, false, true StringsEx: “abc”, “John Smith”, “05/30/2010” NumbersEx: 10, 325.64 Variables Must be a legal Java identifier Top-level variables are provided by the instantiation context Copyright © 2010 Nu Echo Inc.
- 4. 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.
- 6. Dynamic Words Syntax@word ( Expressions… ) Values of all expressions are concatenated Example Copyright © 2010 Nu Echo Inc.
- 7. 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.
- 8. Dynamic Tags Syntax@tag ( Expressions… ) Values of all expressions are concatenated Example Copyright © 2010 Nu Echo Inc.
- 9. 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.
- 15. Example 2 Beware: @alt and @for may produce unexpected results Dynamic Choices Copyright © 2010 Nu Echo Inc.
- 16. Example 2 (cont'd) Solution: use grouping Dynamic Choices Copyright © 2010 Nu Echo Inc.
- 17. Local Variable Definitions Syntax@varIdent = Expression :Expansions… @end Ident is visible for the Expansions Multiple variables can be declared at once Example@varfirstname = name.firstname,lastname = name.lastname : ( [@wordlastname] [@wordfirstname] @wordlastname )@end Copyright © 2010 Nu Echo Inc.
- 18. Conditionals Syntax@if ( Expression )Expansions… @elseif ( Expression )Expansions… @elseExpansions… @end A single branch of the conditional is executed @elseifand @else branches are optional There can be more than one @elseif, but a single @else Copyright © 2010 Nu Echo Inc.
- 19. Macros Definitions Syntax@defineIdent (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.
- 21. Dynamic Rules Syntax@ruleExpression = 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.
- 22. Dynamic Headers Syntaxmode @stringExpression;root @stringExpression;language @stringExpression;lexicon @stringExpression;meta “string” is @stringExpression;tag-format @stringExpression; Expression must evaluate to a string Useful for engine-specific headers Copyright © 2010 Nu Echo Inc.
- 23. Conditional Headers Syntax Add a @when clause at the end of the header form Examplelexicon <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.