uk.ac.bbk.dcs.automed.qproc.iql
Class ASG

java.lang.Object
  extended by uk.ac.bbk.dcs.automed.qproc.iql.ASG
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ASGComprehension

public class ASG
extends java.lang.Object
implements java.io.Serializable

Every IQL query is internally represented as an Abstract Syntax Graph (ASG).

See Also:
Serialized Form

Field Summary
private static java.lang.String[] indents
           
private static int MAX_INDENT
           
protected  Cell root
           
 
Constructor Summary
protected ASG()
           
  ASG(Cell n)
           
  ASG(Cell n, boolean copy)
          Creates a new ASG object.
  ASG(java.io.File f)
           
  ASG(java.lang.String s)
           
 
Method Summary
 void annotate()
           
 ASG copyOfASG()
          Creates and returns an exact copy of the ASG.
static ASG emptyBag()
          Returns the ASG representation of the empty Bag - a BNil constructor.
static ASG emptyCollection(java.lang.String colType)
           
static ASG emptyList()
          Returns the ASG representation of the empty List - a Nil constructor.
static ASG emptySet()
          Returns the ASG representation of the empty Set - an SNil constructor.
 boolean equals(java.lang.Object o)
           
 boolean equalsButForConstants(java.lang.Object o)
           
 void explore()
           
private  void explore(Cell c, int indent, java.io.PrintStream ps)
           
private  void explore(Cell c, int indent, java.lang.StringBuffer sb)
           
 void explore(java.io.PrintStream ps)
           
 java.lang.String exploreAsString()
           
 void finalize()
           
 java.lang.String formattedString()
          Given that the ASG represents a list the string returned has each element separated by carriage returns for more legible output.
static java.lang.String fromASG(ASG g)
          Returns the text IQL of g.
static java.lang.String fromASG(Cell n)
          Returns the text IQL of the abstract syntax graph of which n is the root.
static java.util.ArrayList fromASGCollection(ASG g)
          If g represents a list/set/bag this returns an ArrayList of its Cells.
static java.util.ArrayList fromASGCollection(Cell n)
          If n is the root of an ASG that represents a list, this returns an ArrayList of its Cells.
static java.util.ArrayList fromASGList(ASG g)
          If g represents a list this returns an ArrayList of its Cells.
static java.util.ArrayList fromASGList(Cell n)
          If n is the root of an ASG that represents a list, this returns an ArrayList of its Cells.
static java.util.ArrayList fromASGTuple(ASG g)
          If g represents a tuple this returns an ArrayList of its Cells.
static java.util.ArrayList fromASGTuple(Cell n)
          If n is the root of an ASG that represents a tuple, this returns an ArrayList of its Cells.
static java.lang.String getColType(Cell c)
           
static java.lang.String getCompType(Cell c)
           
static java.util.List getGenerators(Cell c)
           
static java.util.List getGenerators(Cell c, boolean copy)
           
static void getGenerators(Cell c, java.util.LinkedList l, boolean deep, boolean copy)
           
static Cell getHead(Cell c)
           
static Cell getHead(Cell c, boolean copy)
           
static java.util.LinkedList getPredicates(Cell c)
           
static java.util.LinkedList getPredicates(Cell c, boolean copy)
           
static java.util.LinkedList getQualifiers(Cell c)
           
static java.util.LinkedList getQualifiers(Cell c, boolean copy)
           
static java.util.LinkedList getSchemeInfoObjects(Cell c)
           
static java.util.LinkedList getSchemeInfoObjects(Cell c, boolean copy)
           
private static void getSchemeInfoObjects(Cell c, java.util.LinkedList schemes, boolean copy)
           
static java.util.Collection getSchemes(Cell root, java.util.Collection col)
           
static java.util.List getTupleItems(ASG g)
           
static java.util.List getVars(Cell c)
           
static java.util.List getVars(Cell c, boolean copy)
           
 java.util.List listOfSchemeObjects()
          Return SchemeInfo objects instead of scheme strings
static java.util.ArrayList listOfSchemes(ASG g, boolean full)
          Returns a list of the schemes used in the ASG as String objects.
 java.util.ArrayList listOfSchemes(boolean full)
          Returns a list of the schemes used in the ASG as String objects.
private static java.util.ArrayList listOfSchemes(Cell n, boolean full)
           
static java.util.ArrayList listOfVars(Cell n)
           
private  void makeListOfSchemeObjects(java.util.List list, Cell n)
           
private static void makeListOfSchemes(java.util.ArrayList list, Cell n, boolean full)
           
private static void makeListOfVars(java.util.ArrayList list, Cell n)
           
 void print(boolean formatted)
          Prints g in System.out
 void print(java.io.PrintStream ps, boolean formatted)
           
private  void printIndent(java.io.PrintStream ps, int indent)
           
private  void printIndent(java.lang.StringBuffer sb, int indent)
           
 void println(boolean formatted)
           
 Cell root()
          Returns the root of the ASG
static ASG toASGCollection(java.util.List collection, java.lang.String type)
          Generates an ASG list from a Java List.
static ASG toASGList(java.util.ArrayList list)
          Generates an ASG list from an ArrayList.
static ASG toASGTuple(java.util.ArrayList list)
          Generates an ASG tuple from an ArrayList.
static java.lang.String toIQLDateTime(java.util.Calendar c)
           
 java.lang.String toString()
           
 java.lang.String toStringOBID()
          Use only for printing purposes in debug settings: works just like toString(), but schemes has an OBID suffix.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

root

protected Cell root

MAX_INDENT

private static final int MAX_INDENT
See Also:
Constant Field Values

indents

private static final java.lang.String[] indents
Constructor Detail

ASG

protected ASG()

ASG

public ASG(Cell n)
Parameters:
n - the root cell of a graph. This graph will be copied and packaged as an ASG.

ASG

public ASG(Cell n,
           boolean copy)
Creates a new ASG object.

Parameters:
n - the Cell that is to be the root of the ASG
copy - whether a copy of the tree of is to be created or not

ASG

public ASG(java.lang.String s)
    throws ParseException
Parameters:
s - text IQL query
Throws:
java.lang.Exception
ParseException

ASG

public ASG(java.io.File f)
Parameters:
f - text file containing the text of an IQL query.
Method Detail

toASGList

public static ASG toASGList(java.util.ArrayList list)
Generates an ASG list from an ArrayList. The ArrayList should be an array of Cells.


toASGCollection

public static ASG toASGCollection(java.util.List collection,
                                  java.lang.String type)
Generates an ASG list from a Java List. The List should be an array of Cells. Type is one of "List", "Set" or "Bag" WARNING: Does not transform from one collection type to another, i.e. if collection contains duplicates and type is "Set", then no error is thrown, or conversion is made.


toASGTuple

public static ASG toASGTuple(java.util.ArrayList list)
Generates an ASG tuple from an ArrayList. The ArrayList should be an array of Cells.


fromASGCollection

public static java.util.ArrayList fromASGCollection(ASG g)
If g represents a list/set/bag this returns an ArrayList of its Cells.

Throws:
QProcException

fromASGCollection

public static java.util.ArrayList fromASGCollection(Cell n)
If n is the root of an ASG that represents a list, this returns an ArrayList of its Cells.


fromASGList

public static java.util.ArrayList fromASGList(ASG g)
If g represents a list this returns an ArrayList of its Cells.


fromASGList

public static java.util.ArrayList fromASGList(Cell n)
If n is the root of an ASG that represents a list, this returns an ArrayList of its Cells.


fromASGTuple

public static java.util.ArrayList fromASGTuple(ASG g)
If g represents a tuple this returns an ArrayList of its Cells.

Throws:
QProcException

fromASGTuple

public static java.util.ArrayList fromASGTuple(Cell n)
If n is the root of an ASG that represents a tuple, this returns an ArrayList of its Cells.

Throws:
QProcException

getGenerators

public static java.util.List getGenerators(Cell c)
Parameters:
c - input Cell - assumes it is the root of a comprehension
Returns:
a list of pointers to the generators contained in the comprehension

getGenerators

public static java.util.List getGenerators(Cell c,
                                           boolean copy)
Parameters:
c - input Cell - assumes it is the root of a comprehension
copy - true if copies instead of pointers are needed
Returns:
a list of the generators contained in the comprehension

getGenerators

public static void getGenerators(Cell c,
                                 java.util.LinkedList l,
                                 boolean deep,
                                 boolean copy)
Parameters:
c - input Cell - assumes it is the root of a comprehension
copy - true if copies instead of pointers are needed

getPredicates

public static java.util.LinkedList getPredicates(Cell c)
Parameters:
c - input Cell - assumes it is the root of a comprehension
Returns:
a list of pointers to the predicates contained in the comprehension

getPredicates

public static java.util.LinkedList getPredicates(Cell c,
                                                 boolean copy)
Parameters:
c - input Cell - assumes it is the root of a comprehension
copy - true if copies instead of pointers are needed
Returns:
a list of the predicates (filters) contained in the comprehension

getQualifiers

public static java.util.LinkedList getQualifiers(Cell c)
Parameters:
c - input Cell - assumes it is the root of a comprehension
Returns:
a list of pointers to the qualifiers contained in the comprehension

getQualifiers

public static java.util.LinkedList getQualifiers(Cell c,
                                                 boolean copy)
Parameters:
c - input Cell - assumes it is the root of a comprehension
copy - true if copies instead of pointers are needed
Returns:
a list of the qualifiers (generators + filters) contained in the comprehension

getHead

public static Cell getHead(Cell c)
Parameters:
c - input Cell
Returns:
a pointer to the head of the comprehension

getHead

public static Cell getHead(Cell c,
                           boolean copy)
Parameters:
c - input Cell
copy - true if a copy instead of a pointer is needed
Returns:
the head of the comprehension

getSchemeInfoObjects

public static java.util.LinkedList getSchemeInfoObjects(Cell c)
Parameters:
c - input Cell
Returns:
a list of pointers to the SchemeInfo objects contained in the comprehension

getSchemeInfoObjects

public static java.util.LinkedList getSchemeInfoObjects(Cell c,
                                                        boolean copy)
Parameters:
c - input Cell
copy - true if a copy instead of a pointer is needed
Returns:
a list of the SchemeInfo objects contained in the comprehension

getSchemeInfoObjects

private static void getSchemeInfoObjects(Cell c,
                                         java.util.LinkedList schemes,
                                         boolean copy)

getVars

public static java.util.List getVars(Cell c)
Parameters:
c - input Cell
Returns:
a list of pointers to the variables contained in the subtree whose root is the input Cell

getVars

public static java.util.List getVars(Cell c,
                                     boolean copy)
Parameters:
c - input Cell
copy - true if a copy instead of a pointer is needed
Returns:
a list of the variables contained in the subtree whose root is the input Cell

getTupleItems

public static java.util.List getTupleItems(ASG g)
                                    throws QProcException
Throws:
QProcException

getSchemes

public static java.util.Collection getSchemes(Cell root,
                                              java.util.Collection col)

listOfSchemes

public java.util.ArrayList listOfSchemes(boolean full)
Returns a list of the schemes used in the ASG as String objects.

Parameters:
full - true if the format :P:S:M:C:<<...>>:T is needed, false if the simple <<...>> format is needed

listOfSchemeObjects

public java.util.List listOfSchemeObjects()
Return SchemeInfo objects instead of scheme strings

Parameters:
full -
Returns:

makeListOfSchemeObjects

private void makeListOfSchemeObjects(java.util.List list,
                                     Cell n)

listOfSchemes

public static java.util.ArrayList listOfSchemes(ASG g,
                                                boolean full)
Returns a list of the schemes used in the ASG as String objects.


listOfSchemes

private static java.util.ArrayList listOfSchemes(Cell n,
                                                 boolean full)

makeListOfSchemes

private static void makeListOfSchemes(java.util.ArrayList list,
                                      Cell n,
                                      boolean full)

listOfVars

public static java.util.ArrayList listOfVars(Cell n)

makeListOfVars

private static void makeListOfVars(java.util.ArrayList list,
                                   Cell n)

root

public Cell root()
Returns the root of the ASG


emptyList

public static ASG emptyList()
Returns the ASG representation of the empty List - a Nil constructor.


emptySet

public static ASG emptySet()
Returns the ASG representation of the empty Set - an SNil constructor.


emptyBag

public static ASG emptyBag()
Returns the ASG representation of the empty Bag - a BNil constructor.


emptyCollection

public static ASG emptyCollection(java.lang.String colType)
                           throws IQLException
Throws:
IQLException

getColType

public static java.lang.String getColType(Cell c)
                                   throws QProcException
Throws:
QProcException

getCompType

public static java.lang.String getCompType(Cell c)
                                    throws IQLException
Throws:
IQLException

copyOfASG

public ASG copyOfASG()
Creates and returns an exact copy of the ASG.


println

public void println(boolean formatted)

print

public void print(boolean formatted)
Prints g in System.out


print

public void print(java.io.PrintStream ps,
                  boolean formatted)

toStringOBID

public java.lang.String toStringOBID()
Use only for printing purposes in debug settings: works just like toString(), but schemes has an OBID suffix.


fromASG

public static java.lang.String fromASG(ASG g)
Returns the text IQL of g.


fromASG

public static java.lang.String fromASG(Cell n)
Returns the text IQL of the abstract syntax graph of which n is the root.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

formattedString

public java.lang.String formattedString()
Given that the ASG represents a list the string returned has each element separated by carriage returns for more legible output.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

equalsButForConstants

public boolean equalsButForConstants(java.lang.Object o)

annotate

public void annotate()

printIndent

private void printIndent(java.lang.StringBuffer sb,
                         int indent)

printIndent

private void printIndent(java.io.PrintStream ps,
                         int indent)

explore

public void explore()

explore

public void explore(java.io.PrintStream ps)

exploreAsString

public java.lang.String exploreAsString()

explore

private void explore(Cell c,
                     int indent,
                     java.lang.StringBuffer sb)

explore

private void explore(Cell c,
                     int indent,
                     java.io.PrintStream ps)

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

toIQLDateTime

public static java.lang.String toIQLDateTime(java.util.Calendar c)