This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
|
Add Natural Language Search Capabilities to Your Site with English Query
Adam Blum |
Now that you're building ASP-based sites to drive your Web content from a database, why not add advanced natural language search capabilities? |
S o you've used Active Server Pages (ASP) to build yourself a dynamic Web site or application. You've gone beyond that to master Active Data Objects (ADO) and drive your Web content from SQL Server or some other database server. Next, you'll probably want to add some way for users to search and report on your database content. Of course, it's easy enough to add a query form that lets users search based on one or two fields. It's much harder to build form-based Web pages to allow searches across multiple tables and fields.
There are many problems beyond the mundane UI and Web coding aspects, including defining how the various tables and fields are related to each other. And even with the best interface, your pages will be difficult for your casual Web visitors to use and understand. There's an inevitable learning curve for any complex search of structured data. Fortunately, there is a powerful, flexible search specification mechanism that all your users are likely to understandthe English language. Since the introduction of Microsoft® English Query 1.0 with SQL Server 6.5 Enterprise Edition last year, such a capability is no longer the stuff of science fiction. English Query provides the ability for users to ask questions about your data in plain English in your existing database-driven Web sites and applications. Putting up your initial natural language search is very easya small fraction of the effort of building your overall application. The development process is higher level than traditional programming, and can be mastered by nonprogrammers with some database background (such as a DBA or Web content developer who often works with databases). English Query ships with an engine (a COM server) used at runtime to convert a user's English question to a SQL-friendly query. Microsoft even provides sample ASP pages that drive the engine, prompt a user for English questions, execute the engine's returned SQL, and display the database's results to the user. Let's take a look at authoring your own English Query domain and embedding the English Query engine and authored domain into your Web site. English Query can be embedded into any application that supports COM, but most commonly it's embedded into a Web site built with ASP scripts. Figure 1 shows a Web page created using the sample ASP scripts that come with English Query. The user enters a question or clicks the Sample Questions button. The Sample Questions button gives the user some predefined questions that demonstrate the kinds of information that are available. Pressing Enter submits the question to the English Query engine, which generates a SQL statement that is submitted to SQL Server via ADO. The returned recordset is then displayed in the lower frame.
Authoring an English Query Domain
Creating Entities
|
Figure 3: Defining an Entity |
Major entities have two kinds of minor entities associated with them: names and traits. Names indicate how the entity is identified in plain English questions and statements. Clicking on the Autoname button for the author major entity will create a minor entity that represents the name of the author, represented by the first and last name fields. You'll want to create such name entities for major entities that are represented by entire tables so that the user has some way of identifying the entity in question.
Creating Relationships
|
Figure 5: Defining a Relationship |
Next you'll create phrasings for that relationship. They can be verb phrasings ("authors write books"), preposition phrasings ("publishers are in cities"), adjective phrasings ("books are popular"), or subset phrasings ("some books
are bestsellers"). Most trait phrasings ("books have royalties") and name phrasings ("author names are the names of authors") are created by Autotrait and Autoname, as I've just shown. Figure 6 shows a verb phrasing defined for "authors write books." |
Figure 6: Adding a Phrasing |
Select the Database tab to specify a table that contains links to all relationships (in this example, the titleauthor table is computed automatically by the tool). You can create relationships for every kind of question that you want the user to be able to ask. For example, if you want the model to support questions about authors being in cities, you'd go back to the "authors have cities" relationship and supply a new preposition phrasing that says that "authors are in cities."
Testing Your Model
|
Figure 7: Testing Your Application |
Another Tools menu item called Regression Test will execute all queries in the Question File and compare the output against a reference file (which is usually generated the first time you run Regression). This is a good way to make sure you haven't broken your model as it becomes more and more complex over time. The Question File questions can also be used as a set of sample questions on the Web page to give users an idea of the kinds of information that are available. Once you've developed and tested the model to your satisfaction inside the English Query authoring tool, you're ready to build the application. Tools | Build Application will create the English Query domain (EQD) file. The EQD file and the English Query engine (the COM server MSEQ.Session) can be deployed inside any application that supports COM.
Adding English Query to Your Web Site
Summary
|
From the April 1998 issue of Microsoft Interactive Developer.