Home > Articles > Data > SQL Server

SQL Server Reference Guide

Hosted by

Toggle Open Guide Table of ContentsGuide Contents

Close Table of ContentsGuide Contents

Close Table of Contents

English Query - Part 3

Last updated Mar 28, 2003.

I'm continuing my previous tutorials on Natural Language Processing (NLP) technology in SQL Server, using Microsoft's English Query. In the first tutorial I introduced the product, and in the last couple I explained how to install the product, as well as the questions we need to answer in the application and the physical data structure we have to support the answers. I also covered the types of Phrasings we have available within the product that give us the structures for the application.

We now have the Physical model components as well as the Semantic model. We're ready to design the application. If you have installed the product, you can perform the same steps I have here to create this application. If you don't have English Query installed, just follow along with these example screens.

Beginning in the Windows Start menu select the All Programs | Microsoft SQL Server | English Query | Microsoft English Query item. You're shown the following opening screen:

You're actually using Visual Studio to design and build English Query Applications, so you'll need to select the English Query Objects and then SQL Project Wizard item at the first panel. Name the project as I have here, and then click the Open button to continue. Notice that you can design solutions against Analysis Services as well as SQL Server. In fact, using English Query with Analysis Services is one of the most common ways to deliver a Natural Language solution, since you're normally dealing with a non-technical audience in an OLAP environment. The two products are a natural mix.

In the first set of screens you're asked for the connection information to the server you're going to use as the physical structure of the data. I won't go through each of those screens here, but you should be aware that the wizard will lead you through selecting data from Oracle, SQL Server or any other ODBC-compliant connection. You're asked to provide the name of the server and the credentials you use to connect to that server, if that applies.

You'll also have to specify the names of the views or tables you need to satisfy the physical structure. You'll recall from my earlier tutorials that we need authors and titleauthors for the simple questions in this example. I'm ignoring the sales questions we talked about to make the example simple.

The next screen in the Wizard is where things really begin to get interesting. Each part of the screen is significant, from the column titles to the symbols and icons on the screen. Take a moment to review the screen before you read on:

The system has attempted to derive the Phrasings the project needs to answer questions. It does a pretty good job too – at least most of the time. Let's take a deeper look at what the parts of this screen in the Wizard represents.

The first element is that several objects have checkboxes beside them. If a box is selected, the Entities and Relationships (as I explained in the previous tutorials in this series) will be created. If it's not checked, the Wizard won't create that item or type of item.

Each of the Entities is highlighted in blue. Clicking on the blue Entity name takes you to a property tab for that object.

Beside each Entity is a small icon that represents a Trait Phrasing, which I explained in the last tutorial. To the right of the screen in the next column is the database object that ties in to those Entities.

Two things are important to remember about this panel before you push the OK button. The first is that you should take your time and edit all of the items you can think of while you're in this Wizard. The more complete you are here, the less work you have to do later. The second thing to remember is that nothing is fatal – you can change any of the items the Wizard creates, and even add others. We'll do both of those in the course of this series.

I'll begin some of the changes we need to make with the selection boxes. The Wizard defaults to authors having items. If we take our time and think this through, we'll see that authors don't have all of the Traits the Wizard has picked out. For instance, the Wizard thinks that the authors have states. That might be true if the value in the state field could contain the text active and inactive. The states in question, however, are American states such as Florida or South Carolina. So we see right away that authors don't have states, they are in states.

Before I move away from this point I want to re-iterate a statement I've made throughout this series. When you design an English Query project, it is essential that you understand the source data and the questions the users will ask. Because of the ambiguity of language (bear right versus bear, right) you might end up giving the wrong answer to a question. For a professional DBA it's actually worse to give incorrect data than it is to give no data at all. If you don't provide an answer, the user knows to keep looking. Depending on how the data is used, giving an incorrect answer might be life-threatening.

I've made several changes to my Traits, mostly dealing with addresses. Notice that I set authors to have an address but be in a state or city. Again, the selections you make have everything to do with the questions the users might ask.

Now let's turn our attention to the Entities. After I make the change to set authors to be in a state, I click on the author object. This is the screen that appears:

This screen shows the relationships between the Semantic model and the Database or Physical model. The Wizard has correctly guessed that an author is made up of two fields: au_fname and au_lname. That works for this example, but the Wizard isn't always this lucky. That's why I made sure that I could get the answers I needed from the database using standard Transact-SQL (T-SQL) statements in my earlier tutorials. Having those queries defined and handy helps you fill out this portion of the screen.

Notice also that the Wizard has also guessed at a few Synonyms for the word author. It's come up with biographer and cause. I'm OK with biographer, but I'm not so sure about the word cause. I'll leave it for now, and I'll add writer and novelist to the list using the pull-down menu. We'll revisit this selection later.

In the Entity type box I've changed the default selection from None to Who. Setting this box properly helps English Query answer even more types of questions, because it begins to "understand" that the author entity is a person, and as such gets a whole bunch of English attributes of ownership. This doesn't always apply, but you should check each item to make the project more complete. The more time you spend on these selections, the more questions the system can answer.

I'm going to move on using the default settings for the rest of the objects by closing this panel and then selecting OK at the main Wizard screen. We're dropped into the main design screen for English Query.

We're going to stop here for now. In the next tutorial we'll come back and begin to explore this interface. We'll also begin to edit the current design and then add more objects and relationships to it. We'll close out the series by asking our application a few questions and check the answers we get back.

Informit Articles and Sample Chapters

If you happen to still use SQL Server 7, you can check out this free chapter on English Query for that version.

Online Resources

Microsoft's site for English Query is here.