Validate Natural Language
When you have an NL model you can validate the NL structure to ensure it is a valid NL. There are two ways to validating:
- Create an instance of an engine using RuntimeEngine
- Build the execution plan of NL using NaturalParser parser
To validate the XML structure (i.e. Declaration, Define...) you can check the XML against our Document Commands.
When you create an instance of a IRuntimeEngine for a Natural Language, the execution plan will be created for NL immediately.
// get the binary of your NL model var nlContent = Encoding.UTF8.GetBytes(rule); // create an instance of engine for the NL var engine = RuntimeEngine.FromXml(nlContent); // Force engine to create the execution plan engine.EnsureLoaded()
Using Natural Language Parser
In this approach, you can validate the NL format and structure.
// get the binary of your NL model var nlContent = Encoding.UTF8.GetBytes(rule); // Use table parser to build the execution plan for your NL var nlPlanModel = TableParser.CreateParser().Parse(nlContent).First();
And then create an execution plan to ensure the whole XML document is valid:
// Create an Execution Plan for NL var engine = RuntimeEngine.FromXml(nlContent);