You are absolutely right: it is complex... but doable.
I have been spending the last month trying to do it; reasonable functionality now but still optimizing for performance (it is done in Prolog). Can set-up my site to include it so that it can be asked for download, if anybody is interested, of course.
If MS were to include that kind of facility in the SDK, our lives would be much simpler (they have tons of high-caliber researchers).
Coincidentally, grammar inference is more important for M than for Mg (there is still such a distinction in my mind).