gate.creole.annic.lucene
Class QueryParser

java.lang.Object
  extended by gate.creole.annic.lucene.QueryParser

public class QueryParser
extends Object

QueryParser parses the provided ANNIC Query and converts it into the format understood to Lucene.

Author:
niraj

Field Summary
(package private)  boolean areAllTermsTokens
           
private  String baseTokenAnnotationType
          Base token annotation type.
private  String field
          Name of the field that contains the index data.
private  boolean needValidation
          Indicates if we need to valid results returned by lucene.
 int position
           
private  ArrayList queries
          Queries generated as a result of normalizing the submitted query.
 
Constructor Summary
QueryParser()
          Constructor
 
Method Summary
private  Query createPhraseQuery(String query)
          This method will create each normalized query into a Phrase or Term query If the query has only one term to search, it will be returned as a TermQuery otherwise, it will be returned as the PhraseQuery
 ArrayList[] createTerms(String elem)
           
private  int findIndexOf(String element, char ch)
           
 List<String> findTokens(String query)
          Given a query this method returns tokens.
 String getQueryString(int i)
          When user submits an ANNIC query, one or more instances of lucene queries are created and returned.
private  boolean isBaseTokenTerm(Term t)
          Returns true if the provided Term is a based token term.
private  boolean isClosingBrace(char ch, char pre)
           
private  boolean isEscapeSequence(String element, int index)
           
private  boolean isOpeneningBrace(char ch, char pre)
           
static boolean isValidQuery(String query)
          Returns true if the submitted query is valid.
static void main(String[] args)
           
 boolean needValidation()
           
private  String norm(String string)
           
 Query[] parse(String field, String query, String baseTokenAnnotationType, String corpusID, String annotationSetToSearchIn)
          Given a query, this method parses it to convert it into one or more lucene queries.
private  ArrayList splitString(String string, char with, boolean normalize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queries

private ArrayList queries
Queries generated as a result of normalizing the submitted query.


field

private String field
Name of the field that contains the index data.


baseTokenAnnotationType

private String baseTokenAnnotationType
Base token annotation type.


needValidation

private boolean needValidation
Indicates if we need to valid results returned by lucene.


position

public int position

areAllTermsTokens

boolean areAllTermsTokens
Constructor Detail

QueryParser

public QueryParser()
Constructor

Method Detail

main

public static void main(String[] args)

isValidQuery

public static boolean isValidQuery(String query)
Returns true if the submitted query is valid.

Parameters:
query -
Returns:

parse

public Query[] parse(String field,
                     String query,
                     String baseTokenAnnotationType,
                     String corpusID,
                     String annotationSetToSearchIn)
              throws SearchException
Given a query, this method parses it to convert it into one or more lucene queries.

Parameters:
field -
query -
baseTokenAnnotationType -
corpusID -
Returns:
Throws:
SearchException

getQueryString

public String getQueryString(int i)
When user submits an ANNIC query, one or more instances of lucene queries are created and returned. This method returns the string representation of the query at the given index.

Parameters:
i -
Returns:

createPhraseQuery

private Query createPhraseQuery(String query)
                         throws SearchException
This method will create each normalized query into a Phrase or Term query If the query has only one term to search, it will be returned as a TermQuery otherwise, it will be returned as the PhraseQuery

Throws:
SearchException

isBaseTokenTerm

private boolean isBaseTokenTerm(Term t)
Returns true if the provided Term is a based token term. To be a base token term it has to satisify the following terms: 1. If its text is baseTokenAnnotationType and the type is "*" or 2. If its type = "baseTokenAnnotationType.feature"

Parameters:
t -
Returns:

findTokens

public List<String> findTokens(String query)
                        throws SearchException
Given a query this method returns tokens. Here token is an object of string.

Parameters:
query -
Returns:
Throws:
SearchException

isOpeneningBrace

private boolean isOpeneningBrace(char ch,
                                 char pre)

isClosingBrace

private boolean isClosingBrace(char ch,
                               char pre)

isEscapeSequence

private boolean isEscapeSequence(String element,
                                 int index)

splitString

private ArrayList splitString(String string,
                              char with,
                              boolean normalize)

findIndexOf

private int findIndexOf(String element,
                        char ch)

norm

private String norm(String string)

createTerms

public ArrayList[] createTerms(String elem)
                        throws SearchException
Throws:
SearchException

needValidation

public boolean needValidation()