You can also use the sample application to begin integrating English Query into other ASP applications. For example, you might choose to have an English Query text box available on your search page or to supplement existing reporting mechanisms.
This code fragment (a simplified version of the ASP sample code) shows the essence of how to convert the questions supplied by users into SQL. You embed code such as this in the ASP that processed the user’s query.
' create the English Query object
Set objEQSession = Server.CreateObject("Mseq.Session")
' load the domain
objEQSession.InitDomain ("c:\pubs\pubs.eqd")
' convert user’s question to English Query response object
Set objEQResponse = objEQSession.ParseRequest(Request ("User Question"))
' determine what kind of response object it is
Select Case objEQResponse.Type
Case nlCommandResponse
Set objCommands = objEQResponse.Commands
For intCommand = 0 To objCommands.Count - 1
Set objCommand = objCommands(intCommand)
Select Case objCommand.CmdID
Case nlQueryCmd
' execute the returned SQL and display to the user
DoSQLCommand objCommand
Case nlAnswerCmd
' just display the answer
Response.Write objCommand.Answer
End Select
Next
Case nlUserClarifyResponse
DoClarification objEQResponse, strQuestion
Case nlErrorResponse
Response.Write objEQResponse.Description & "<BR>"
End Select
Create an English Query object with Server.CreateObject(“Mseq.Session”). To load your domain, call the InitDomain method with the name of the .eqd file. Call ParseRequest() with the user’s question and a Response object is returned. The Response object can be a CommandResponse, which is a collection of commands that are either SQL commands or direct answers. Each SQL command should be executed against your SQL Server database, and you can display the result as a table on the Web page. The process of executing the SQL command using ADO and displaying the result in a table is embedded in the DoSQLCommand function (available in Samples/Asp/Common.inc).
If the command is an answer, it is displayed directly to the user. The response might also be a request for clarification. For example, the question might be “What are all the compact cars in Washington?” and the clarification question might ask whether Washington is a city or a state. The DoClarification call (also available in Common.inc) encapsulates the code necessary to prompt the user to choose from possible values in the UserInputs collection on the Response object.