gov.nih.nlm.nls.gspell
Class NGrams

java.lang.Object
  extended bygov.nih.nlm.nls.gspell.NGrams

final class NGrams
extends java.lang.Object

NGrams is a spelling suggestion api that suggests nearest neighbor candidates to an incoming term.


Field Summary
static int LEFT_MOST
           
static int NGRAMS
           
static int RIGHT_MOST
           
 
Constructor Summary
  NGrams(GlobalBehavior pSettings)
          This is a constructor for NGrams
(package private) NGrams(Options pOptions)
          Deprecated.  
  NGrams(java.lang.String[] args)
          This is a constructor for NGrams
 
Method Summary
 GlobalBehavior cleanup()
          Method cleanup closes up open files, writes to data stores.
 void close()
          Method close closes the open db's
(package private)  void export()
          Method export prints out the contents of the store to stdout
 int find(java.io.BufferedReader pFStream, java.io.PrintWriter pPrintStream)
          Method find retreives closest neibhors of the terms coming in from the BufferedReader.
(package private)  Candidate[] find(FindOptions pFindOptions, int pLookupType, java.lang.String pTerm)
          Method find retrieves the closest candidates to the input term using either the ngram or leftmost or rightmost matching grams
 Candidate[] find(FindOptions pFindOptions, java.lang.String pTerm)
          Method find retrieves the closest candidates to the input term
 Candidate[] find(java.lang.String pTerm)
          Method find retrieves the closest candidates to the input term
 int findLeftMost(java.io.BufferedReader pFStream, java.io.PrintWriter pPrintStream)
          Method findLeftMost retreives everything that starts with the leftmost part of terms coming in from the BufferedReader.
 Candidate[] findLeftMost(FindOptions pFindOptions, java.lang.String pTerm)
          Method findLeftMost retrieves candidates that match the leftmost part of the input term
 Candidate[] findLeftMost(java.lang.String pTerm)
          Method findLeftMost retrieves the strings that match the left most part of the input term
 int findRightMost(java.io.BufferedReader pFStream, java.io.PrintWriter pPrintStream)
          Method findRightMost retreives everything that starts with the rightmost part of terms coming in from the BufferedReader.
 Candidate[] findRightMost(FindOptions pFindOptions, java.lang.String pTerm)
          Method findRightMost retrieves candidates that match the rightmost part of the input term
 Candidate[] findRigtMost(java.lang.String pTerm)
          Method findRigtMost retrieves the strings that match the right most part of the input term
(package private)  void flush()
          Method flush writes to the data stores.
 void freeCandidates()
          freeCandidates returns the candidates in the candidatePool to the free list
(package private)  int index(java.io.BufferedReader fStream)
          Method index indexes the contents of what somes in from this inputStream This can be a fileStream, or standardinput.
(package private)  void index(java.lang.String pTerm)
          Method index indexes this term
static void main(java.lang.String[] args)
          This is a test main, whose purpose is to test the functionality of each method developed for this class.
static int run(java.lang.String[] args)
          Method run
 void save()
           
(package private)  int update(java.io.BufferedReader pFStream)
          Method update updates the indexes with terms from the file into the dictionary
(package private)  void update(java.lang.String pTerm)
          Method update adds this term to the dictionary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NGRAMS

public static final int NGRAMS
See Also:
Constant Field Values

LEFT_MOST

public static final int LEFT_MOST
See Also:
Constant Field Values

RIGHT_MOST

public static final int RIGHT_MOST
See Also:
Constant Field Values
Constructor Detail

NGrams

public NGrams(GlobalBehavior pSettings)
       throws java.lang.Exception
This is a constructor for NGrams


NGrams

public NGrams(java.lang.String[] args)
       throws java.lang.Exception
This is a constructor for NGrams

Parameters:
args -

NGrams

NGrams(Options pOptions)
 throws java.lang.Exception
Deprecated.  

This is a constructor for NGrams

Parameters:
pOptions - Options that incudes dictionaryName, truncation, max candidates ...
Method Detail

index

int index(java.io.BufferedReader fStream)
    throws java.lang.Exception
Method index indexes the contents of what somes in from this inputStream This can be a fileStream, or standardinput. Rows that start with # are ignored.

Parameters:
fStream -
Returns:
int the number of terms indexed
Throws:
java.lang.Exception

index

void index(java.lang.String pTerm)
     throws java.lang.Exception
Method index indexes this term

Parameters:
pTerm - The word/Term to be indexed.
Throws:
java.lang.Exception

update

int update(java.io.BufferedReader pFStream)
     throws java.lang.Exception
Method update updates the indexes with terms from the file into the dictionary

Parameters:
pFStream -
Returns:
int the number of terms updated
Throws:
java.lang.Exception

update

void update(java.lang.String pTerm)
      throws java.lang.Exception
Method update adds this term to the dictionary

Parameters:
pTerm -
Throws:
java.lang.Exception

find

public int find(java.io.BufferedReader pFStream,
                java.io.PrintWriter pPrintStream)
         throws java.lang.Exception
Method find retreives closest neibhors of the terms coming in from the BufferedReader. This method writes to the output the following: inputTerm|candidate|rank|FromMethod|Messages if there are candidates Otherwise, this method writes the following: inputTerm||-9999||No Suggestions Where messages could include "Correct" if the rank = 0; or "No Suggestions" there are no close suggestions.

Parameters:
pFStream -
pPrintStream -
Returns:
int the number of terms looked up
Throws:
java.lang.Exception

findLeftMost

public int findLeftMost(java.io.BufferedReader pFStream,
                        java.io.PrintWriter pPrintStream)
                 throws java.lang.Exception
Method findLeftMost retreives everything that starts with the leftmost part of terms coming in from the BufferedReader. This method writes to the output the following: inputTerm|candidate|rank|FromMethod|Messages if there are candidates Otherwise, this method writes the following: inputTerm||-9999||No Suggestions Where messages could include "Correct" if the rank = 0; or "No Suggestions" there are no close suggestions.

Parameters:
pFStream -
pPrintStream -
Returns:
int the number of terms looked up
Throws:
java.lang.Exception

findRightMost

public int findRightMost(java.io.BufferedReader pFStream,
                         java.io.PrintWriter pPrintStream)
                  throws java.lang.Exception
Method findRightMost retreives everything that starts with the rightmost part of terms coming in from the BufferedReader. This method writes to the output the following: inputTerm|candidate|rank|FromMethod|Messages if there are candidates Otherwise, this method writes the following: inputTerm||-9999||No Suggestions Where messages could include "Correct" if the rank = 0; or "No Suggestions" there are no close suggestions.

Parameters:
pFStream -
pPrintStream -
Returns:
int the number of terms looked up
Throws:
java.lang.Exception

find

public Candidate[] find(java.lang.String pTerm)
                 throws java.lang.Exception
Method find retrieves the closest candidates to the input term

Parameters:
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

findLeftMost

public Candidate[] findLeftMost(java.lang.String pTerm)
                         throws java.lang.Exception
Method findLeftMost retrieves the strings that match the left most part of the input term

Parameters:
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

findRigtMost

public Candidate[] findRigtMost(java.lang.String pTerm)
                         throws java.lang.Exception
Method findRigtMost retrieves the strings that match the right most part of the input term

Parameters:
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

find

public Candidate[] find(FindOptions pFindOptions,
                        java.lang.String pTerm)
                 throws java.lang.Exception
Method find retrieves the closest candidates to the input term

Parameters:
pFindOptions -
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

findLeftMost

public Candidate[] findLeftMost(FindOptions pFindOptions,
                                java.lang.String pTerm)
                         throws java.lang.Exception
Method findLeftMost retrieves candidates that match the leftmost part of the input term

Parameters:
pFindOptions -
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

findRightMost

public Candidate[] findRightMost(FindOptions pFindOptions,
                                 java.lang.String pTerm)
                          throws java.lang.Exception
Method findRightMost retrieves candidates that match the rightmost part of the input term

Parameters:
pFindOptions -
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

find

Candidate[] find(FindOptions pFindOptions,
                 int pLookupType,
                 java.lang.String pTerm)
           throws java.lang.Exception
Method find retrieves the closest candidates to the input term using either the ngram or leftmost or rightmost matching grams

Parameters:
pFindOptions -
pLookupType - NGRAMS|LEFT_MOST|RIGHT_MOST
pTerm -
Returns:
Candidate[]
Throws:
java.lang.Exception

cleanup

public GlobalBehavior cleanup()
                       throws java.lang.Exception
Method cleanup closes up open files, writes to data stores.

Throws:
java.lang.Exception

freeCandidates

public void freeCandidates()
freeCandidates returns the candidates in the candidatePool to the free list


close

public void close()
           throws java.lang.Exception
Method close closes the open db's

Throws:
java.lang.Exception

flush

void flush()
     throws java.lang.Exception
Method flush writes to the data stores.

Throws:
java.lang.Exception

export

void export()
      throws java.lang.Exception
Method export prints out the contents of the store to stdout

Throws:
java.lang.Exception

run

public static int run(java.lang.String[] args)
Method run

Parameters:
args -
Returns:
int

save

public void save()
          throws java.lang.Exception
Throws:
java.lang.Exception

main

public static final void main(java.lang.String[] args)
This is a test main, whose purpose is to test the functionality of each method developed for this class. This main strives to test the boundary conditions as well as some sample common ways each method is intended to be used.

Parameters:
args - The command line input, tokenized


The use and distribution of this material is subject to the terms and conditions included in the file SPECIALIST_NLP_TOOLS_TERMS_AND_CONDITIONS.TXT, located in the root directory of the distribution.