How does it work?


Wine Agent demonstrates machine interface to a knowledge base ("KB") using a web-based ontological mark-up language. That is, by combining a logical reasoner (called JTP) with an OWL ontology, this example implementation operates over a domain that can one day exist as a web of interfacing definitions.

Thus the agent's operation can be described in three parts--consulting the ontology, performing queries, and outputting results. An example interaction traced through these three phases will precede an elaboration on why this application uses ontologies, and how future agents might continue to do so.


Ontology

The ontology underlying Wine Agent is freely accessed over the web. It contains hierarchies and descriptions of food and wine categories, along with restrictions on how particular instances might be paired together.

Wine

The ontology defines the concept of a wine with the declaration excerpted on the right. According to the specification, a wine is a potable liquid produced by at least one maker of type winery, and is made from at least one type of grape (such grapes are restricted to wine grapes elsewhere in the ontology.)

The full text of the declaration additionally stipulates that a wine comes from a region that is wine-producing and, most importantly to the agent, that a wine has four properties: color, sugar, body, and flavor.
   <rdfs:Class rdf:ID="WINE">
      <rdfs:subClassOf rdf:resource="#POTABLE-LIQUID"/>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#MAKER"/>
            <daml:minCardinality>
               1
            </daml:minCardinality>
         </daml:Restriction>
      </rdfs:subClassOf>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#MAKER"/>
            <daml:toClass rdf:resource="#WINERY"/>
         </daml:Restriction>
      </rdfs:subClassOf>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#GRAPE-SLOT"/>
            <daml:minCardinality>
               1 
      .........
   </rdfs:Class>
   (full text)
Meal Course

The concept of a meal course underlies pairing of a food with a wine. Each course is a consumable thing comprising at least one food and at least one drink, the latter of which is stipulated to be a wine.

When the user selects a type of course, or an individual food that gets mapped to a type of course, the agent will consult that course definition for restrictions on the constituent food or wine. All such course types map back to this concept, like objects to their superclasses in object-oriented programming. One such example follows...
   <rdfs:Class rdf:ID="MEAL-COURSE">
      <rdfs:subClassOf rdf:resource="#CONSUMABLE-THING"/>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#FOOD"/>
            <daml:minCardinality>
               1
            </daml:minCardinality>
         </daml:Restriction>
      </rdfs:subClassOf>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#FOOD"/>
            <daml:toClass rdf:resource="#EDIBLE-THING"/>
         </daml:Restriction>
      </rdfs:subClassOf>
      <rdfs:subClassOf>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#DRINK"/>
            <daml:minCardinality>
               1
      .........
   </rdfs:Class>
   (full text)
Pasta with Spicy Red Sauce

Suppose the user has selected fra diavolo, or perhaps pasta with spicy red sauce directly. The concept of such a food is defined elsewhere in the ontology, but most relevant here is the notion of a pasta with spicy red sauce course. Here the concept is defined as a type of meal course where the food must be a pasta with spicy red sauce.

Furthermore, such courses must be a subclass of those with specific restrictions on the properties of their wines. In particular, #DRINK-HAS-RED-COLOR-RESTRICTION and the like appear elsewhere, specfying the properties of candidate wines in a straightforward manner.
   <rdfs:Class rdf:ID="PASTA-WITH-SPICY-RED-SAUCE-COURSE">
      <daml:intersectionOf rdf:parseType="daml:collection">
         <rdfs:Class rdf:about="#MEAL-COURSE"/>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#FOOD"/>
            <daml:toClass rdf:resource="#PASTA-WITH-SPICY-RED-SAUCE"/>
         </daml:Restriction>
      </daml:intersectionOf>
      <rdfs:subClassOf
   rdf:resource="#DRINK-HAS-RED-COLOR-RESTRICTION"/>
      <rdfs:subClassOf
   rdf:resource="#DRINK-HAS-FULL-BODY-RESTRICTION"/>
      <rdfs:subClassOf
   rdf:resource="#DRINK-HAS-STRONG-FLAVOR-RESTRICTION"/>
      <rdfs:subClassOf
   rdf:resource="#DRINK-HAS-DRY-SUGAR-RESTRICTION"/>
   </rdfs:Class>
Chateau Lafite Rothschild Pauillac

One wine that matches the above restrictions is the Pauillac here described. This individual wine is simply defined as a Pauillac whose maker is Chateau Lafite Rothschild. Together with other statements in the ontology, this allows the reasoner to deduce many additional facts: that this a Medoc wine from Bordeaux, in France, and that it is red, to name a few.
   <rdf:Description
rdf:ID="CHATEAU-LAFITE-ROTHSCHILD-PAUILLAC">
         <rdf:type rdf:resource="#PAUILLAC"/>
      <MAKER rdf:resource="#CHATEAU-LAFITE-ROTHSCHILD"/>
   </rdf:Description>
Pauillac

For instance, the concept of a Pauillac specifies that all such wines feature full bodies and strong flavors, and are made entirely from cabernet sauvignon grapes. Further, Pauillacs are a particular subset of Medocs, distinguished by their origin in the Pauillac region. It is through this additional subclass relationship that Pauillac are defined elsewhere as red and dry.
   <rdfs:Class rdf:ID="PAUILLAC">
      <rdfs:subClassOf rdf:resource="#FULL-BODY-RESTRICTION"/>
      <rdfs:subClassOf rdf:resource="#STRONG-FLAVOR-RESTRICTION"/>
      <rdfs:subClassOf rdf:resource=
   "#CABERNET-SAUVIGNON-INDIVIDUAL-GRAPE-SLOT-RESTRICTION"/>
      <rdfs:subClassOf rdf:resource=
   "#GRAPE-SLOT-MAX-CARDINALITY-1-RESTRICTION"/>
      <daml:intersectionOf rdf:parseType="daml:collection">
         <rdfs:Class rdf:about="#MEDOC"/>
         <daml:Restriction>
            <daml:onProperty rdf:resource="#REGION"/>
            <daml:hasValue rdf:resource="#PAUILLAC-INDIVIDUAL"/>
         </daml:Restriction>
      </daml:intersectionOf>
   </rdfs:Class>

Reasoner

Following the above example through the ontology reveals a straightforward logical path for pairing the Pauillac with the selected course. Because it was specified in a standardized, machine-readable format, it is an equally straightforward task for any compliant automated reasoner.

For example, the wine agent uses an embedded theorem prover called JTP that is maintained at the same reseach lab. The various assertions and queries conducted during the sample interaction appear below, and should be readily generalizable to any typical reasoning system. Note that the namespace of each concept precedes each concept name--this is the syntactic embodiment of the semantic web, in that definitions can be combined from different ontologies. Note that the example ontology actually resides here, but its location has been changed to "http://ra1.stanford.edu/wkb" below in order to save space.

Creating the course

The first step is to assert the existence of a new course in order to handle the user's query. A unique name is generated ("NEW-COURSE9") and it is asserted to be of type PASTA-WITH-RED-SAUCE-COURSE. The drink for that course is asserted to be "WINE9".
Note that the new course and drink are to be defined in the local "wkb" wines knowledge base, and the concept of a course featuring spicy red pasta already is. However, the concept of type is separately defined in the rdf syntax declaration, hence the different namespace.
Assert:
(|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type
 |http://ra1.stanford.edu/wkb#|::|NEW-COURSE9|
 |http://ra1.stanford.edu/wkb#|::|PASTA-WITH-SPICY-RED-SAUCE-COURSE|)
Assert:
(|http://ra1.stanford.edu/wkb#|::|DRINK|
 |http://ra1.stanford.edu/wkb#|::|NEW-COURSE9|
 |http://ra1.stanford.edu/wkb#|::|WINE9|)
Querying for properties

Now that the course and wine have been created, the agent can query for the properties of the wine as implied by the various restrictions in the knowledge base. Specifically, it asks for the COLOR, BODY, SUGAR, and FLAVOR of WINE9. The answers are other concepts from the same knowledge base: RED, DRY, FULL, and STRONG.

Query:
(|http://ra1.stanford.edu/wkb#|::|COLOR|
 |http://ra1.stanford.edu/wkb#|::|WINE9|
 ?x)
----------->
X = |http://ra1.stanford.edu/wkb#|::|RED|

Query:
(|http://ra1.stanford.edu/wkb#|::|SUGAR|
 |http://ra1.stanford.edu/wkb#|::|WINE9|
 ?x)
----------->
X = |http://ra1.stanford.edu/wkb#|::|DRY|

Query:
(|http://ra1.stanford.edu/wkb#|::|BODY|
 |http://ra1.stanford.edu/wkb#|::|WINE9|
 ?x)
----------->
X = |http://ra1.stanford.edu/wkb#|::|FULL|

Query:
(|http://ra1.stanford.edu/wkb#|::|FLAVOR|
 |http://ra1.stanford.edu/wkb#|::|WINE9|
 ?x)
----------->
X = |http://ra1.stanford.edu/wkb#|::|STRONG|
Querying for wines

Retaining the property requirements obtained above, the agent can now use logical deduction in order to determine which if any wines in ontology satisfy those criteria. Here the agent asks for all concepts in the knowledge base which are of type wine, and which feature COLOR, SUGAR, BODY, and FLAVOR as properties which are set to RED, DRY, FULL, and STRONG, respectively.
Query:
(AND
 (|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type
  ?x
  |http://ra1.stanford.edu/wkb#|::|WINE|)
 (|http://ra1.stanford.edu/wkb#|::|COLOR|
  ?x
  |http://ra1.stanford.edu/wkb#|::|RED| )
 (|http://ra1.stanford.edu/wkb#|::|SUGAR|
  ?x
  |http://ra1.stanford.edu/wkb#|::|DRY| )
 (|http://ra1.stanford.edu/wkb#|::|BODY|
  ?x
  |http://ra1.stanford.edu/wkb#|::|FULL| )
 (|http://ra1.stanford.edu/wkb#|::|FLAVOR|
  ?x
  |http://ra1.stanford.edu/wkb#|::|STRONG| ) )
----------->
X = |http://ra1.stanford.edu/wkb#|::|CHATEAU-LAFITE-ROTHSCHILD-PAUILLAC|
Querying for varietals

Finally, for any wine retrieved from the knowledge base, the agent can now determine its varietal. Because it can process semantic information, the agent can use the ontology rather than syntactic manipulation, i.e. assuming that the varietal is the last word of the name. Rather, it searches for a concept of type wine of which the Chateau Lafite Rothschild Pauillac is an instance.
Query:
(AND
 (|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type
  |http://ra1.stanford.edu/wkb#|::|CHATEAU-LAFITE-ROTHSCHILD-PAUILLAC|
  ?x)
 (|http://www.w3.org/2000/01/rdf-schema#|::|subClassOf|
  ?x
  |http://ra1.stanford.edu/wkb#|::|WINE|))
----------->
X = |http://ra1.stanford.edu/wkb#|::|PAUILLAC|

Output

By the process traced above, the agent has now identified the properties of a suitable wine, at least one wine matching those properties, and the varietal of that particular wine. From here it is a matter of only text manipulation to generate the portal page.

The heading follows a rote natural language template to place the inferred property constraints in an English-like sentence. The link to wines.com follows a tailored set of rules to ensure an adequate number of responses. If no wine was found in the knowledge base, the search is for the conjunction of the desired properties. If any individual wines were identified, the wine searches for them by name, and also for their varietals. In such cases the properties go unused in order to avoid incorrect matches. In addition to responses concerning individual wines, the portal might also present suitable varietals. In such case the links represent wine.com searches for those varietals, created by looking up the appropriate codes used by the wine.com search engine, and adding them to the URL.


Why use an ontology?

The functionality provided by the wine agent is not unlike that which could be provided by a simple look-up table. Indeed, food/wine pairings are traditionally published in some form of tabular chart where marks appear at the intersections of columns and rows representing compatible varieties of food and wine. The wine agent demonstrates that at least this simple task can be accomplished within semantic markup technology, but the burden remains to demonstrate how this can be better in the future.

Suppose that if not the entire web, then at least some number of cooperating parties were using semantic markup to participate in this project. Rather than the traditional approach of trying to build an enormous database of foods and wines, then, the definitions would be distributed across the participating parties. A restaurant or retailer offering an on-line menu could mark each food item with standardized machine-readable definitions. Similarly, then, a wine retailer could mark its wines according to the definitions exemplified above.

Such markings would benefit from well-known advantages of ontologies. For instance, through the subclassing, adding a new Pauillac to the inventory would not require wine.com to mark all of the wine's properties; it would just be another Pauillac as specified in the example, plus any differentiating features. But more importantly in terms of software agents, all the markings would be machine readable, and could be handled by systems from any organization.

For instance, the above section notes that the interface to wine.com is compiled by hand. In the case of varietals search, the mapping from varietals to search codes was derived by a human systematically trying each possible search from a provided menu! Alternatively, by the web services model, a program such as the wine agent can interact with the wine.com search engine via a well-formed language. Such communications would not only cover wine information specific to the given application domain and ontology, but also model the very process of querying the inventory. Examples of the latter would include representations of sessions, requests, reponse sets, and exceptions.

The point is that in such a case, the existing implementation of the wine agent would already be able to parse any marked menu of food items, and access any marked inventory of wines, and perform its pairing. Rather than compiling a search string for wine.com as it does now, the agent would be able to search the inventory directly by referencing wines in the wine.com namespace. Rather than relying on a human user to select a food or food type, the agent could crawl the web for foods marked within the wines namespace and pre-compile suitable pairings.

poster describing wine agent (.ppt)...
back to wine agent...

Comments welcome.
Last modified: Tue Apr 8 10:57:20 PDT 2003