edu.northwestern.at.wordhoard.swing.calculator.cql
Class CQLTerm

java.lang.Object
  extended by edu.northwestern.at.wordhoard.swing.calculator.cql.CQLTerm

public class CQLTerm
extends java.lang.Object

A WordHoard Corpus Query Language term.

The general form of a query term is:

[!]func({text})

!means "do not match the text defined by this term." By default, the text will be matched.

func is the term type. Example: spe means spelling.

text is the term text. If enclosed in braces, it is assumed to be a regular expression. The term text need not be enclosed in quotes unless it contains blanks or special characters.

Examples:


Field Summary
protected static java.util.HashMap allowsOperators
          True if element value can contain operator.
static int AUTHORCONTEMPORARY
           
static int AUTHORNAME
           
static int CORPUSTAG
           
static int CORPUSTITLE
           
protected static java.util.HashMap elementsToHQLNames
          Maps term types to HQL names.
protected static java.util.HashMap elementsToNames
          Maps term types to CQL names.
protected static java.lang.String gender_female
           
protected static java.lang.String gender_male
          Object model data values.
protected static java.lang.String gender_uncertain
           
protected  boolean isRegExp
          True if query text is a regular expression.
static int ISVERSE
           
static int LEMMA
           
static int MAJORWORDCLASS
           
protected  boolean matchTerm
          True to match the query text, false to not match it.
static int METRICALSHAPE
           
protected static java.lang.String mortality_immortal
           
protected static java.lang.String mortality_mortal
           
protected static java.lang.String mortality_uncertain
           
protected static java.util.HashMap namesToElements
          Maps CQL names to term types.
static int NARRATIVE
           
static int POS
           
protected static java.lang.String prosodic_prose
           
protected static java.lang.String prosodic_unknown
           
protected static java.lang.String prosodic_verse
           
static int PUBLICATIONYEAREARLY
           
static int PUBLICATIONYEARLATE
           
static int SEMANTICTAGS
           
static int SPEAKER
           
static int SPEAKERGENDER
           
static int SPEAKERMORTALITY
           
static int SPELLING
          The query term types.
protected  java.lang.String termText
          The query term text.
protected  int termType
          The type of query term.
static int WORDCLASS
           
static int WORDPARTCOUNT
           
static int WORKFULLTITLE
           
static int WORKPARTFULLTITLE
           
static int WORKPARTSHORTTITLE
           
static int WORKPARTTAG
           
static int WORKSHORTTITLE
           
static int WORKTAG
           
 
Constructor Summary
CQLTerm()
          Create new term type.
CQLTerm(CQLQueryTokenizer tokenizer)
          Create a new term type from a CQLQueryTokenizer.
CQLTerm(java.lang.String termText, int termType, boolean matchTerm, boolean isRegExp)
          Create a new term type.
 
Method Summary
 boolean equals(java.lang.Object other)
          Check if this query term is equal to another.
protected  java.lang.String getTermTypeName(int termType)
          Get term type name.
 boolean hasAuthor()
          Determine if query term refers to an author.
 int hashCode()
          Hash code for query term.
 boolean hasSpeaker()
          Determine if query term refers to a speaker.
 boolean hasSpeech()
          Determine if query term refers to a speech.
 boolean hasWordPart()
          Determine if query term refers to a word part.
 boolean hasWork()
          Determine if query term refers to a work.
 boolean hasWorkPart()
          Determine if query term refers to a work part.
 java.lang.String toHQL(java.lang.String queryField, int fieldIndex, boolean doingWords)
          Get HQL version of query term.
 java.lang.String toString()
          Get string version of query term for display.
protected  void validateTermText(CQLQueryTokenizer tokenizer)
          Fix up query arguments as needed to match database values.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SPELLING

public static final int SPELLING
The query term types.

See Also:
Constant Field Values

LEMMA

public static final int LEMMA
See Also:
Constant Field Values

POS

public static final int POS
See Also:
Constant Field Values

WORDCLASS

public static final int WORDCLASS
See Also:
Constant Field Values

MAJORWORDCLASS

public static final int MAJORWORDCLASS
See Also:
Constant Field Values

SPEAKER

public static final int SPEAKER
See Also:
Constant Field Values

SPEAKERGENDER

public static final int SPEAKERGENDER
See Also:
Constant Field Values

SEMANTICTAGS

public static final int SEMANTICTAGS
See Also:
Constant Field Values

ISVERSE

public static final int ISVERSE
See Also:
Constant Field Values

METRICALSHAPE

public static final int METRICALSHAPE
See Also:
Constant Field Values

SPEAKERMORTALITY

public static final int SPEAKERMORTALITY
See Also:
Constant Field Values

WORDPARTCOUNT

public static final int WORDPARTCOUNT
See Also:
Constant Field Values

AUTHORNAME

public static final int AUTHORNAME
See Also:
Constant Field Values

AUTHORCONTEMPORARY

public static final int AUTHORCONTEMPORARY
See Also:
Constant Field Values

CORPUSTAG

public static final int CORPUSTAG
See Also:
Constant Field Values

CORPUSTITLE

public static final int CORPUSTITLE
See Also:
Constant Field Values

WORKFULLTITLE

public static final int WORKFULLTITLE
See Also:
Constant Field Values

WORKSHORTTITLE

public static final int WORKSHORTTITLE
See Also:
Constant Field Values

WORKTAG

public static final int WORKTAG
See Also:
Constant Field Values

WORKPARTFULLTITLE

public static final int WORKPARTFULLTITLE
See Also:
Constant Field Values

WORKPARTSHORTTITLE

public static final int WORKPARTSHORTTITLE
See Also:
Constant Field Values

WORKPARTTAG

public static final int WORKPARTTAG
See Also:
Constant Field Values

PUBLICATIONYEAREARLY

public static final int PUBLICATIONYEAREARLY
See Also:
Constant Field Values

PUBLICATIONYEARLATE

public static final int PUBLICATIONYEARLATE
See Also:
Constant Field Values

NARRATIVE

public static final int NARRATIVE
See Also:
Constant Field Values

termText

protected java.lang.String termText
The query term text.


termType

protected int termType
The type of query term.


matchTerm

protected boolean matchTerm
True to match the query text, false to not match it.


isRegExp

protected boolean isRegExp
True if query text is a regular expression.


elementsToNames

protected static final java.util.HashMap elementsToNames
Maps term types to CQL names.


elementsToHQLNames

protected static final java.util.HashMap elementsToHQLNames
Maps term types to HQL names.


namesToElements

protected static final java.util.HashMap namesToElements
Maps CQL names to term types.


allowsOperators

protected static final java.util.HashMap allowsOperators
True if element value can contain operator.


gender_male

protected static java.lang.String gender_male
Object model data values.


gender_female

protected static java.lang.String gender_female

gender_uncertain

protected static java.lang.String gender_uncertain

mortality_mortal

protected static java.lang.String mortality_mortal

mortality_immortal

protected static java.lang.String mortality_immortal

mortality_uncertain

protected static java.lang.String mortality_uncertain

prosodic_prose

protected static java.lang.String prosodic_prose

prosodic_verse

protected static java.lang.String prosodic_verse

prosodic_unknown

protected static java.lang.String prosodic_unknown
Constructor Detail

CQLTerm

public CQLTerm()
Create new term type.


CQLTerm

public CQLTerm(java.lang.String termText,
               int termType,
               boolean matchTerm,
               boolean isRegExp)
Create a new term type.

Parameters:
termText - The query term text.
termType - The query term type.
matchTerm - True to match term, false to not match.
isRegExp - True if term text is regular expression.

CQLTerm

public CQLTerm(CQLQueryTokenizer tokenizer)
        throws InvalidCQLQueryException
Create a new term type from a CQLQueryTokenizer.

Parameters:
tokenizer - The CQLQueryTokenizer. Should be pointing at the start of a CQLTerm definition.
Throws:
InvalidCQLQueryException - if the CQL term syntax is bad.
Method Detail

validateTermText

protected void validateTermText(CQLQueryTokenizer tokenizer)
Fix up query arguments as needed to match database values.

Parameters:
tokenizer - CQLQueryTokenizer.
Throws:
InvalidCQLQueryException - if the CQL term syntax is bad.

getTermTypeName

protected java.lang.String getTermTypeName(int termType)
Get term type name.

Parameters:
termType - The term type.
Returns:
Name of the term type as a string. Empty string if term type unknown.

toString

public java.lang.String toString()
Get string version of query term for display.

Overrides:
toString in class java.lang.Object
Returns:
String version of query term.

toHQL

public java.lang.String toHQL(java.lang.String queryField,
                              int fieldIndex,
                              boolean doingWords)
Get HQL version of query term.

Parameters:
queryField - The name of field to which this query term applies.
fieldIndex - The index of this field in the select clause.
doingWords - true if word results, false for work part results.
Returns:
HQL version of query term for specified field.

hasAuthor

public boolean hasAuthor()
Determine if query term refers to an author.

Returns:
true if a constituent term refers to an author.

hasSpeaker

public boolean hasSpeaker()
Determine if query term refers to a speaker.

Returns:
true if a constituent term refers to a speaker.

hasSpeech

public boolean hasSpeech()
Determine if query term refers to a speech.

Returns:
true if a constituent term refers to a speech.

hasWordPart

public boolean hasWordPart()
Determine if query term refers to a word part.

Returns:
true if a constituent term refers to a word part.

hasWork

public boolean hasWork()
Determine if query term refers to a work.

Returns:
true if a constituent term refers to a work.

hasWorkPart

public boolean hasWorkPart()
Determine if query term refers to a work part.

Returns:
true if a constituent term refers to a work part.

equals

public boolean equals(java.lang.Object other)
Check if this query term is equal to another.

Overrides:
equals in class java.lang.Object
Returns:
True if the query terms are equal, false otherwise.

The query terms are equal when the term text, term type, match term, and is regular expression fields are the same in both query terms.


hashCode

public int hashCode()
Hash code for query term.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.