Building Parsers with Java

sjm.examples.query
Class QueryBuilder

java.lang.Object
  |
  +--sjm.examples.query.QueryBuilder

public class QueryBuilder
extends java.lang.Object
implements PubliclyCloneable

This class accepts terms, class names and comparisons, and then builds a query from them. The query this builder creates will have the form:

	
     q(term0, term1, ...), 
     className0, className1, ...,
     comparison0, comparison1, ...
 
The first structure forms a "projection", which is set of terms that should all be valid after the remaining structures prove themselves. To use the query after building it, prove its tail to establish values for its head. For example, consider the select statement:
    select PricePerBag * 0.9 
        from chip 
        where PricePerBag > 10
 
a parser for this statement can pass a QueryBuilder one term, one class name and one comparison; the builder will take these and build the query:
     q(*(PricePerBag, 0.9)), 
     chip(ChipID, ChipName, PricePerBag, Ounces, Oil), 
     >(PricePerBag, 10.0)
 
A program can prove the tail of this query (that is, all the structures after the first). Each proof of the tail will establish a value for the PricePerBag variable. After each proof, the term in the head structure will have a value of .9 times the PricePerBag.


Field Summary
protected  java.util.Vector classNames
           
protected  java.util.Vector comparisons
           
protected  Speller speller
           
protected  java.util.Vector terms
           
 
Constructor Summary
QueryBuilder(Speller speller)
          Construct a query builder that will use the given speller.
 
Method Summary
 void addClassName(java.lang.String s)
          Add the given class name to the query.
 void addComparison(Comparison c)
          Add a comparison to the query.
 void addTerm(Term t)
          Add a term that will appear in the head structure of the query.
 Query build(AxiomSource as)
          Create a query from the terms, class names and variables this object has received so far.
 java.lang.Object clone()
          Return a copy of this object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

speller

protected Speller speller

terms

protected java.util.Vector terms

classNames

protected java.util.Vector classNames

comparisons

protected java.util.Vector comparisons
Constructor Detail

QueryBuilder

public QueryBuilder(Speller speller)
Construct a query builder that will use the given speller.
Method Detail

addClassName

public void addClassName(java.lang.String s)
Add the given class name to the query. This method checks that the class name when properly spelled matches a known class name.

addComparison

public void addComparison(Comparison c)
Add a comparison to the query.

addTerm

public void addTerm(Term t)
Add a term that will appear in the head structure of the query.

build

public Query build(AxiomSource as)
Create a query from the terms, class names and variables this object has received so far.

clone

public java.lang.Object clone()
Return a copy of this object.
Specified by:
clone in interface PubliclyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy of this object

by Steve Metsker