How to disable a VoiceXML grammar? - voicexml

I'm writing a VoiceXML application where we have a speech grammar and a DTMF grammar. If the caller is calling from a particularly noisy environment, we need to disable the speech grammar. Is there a way to do this which doesn't involve copying the entire form into another form and deleting the speech grammar?

What you're looking for is probably the inputmodes property:
<property name="inputmodes" value="dtmf"/>
This will enable the DTMF grammar while the voice grammar is disabled.

You don't mention which platform(s) you're using, but it's important because this is one of those areas where you have variation between platforms.
Section [3.1.4][1] of the VoiceXMl 2.0 spec says that inputmodes="dtmf" does not de-activate speech grammars, but merely makes it impossible for them to be matched. So, if you turn off the speech recognition grammars, you would hope that the end pointer wouldn't allow speech bargein, but it isn't necessarily forbidden by the spec.
Barring any platform-specific extensions you can use, you might also consider the sensitivity property. Setting that to 0 should make the ASR stop listening for speech.
You could also try setting the bargeintype property to "hotword", if your platform supports it. This won't disable the speech grammars, but it will make it less likely that users won't hear the prompts due to noise-related bargein which is sometimes enough to make the application work.

Using inputmodes can work but you'll still need two forms. There is, however, a work around if you are using voicexml 2.1 and make sure you do not provide the input mod in the grammar tag and make sure it's specified in the grammar itself then you can use a srcexpr to "turn off" your speech grammar.
Say you specify your grammars thus:
<grammar type="application/srgs+xml" src="/grammars/menu.grxml" />
<grammar type="application/srgs+xml" src="/grammars/menu-dtmf.grxml" />
You can disable the speech grammar by repeating the use of the dtmf version:
<grammar type="application/srgs+xml" srcexpr="'/grammars/menu' + (dtmfMode?'-dtmf':'') + '.grxml'" />
<grammar type="application/srgs+xml" src="/grammars/menu-dtmf.grxml" />
So all you need to do is set a boolean variable called dtmfMode that is true when you only want DTMF.

Related

Reader macro vs a normal parser

I am in the process of implementing a program that applies some transformations to SQL code.
When it comes to parsing said code, I thought about two approaches.
Implementing a "standard" parser using ordinary functions
Implementing a Reader macro that does such interpretation at read-time.
I'd like to know if implementing a reader macro is valid for this case or I'm better off writing it with usual functions and avoid killing a insect with a bazooka.
You can use a reader macro as a way to inline SQL code if you want, like
#[SQL code here]
having that call a function like (sql "SQL code here"), but you won't be able to do something as complex as writing a full SQL interpreter with reader macros. Besides, how could you access the database at runtime (when you will probably need it) if you did all that at read time?
Another approach is to create a lispy SQL DSL, where you could use regular functions and macros.

Source Insight can not jump to function definition

My language is lua.
Many functions in the file table.lua is named as "Table_XXX",like pictue1.In table.lua's symbol window,all they are marked as the same symbol----"Table",like picture 1.while function call in other files(enven in the same file),Source Insight can not recognizes the function and jump to its definition.
so,what should I do to solve this problem?
thanks a lot.
Unfortunately you can't expect any help from SI folks so it will have to be a DIY thing.
Open Lua.xclf (it's XML, you can even drag&drop it into SI itself).
Notice:
<Expression
SymbolType="Function"
Pattern="function\w+\([a-zA-Z][a-zA-Z0-9]*\)"
RegexType="Source Insight"
/>
and that regex function\w+\([a-zA-Z][a-zA-Z0-9]*\) doesn't have [ _ ] char. If you are already playing, do yourself a favor and switch type to "Perl Compatible" to have much better control.
You can also edit that in Options / Preferences / Languages double click the language and Custom Parsing.
Also notice that in Keywords [function] is declared as "control" and you'd probably want "Declare Function" or "Declare Method".
You'll have to scrutinize it in great detail (wither in XML or UI) and you'll probably find many other problems. If you reach a good state you'll have to publish it on your own (say on https://pastebin.com/) and then publish the link here.
In theory you could write to their support to ask them do they want a better file but don't expect much. SI ended up being so neglected that you could start crying if you remember it's golden days (whole Windows shipped with SI - several times). That's why people gave up. So, now it's DIY - find some highlighter files from other editors and copy regexs is you can.
Maybe IBM could buy them - right after they pay for Red Hat :-)

Flex input buffer reset after error

I'm using flex & bison to parse a custom language and I'm in the situation described here: http://www.gnu.org/software/bison/manual/html_node/How-Can-I-Reset-the-Parser.html.
To be more precise
I invoke yyparse several times, and on correct input it works
properly; but when a parse error is found, all the other calls fail
too. How can I reset the error flag of yyparse?
My parser and scanner run inside a separate thread, but there is only one thread working with the input file. In my understanding I don't need to write a reentrant scanner since there is only one thread working with the input file. In that page the problem is clearly explained but the solution is not clear to me.
It says:
Therefore, whenever you change yyin, you must tell the Lex-generated
scanner to discard its current buffer and switch to the new one. This
depends upon your implementation of Lex; see its documentation for
more. For Flex, it suffices to call ‘YY_FLUSH_BUFFER’ after each
change to yyin. If your Flex-generated scanner needs to read from
several input streams to handle features like include files, you might
consider using Flex functions like ‘yy_switch_to_buffer’ that
manipulate multiple input buffers
My parser thread calls yyparse in order to build my AST. What is not clear to me is when and where I have to call yy_flush_buffer to fix the problem. In my understanding the scanner code (generated by Flex) is called by the parser code (generated by Bison). The Bison generated code is generated by the grammar. As a result the parser code is not under my direct control. This means I cannot include the call to yy_flush_buffer into the parser code since it would be overwritten every time I generate the parser code by the grammar. It means that I should put the yy_flush_buffer in the grammr file somewhere. But where?
I fixed the problem by doing:
...
FILE *f = fopen(_filename, "r");
yyrestart(f);
yyparse();
...
I leave the question since it could be useful for other people.

Can I get lex to put out a yylex() function with a different name?

I want to have two lexers in one project, and I don't want to run into problems with having multiple yylex functions in the build. Can I make lex output with a different prefix?
You can use the -Pprefix parameter for flex in your makefile. Using flex -Pfoo you would effectively prefix all yy generated functions. Have a look at the manual page for further details.
flex lets you do that. Just define the YY_DECL macro. Dunno about actual Unix(tm) lex(1) though.
You could build a C++ lexer. This means all the state information is held in an object.
Then it is just a matter of using the correct object!

Ant (or NAnt) in Lisp

In his article The Nature of Lisp, Slava Akhmechet introduces people to lisp by using Ant/NAnt as an example. Is there an implementation of Ant/NAnt in lisp? Where you can use actual lisp code, instead of xml, for defining things? I've had to deal with creating additions to NAnt, and have wished for a way to bypass the xml system in the way Slava shows could be done.
Ant is a program that interprets commands written in some XML language. You can, as justinhj mentioned in his answer use some XML parser (like the mentioned XMLisp) and convert the XML description in some kind of Lisp data and then write additional code in Lisp. You need to reimplement also some of the Ant interpretation.
Much of the primitive stuff in Ant is not needed in Lisp. Some file operations are built-in in Lisp (delete-file, rename-file, probe-file, ...). Some are missing and need to be implemented - alternative you can use one of the existing libraries. Also note that you can LOAD Lisp files into Lisp and execute code - there is also the REPL - so it comes already with an interactive frontend (unlike Java).
Higher level build systems in Common Lisp usually are implementing an abstraction called 'SYSTEM'. There are several of those. ASDF is a popular choice, but there are others. A system has subsystems and files. A system has also a few options. Its components also have options. A system has either a structural description of the components, a description of the dependencies, or a kind descriptions of 'actions' and their dependencies. Typically these things are implemented in an object-oriented way and you can implement 'actions' as Lisp (generic) functions. Lisp also brings functions like COMPILE-FILE, which will use the Lisp compiler to compile a file. If your code has, say, C files - you would need to call a C compiler - usually through some implementation specific function that allows to call external programs (here the C compiler).
As, mentioned by dmitry-vk, ASDF is a popular choice. LispWorks provides Common Defsystem. Allegro CL has their own DEFSYSTEM. Its DEFSYSTEM manual describes also how to extend it.
All the Lisp solution are using some kind of Lisp syntax (not XML syntax), usually implemented by a macro to describe the system. Once that is read into Lisp, it turns into a data representation - often with CLOS instances for the system, modules, etc.. The actions then are also Lisp functions. Some higher-order functions then walk over the component graph/tree and execute actions of necessary. Some other tools walk over the component graph/tree and return a representation for actions - which is then a proposed plan - the user then can let Lisp execute the whole plan, or parts of the plan.
On a Lisp Machine a simple system description looks like this:
(sct:defsystem scigraph
(:default-pathname "sys:scigraph;"
:required-systems "DWIM")
(:serial "package" "copy" "dump" "duplicate" "random"
"menu-tools" "basic-classes" "draw" "mouse"
"color" "basic-graph" "graph-mixins" "axis"
"moving-object" "symbol" "graph-data" "legend"
"graph-classes" "present" "annotations" "annotated-graph"
"contour" "equation" "popup-accept" "popup-accept-methods"
"duplicate-methods" "frame" "export" "demo-frame"))
Above defines a system SCIGRAPH and all files should be compiled and load in serial order.
Now I can see what the Lisp Machine would do to update the compiled code:
Command: Compile System (a system [default Scigraph]) Scigraph (keywords)
:Simulate (compiling [default Yes]) Yes
The plan for constructing Scigraph version Newest for the Compile
operation is:
Compile RJNXP:>software>scigraph>scigraph>popup-accept-methods.lisp.newest
Load RJNXP:>software>scigraph>scigraph>popup-accept-methods.ibin.newest
It would compile one file and load it - I have the software loaded and changed only this file so far.
For ASDF see the documentation mentioned on the CLIKI page - it works a bit different.
Stuart Halloway's upcoming book Programming Clojure goes through the construction of Lancet throughout the book as an example app. Lancet is a Clojure build system which (optionally) integrates directly with Ant. Source code and examples are available.
If all you want to do is generate Ant XML files using Lisp code, you could use something like clj-html for Clojure or CL-WHO for Common Lisp. Generating XML from Lisp s-exps is fun and easy.
Common Lisp's ASDF (Another System Definition Facility) is analogous to Make/Ant (but not a full analogue — it is aimed at building lisp programs, not generic systems like make or ant). It is extensible with Lisp code (subclassing systems, components, adding operations to systems). E.g., there is an asdf-ecs extensions that allows including (and compiling) C source files into system.
Perhaps you could define things in lisp and convert them to XML at the point you pass them to NAnt.
Something like XMLisp makes it easier to go back and forth between the two representations.
Edit: Actually, xml-emitter would make more sense.

Resources