In the last two articles, we walked you through Q&A’s basic linguistic capabilities and how you can optimize your model to best take advantage of them. Since those with short attention spans have long-since stopped reading, we can now safely reveal to those of you who remain the secret incantations that will soon be available for you to take your models to the next level. Behold: Phrasings.
What Is a Phrasing?
A phrasing is, quite simply, how you talk about (or “phrase”) the relationships between things. For example, to describe the relationship between customers and products, you might say “customers buy products”. Or to describe the relationship between customers and ages, you might say “ages indicate how old customers are”. Or to describe the relationship between customers and phone numbers, you might simply say “customers have phone numbers”.
These phrasings come in a variety of shapes and sizes. Some correspond directly with relationships in the semantic model. Some relate columns with their containing tables. Others relate multiple tables and columns together in complex relationships. In all cases, they describe how things are related using everyday terms.
Where Do Phrasings Come From?
Many simple phrasings are added to the model automatically, based on the structure of the model and some guesses based on column names. For example:
- Most columns will be related to their containing table with a simple phrasing like “products have descriptions”
- Model relationships result in default phrasings for both directions of the relationship like “orders have products” and “products have orders”.
- Some model relationships can, based on their column names, get a more complex default phrasing like “orders are shipped to cities”
There are plenty of ways your users will talk about things that we can’t guess, however. For those, you may want to add your own phrasings manually.
Why Should I Add Phrasings?
The first reason for adding a phrasing is to define a new term. For example, if you want to be able to ask “list the oldest customers”, you must first teach Q&A what you mean by “old”. You would do so by adding a phrasing like “old customers are customers with large ages”.The second reason for adding a phrasing is to resolve ambiguity. Basic keyword search only goes so far when words have more than one meaning. For example, “flights to Chicago” means something quite different than “flights from Chicago”, but Q&A won’t know which one you mean unless you add the phrasings “flights are from departure cities” and “flights are to arrival cities”. Similarly, the distinction between “cars that John sold to Mary” and “cars that John bought from Mary” will only be understood once you add the phrasings “customers buy cars from employees” and “employees sell customers cars”.The final reason for adding a phrasing is to improve restatements. Rather than Q&A echoing back to you “Show the customers and their products”, it would be clearer if it were to say “Show the customers and the products they bought” or “Show the customers and the products they reviewed”, depending on how it understood the question. Adding custom phrasings allows restatements to be more explicit and unambiguous.
What Kinds of Phrasings Are There?
To understand the different types of phrasings, you’re first going to have to dredge up a few repressed memories of English class from when you were ten years old. For those of you who were too traumatized by Mrs. Blagswotter’s fiery temper and rants about “improper conjugation” to remember any of this, we’ll give you a relatively quick and painless refresher:
A noun is a person, place, or thing.
Examples: car, teenager, Marty, flux capacitor
A verb is an action or state of being.
Examples: hatch, burst, devour, eject
An adjective is a descriptive word that modifies a noun.
Examples: powerful, magical, golden, stolen
A preposition is a word used before a noun to relate it to a previous noun, verb or adjective
Examples: of, for, near, from
Ok, you can uncover your eyes now. It’s over.
Attribute phrasings are the workhorse of Q&A, used when one thing is acting as an attribute of another thing. They’re simple, straightforward and perform most of the heavy lifting when a subtler, more detailed phrasing hasn’t been defined. Attribute phrasings are described using the basic verb “have” (e.g. “products have categories”), and automatically also allow questions to be asked using “of” and “for” (e.g. “categories of products”, “orders for products”) and possessive (e.g. “John’s orders”). Attribute phrasings are used in questions such as this:
Which customers have orders?
Show orders that have chai
List customers with orders
What is the category of each product?
Count Robert King's orders
The overwhelming majority of attribute phrasings needed in your model will be automatically generated, based on table/column containment and model relationships, so you typically won’t need to create them yourself.
Name phrasings are key for tables in your model which represent things that have names. For example, a “product names are names of products” phrasing is essential for being able to use product names in questions. While a name phrasing also enables “named” as a verb (e.g. “List customers named John Smith”), it is most important when used in conjunction with other phrasings, to allow a name value to be used to refer to a particular table row. For example, in “Customers that bought chai”, Q&A can tell that the value “chai” is referring to a product rather than merely a product name. Name phrasings are used in questions such as this:
Which employees are named Robert King
Who is named Ernst Handel
What did Robert King buy?
Assuming you used a sensible naming convention for name columns in your model (e.g. “Name” or “ProductName” rather than “PrdNm”), the majority of name phrasings needed in your model will be automatically generated, so you usually won’t need to create them yourself.
Adjective phrasings define new adjectives used describe things in your model. For example, a “happy customers are customers where rating > 6” phrasing is needed to ask questions like “list the happy customers in Des Moines”. There are several forms of adjective phrasings, for use in different situations.
Simple adjective phrasings define a new adjective based on a condition, such as “discontinued products are products where status = D”. Simple adjective phrasings are used in questions such as this:
Which products are discontinued?
List the discontinued products
Products that are backordered
Measurement adjective phrasings define a new adjective based on a numeric value that indicates the extent to which the adjective applies, such as “long rivers are rivers with large lengths”. Measurement adjective phrasings are used in questions such as this:
List the long rivers
Which rivers are the longest?
How long is the Rio Grande?
Dynamic adjective phrasings define a set of new adjectives based on values in a column in the model, such as “colors describe products”. Dynamic adjective phrasings are used in questions such as this:
List the red products
Which products are green?
Count issues that are active
Noun phrasings define new nouns that describe subsets of things in your model. For example, a “flops are movies where net profit < 0” phrasing is needed to ask questions like “count the flops by year”. There are two forms of noun phrasings, for use in different situations.
Simple noun phrasings define a new noun based on a condition, such as “contractors are employees where full time = false”. Simple noun phrasings are used in questions such as this:
Which employees are contractors?
Count the contractors in Portland
Dynamic noun phrasings define a set of new nouns based on values in a column in the model, such as “jobs define subsets of employees”. Dynamic noun phrasings are used in questions such as this:
List the cashiers in Chicago
Which employees are baristas?
Preposition phrasings are used to describe how things in your model are related via prepositions. For example, a “cities are in countries” phrasing improves understanding of questions like “count the cities in Washington”. Some preposition phrasings are created automatically when a column is recognized as a geographical entity. Preposition phrasings are used in questions such as this:
Count the customers in New York
List the books about linguistics
Which city is John Galt in?
How many books are by Stephen Pinker?
Verb phrasings are used to describe how things in your model are related via verbs. For example, a “customers buy products” phrasing improves understanding of questions like “who bought cheese?” and “what did John buy?” Verb phrasings are the most flexible of all of the types of phrasings, often relating more than two things to each other, such as in “employees sell customers products”. Verb phrasings are used in questions such as this:
Who sold what to whom?
Which employee sold chai to John?
How many customers were sold chai by Mary?
List the products that Mary sold to John.
Which discontinued products were sold to Chicago customers by Boston employees?
Verb phrasings can also contain prepositional phrases, thereby adding to their flexibility, such as in “athletes win medals at competitions” or “customers are given refunds for products”. Verb phrasings with prepositional phrases are used in questions such as this:
How many athletes won a gold medal at the Visa Championships?
Which customers were given a refund for cheese?
At which competition did Danell Leyva win a gold medal?
Some verb phrasings are created automatically when a column is recognized as containing both a verb and a preposition.
When All Else Fails
There’s one additional feature that will be available to you for when phrasings aren’t enough: Global Synonyms. A global synonym is a simple textual replacement which is applied to any question prior to Q&A trying to understand it. This can be used in some cases where there exists no phrasing type applicable for the kind of question you are trying to enable.
For example, with this global synonym: “how do you make” means “recipe for”
Then this question: How do you make a Shirley Temple?
Would be answered as if you asked: Recipe for a Shirley Temple?
Only the Beginning
Hopefully, this series of articles has given you a basic sense of the kinds of things you can expect Q&A to handle right now and what you can do to improve its understanding by tweaking your model and later by adding phrasings. Over time, Q&A’s general fluency will continue to grow, as will its ability to be taught linguistic hints about your model. For now, think of it as a precocious grade-schooler, full of enthusiasm and with an excellent intuition for language, but limited in both life experience and vocabulary. The more you teach him, the better job he’ll do on his homework.