uk.ac.ic.doc.automed.p2p.qproc
Class KRange

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.qproc.KRange
All Implemented Interfaces:
java.io.Serializable

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

See Also:
Serialized Form

Field Summary
static double alpha
           
private  boolean analysed
           
private  boolean caseSensitive
          The IQL functions that represent this k-range TODO: keep this field serializable for memory-usage reason.
static java.lang.String COMPOUND
           
static java.lang.String CONTAINSALL
           
static java.lang.String CONTAINSANY
           
static java.lang.String EMPTY_RANGE
           
static java.lang.String EQUAL
           
private  java.lang.String fname
           
static java.lang.String GREATERTHAN
           
static java.lang.String GREATERTHANEQUAL
           
static java.lang.String IN
           
static double KRANGE_NOT_MATCH
           
static double KRANGE_NOT_SPECIFIED
           
private  boolean leftBounded
           
static java.lang.String LESSTHAN
           
static java.lang.String LESSTHANEQUAL
           
static java.lang.String MEMBER
           
private static java.lang.String NLINE
           
private  java.lang.Object[][] rangeArr
           
private  ASG rangeDef
           
private  java.util.List ranges
           
private  boolean rightBounded
           
private static long serialVersionUID
           
private  int size
           
private  java.lang.String toRawString
           
private  java.lang.String toString
           
private  int type
           
static int TYPE_BOUNDED
           
static int TYPE_COUNTABLE
           
static int TYPE_NUMERIC
           
static int TYPE_SINGLE_BOUNDED
           
static int TYPE_STRING
           
static int TYPE_UNCOUNTABLE
           
static java.lang.String VALLIST
           
 
Constructor Summary
private KRange()
          private constructor ONLY to be used from inside this class to create a compound range term
  KRange(ASG rangeDef, java.lang.String fname)
           
  KRange(java.lang.String rangeDefStr)
           
  KRange(java.lang.String rangeDefStr, java.lang.String fname)
           
 
Method Summary
private  void add(KRange kr)
           
private  void analyse()
           
 KRange combineWith(java.lang.String kwd)
          Create a new KRange object by combining this object with a keyword.
private  boolean equal(Cell ce, double testVal)
           
private  boolean equal(Cell ce, java.lang.String testVal, boolean cs)
           
private static boolean eval(double v, AutoMedQueryToken token, double c)
          an eval function to compare between two numeric (long) values
private static boolean eval(java.lang.String s1, AutoMedQueryToken token, java.lang.String s2, boolean cs)
          an eval function to compare two string values
 java.util.List getAsFunctions(java.lang.String var)
          Return the IQL function that represents this k-range.
 java.util.List getAsFunctions(java.lang.String var, java.lang.String hdmType)
          A more generic method that generates IQL functions from a k-range.
It also uses the HDM data type of the actual schema object to which the k-node of this k-range is mapped.
 java.lang.String getFunctionName()
          Return the function name
 AutoMedQueryToken getFunctionToken()
          Translate the function name into the corresponding query token
 java.lang.Object[][] getRangeAsArr()
          Parse the range expression into an array of objects: - an object may either represent an ArrayList (for member of function) - or an array of 4 elements: lower sign, lower val, upper sign and upper val Whilst performing this, we also check whether this range is single-bounded or bounded
 java.lang.String getRangeAsString()
           
 ASG getRangeDef()
           
 int getType()
          Return the type of this k-range
 boolean isArithmeticFunction()
           
static boolean isArithmeticFunction(java.lang.String fname)
          Returns true if the function name is one of the arithmetic functions
e.g.
 boolean isCompound()
          returns true if this is a compound range
 boolean isCountable()
          Does the range repreresent a countable set?
 boolean isEmpty()
           
 boolean isEqualCheck()
           
static boolean isEqualCheck(java.lang.String fname)
          Returns true if the function is an arithmetic function '=' or it is one of the other functions and its argument is a list of values
 boolean isEqualFunction()
           
 boolean isFloat()
           
 boolean isInFunction()
           
 boolean isInteger()
           
 boolean isLowerBoundFunction()
           
 boolean isMemberOf(double testVal)
          Check that a value is a member of the numeric range
 boolean isMemberOf(java.lang.String testVal, boolean cs)
          Check that a test value is a member of a string range
 boolean isNumeric()
           
 boolean isString()
           
 boolean isUpperBoundFunction()
           
 boolean isValueList(java.lang.Object[] rangeObj)
          Check if a range array object is a value list
 boolean isValueListFunction()
           
static boolean isValueListFunction(java.lang.String fname)
          Returns true if k-range function takes a value list as its argument
 boolean isValueRange()
          Returns true if this represents a value range expression, e.g.
 double match(KRange kr, StringMatcher m)
          Measure the matching degree with another k-range.
private  double matchLeftBoundedNumericRange(java.lang.Object[] r1, java.lang.Object[] r2)
          Match range r1 with range r2 knowing that both are at least left bounded and that the left bound of r2 is higher than the left bound of r1
private  double matchNumericBoundedRange(java.lang.Object[] r1, java.lang.Object[] r2)
           
private  double matchNumericListWithRange(java.util.Collection vals, java.lang.Object[] r1)
           
private  double matchStringListWithRange(java.util.Collection vals, java.lang.Object[] r1, StringMatcher m)
          Match list of strings with a string range
 void setCaseSensitive(boolean caseSensitive)
           
 int size()
          If the range is a countable set then we could count its number of elements using this method
 java.lang.String toString()
           
 java.lang.String toStringFriendly()
          Return the text-friendly version of a k-range
 java.lang.String toStringRaw()
          Aggregate all ranges into one big range
private  void updateList(Cell ce, java.util.List l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

rangeDef

private ASG rangeDef

fname

private java.lang.String fname

caseSensitive

private boolean caseSensitive
The IQL functions that represent this k-range TODO: keep this field serializable for memory-usage reason.


analysed

private transient boolean analysed

size

private transient int size

toString

private transient java.lang.String toString

toRawString

private transient java.lang.String toRawString

ranges

private transient java.util.List ranges

type

private transient int type

rangeArr

private transient java.lang.Object[][] rangeArr

leftBounded

private transient boolean leftBounded

rightBounded

private transient boolean rightBounded

EMPTY_RANGE

public static final java.lang.String EMPTY_RANGE
See Also:
Constant Field Values

GREATERTHAN

public static final java.lang.String GREATERTHAN
See Also:
Constant Field Values

GREATERTHANEQUAL

public static final java.lang.String GREATERTHANEQUAL
See Also:
Constant Field Values

LESSTHAN

public static final java.lang.String LESSTHAN
See Also:
Constant Field Values

LESSTHANEQUAL

public static final java.lang.String LESSTHANEQUAL
See Also:
Constant Field Values

EQUAL

public static final java.lang.String EQUAL
See Also:
Constant Field Values

VALLIST

public static final java.lang.String VALLIST
See Also:
Constant Field Values

COMPOUND

public static final java.lang.String COMPOUND
See Also:
Constant Field Values

CONTAINSALL

public static final java.lang.String CONTAINSALL
See Also:
Constant Field Values

CONTAINSANY

public static final java.lang.String CONTAINSANY
See Also:
Constant Field Values

MEMBER

public static final java.lang.String MEMBER
See Also:
Constant Field Values

IN

public static final java.lang.String IN
See Also:
Constant Field Values

NLINE

private static final java.lang.String NLINE
See Also:
Constant Field Values

KRANGE_NOT_SPECIFIED

public static final double KRANGE_NOT_SPECIFIED
See Also:
Constant Field Values

KRANGE_NOT_MATCH

public static final double KRANGE_NOT_MATCH
See Also:
Constant Field Values

TYPE_COUNTABLE

public static final int TYPE_COUNTABLE
See Also:
Constant Field Values

TYPE_UNCOUNTABLE

public static final int TYPE_UNCOUNTABLE
See Also:
Constant Field Values

TYPE_NUMERIC

public static final int TYPE_NUMERIC
See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
See Also:
Constant Field Values

TYPE_BOUNDED

public static final int TYPE_BOUNDED
See Also:
Constant Field Values

TYPE_SINGLE_BOUNDED

public static final int TYPE_SINGLE_BOUNDED
See Also:
Constant Field Values

alpha

public static final double alpha
Constructor Detail

KRange

public KRange(java.lang.String rangeDefStr,
              java.lang.String fname)
       throws ParseException
Throws:
ParseException

KRange

public KRange(java.lang.String rangeDefStr)
       throws ParseException
Throws:
ParseException

KRange

public KRange(ASG rangeDef,
              java.lang.String fname)

KRange

private KRange()
private constructor ONLY to be used from inside this class to create a compound range term

Method Detail

getRangeDef

public ASG getRangeDef()

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)

getAsFunctions

public java.util.List getAsFunctions(java.lang.String var)
Return the IQL function that represents this k-range.

Returns:

getAsFunctions

public java.util.List getAsFunctions(java.lang.String var,
                                     java.lang.String hdmType)
A more generic method that generates IQL functions from a k-range.
It also uses the HDM data type of the actual schema object to which the k-node of this k-range is mapped.

Parameters:
var -
hdmType -
Returns:

getFunctionName

public java.lang.String getFunctionName()
Return the function name

Returns:

getFunctionToken

public AutoMedQueryToken getFunctionToken()
Translate the function name into the corresponding query token

Returns:

analyse

private void analyse()

isValueRange

public boolean isValueRange()
Returns true if this represents a value range expression, e.g. [1970,1980] or
['a','Z'] or > 1970

Returns:

isInFunction

public boolean isInFunction()

isLowerBoundFunction

public boolean isLowerBoundFunction()

isUpperBoundFunction

public boolean isUpperBoundFunction()

isEqualFunction

public boolean isEqualFunction()

isEmpty

public boolean isEmpty()

isNumeric

public boolean isNumeric()

isInteger

public boolean isInteger()

isFloat

public boolean isFloat()

isString

public boolean isString()

isCountable

public boolean isCountable()
Does the range repreresent a countable set?

Returns:

size

public int size()
If the range is a countable set then we could count its number of elements using this method


toStringRaw

public java.lang.String toStringRaw()
Aggregate all ranges into one big range

Returns:

toStringFriendly

public java.lang.String toStringFriendly()
Return the text-friendly version of a k-range


toString

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

isMemberOf

public boolean isMemberOf(double testVal)
Check that a value is a member of the numeric range

Returns:

equal

private boolean equal(Cell ce,
                      double testVal)

equal

private boolean equal(Cell ce,
                      java.lang.String testVal,
                      boolean cs)

isMemberOf

public boolean isMemberOf(java.lang.String testVal,
                          boolean cs)
Check that a test value is a member of a string range

Parameters:
testVal -
Returns:

getRangeAsString

public java.lang.String getRangeAsString()

getRangeAsArr

public java.lang.Object[][] getRangeAsArr()
Parse the range expression into an array of objects: - an object may either represent an ArrayList (for member of function) - or an array of 4 elements: lower sign, lower val, upper sign and upper val Whilst performing this, we also check whether this range is single-bounded or bounded

Returns:

updateList

private void updateList(Cell ce,
                        java.util.List l)

isValueList

public boolean isValueList(java.lang.Object[] rangeObj)
Check if a range array object is a value list

Returns:

isArithmeticFunction

public static boolean isArithmeticFunction(java.lang.String fname)
Returns true if the function name is one of the arithmetic functions
e.g. >, < and so on

Returns:

isValueListFunction

public static boolean isValueListFunction(java.lang.String fname)
Returns true if k-range function takes a value list as its argument

Parameters:
fname -
Returns:

isValueListFunction

public boolean isValueListFunction()

isEqualCheck

public static boolean isEqualCheck(java.lang.String fname)
Returns true if the function is an arithmetic function '=' or it is one of the other functions and its argument is a list of values

Parameters:
fname -
Returns:

isArithmeticFunction

public boolean isArithmeticFunction()

isEqualCheck

public boolean isEqualCheck()

getType

public int getType()
Return the type of this k-range

Returns:

match

public double match(KRange kr,
                    StringMatcher m)
Measure the matching degree with another k-range.
This method returns:
0 if two ranges dont match,
-1 if one or both do not have range expressions, or
a positive real number in (0,1] for the degree of match

Returns:

matchStringListWithRange

private double matchStringListWithRange(java.util.Collection vals,
                                        java.lang.Object[] r1,
                                        StringMatcher m)
Match list of strings with a string range

Parameters:
vals -
r1 -
Returns:

matchNumericListWithRange

private double matchNumericListWithRange(java.util.Collection vals,
                                         java.lang.Object[] r1)

matchNumericBoundedRange

private double matchNumericBoundedRange(java.lang.Object[] r1,
                                        java.lang.Object[] r2)

matchLeftBoundedNumericRange

private double matchLeftBoundedNumericRange(java.lang.Object[] r1,
                                            java.lang.Object[] r2)
Match range r1 with range r2 knowing that both are at least left bounded and that the left bound of r2 is higher than the left bound of r1

Parameters:
r1 -
r2 -
Returns:

eval

private static boolean eval(java.lang.String s1,
                            AutoMedQueryToken token,
                            java.lang.String s2,
                            boolean cs)
an eval function to compare two string values

Parameters:
v -
token -
c -
Returns:

eval

private static boolean eval(double v,
                            AutoMedQueryToken token,
                            double c)
an eval function to compare between two numeric (long) values

Parameters:
v -
token -
c -
Returns:

isCompound

public boolean isCompound()
returns true if this is a compound range

Returns:

combineWith

public KRange combineWith(java.lang.String kwd)
Create a new KRange object by combining this object with a keyword.

Parameters:
kwd -
Returns:

add

private void add(KRange kr)