org.jscience.linguistics.search
Class MismatchSearch

java.lang.Object
  extended by org.jscience.linguistics.search.StringSearch
      extended by org.jscience.linguistics.search.MismatchSearch
Direct Known Subclasses:
ShiftOrMismatches

public abstract class MismatchSearch
extends StringSearch

Subclasses of MismatchSearch allow for searching with a fixed number of possible errors. Subclasses of this class return a int array with the first int being the position at which the hit occurred and the second int being the number of mismatches at the position.

Example:

 int[] positions = new ShiftOrMismatches().searchString("this is null",
 "nall", 1);
positions[0] would be 8, positions[1] (the number of mismatches) would be 1.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.jscience.linguistics.search.StringSearch
StringSearch.Dispatch, StringSearch.ReflectionDispatch
 
Field Summary
 
Fields inherited from class org.jscience.linguistics.search.StringSearch
activeDispatch, useNative
 
Constructor Summary
protected MismatchSearch()
          Constructor for MismatchSearch.
 
Method Summary
 java.lang.Object processBytes(byte[] pattern)
          Pre-process the pattern, allowing zero errors.
abstract  java.lang.Object processBytes(byte[] pattern, int k)
          Pre-processes the pattern, allowing k errors.
 java.lang.Object processChars(char[] pattern)
          Pre-processes the pattern, allowing zero errors.
abstract  java.lang.Object processChars(char[] pattern, int k)
          Pre-processes a char array, allowing k errors.
 java.lang.Object processString(java.lang.String pattern, int k)
          Pre-processes a String, allowing k errors.
 int[] searchBytes(byte[] text, byte[] pattern, int k)
          Returns the position in the text at which the pattern was found.
 int[] searchBytes(byte[] text, byte[] pattern, java.lang.Object processed, int k)
          Returns the position in the text at which the pattern was found.
 int[] searchBytes(byte[] text, int textEnd, byte[] pattern, int k)
          Returns the position in the text at which the pattern was found.
 int[] searchBytes(byte[] text, int textEnd, byte[] pattern, java.lang.Object processed, int k)
          Returns the position in the text at which the pattern was found.
 int[] searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern, int k)
          Returns the position in the text at which the pattern was found.
 int searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern, java.lang.Object processed)
          DOCUMENT ME!
abstract  int[] searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern, java.lang.Object processed, int k)
          Returns the position in the text at which the pattern was found.
 int[] searchChars(char[] text, char[] pattern, int k)
          Finder for the given pattern in the text, allowing k errors.
 int[] searchChars(char[] text, char[] pattern, java.lang.Object processed, int k)
          Finder for the given pattern in the text, allowing k errors.
 int[] searchChars(char[] text, int textStart, char[] pattern, int k)
          Finder for the given pattern in the text, starting at textStart, allowing k errors.
 int[] searchChars(char[] text, int textStart, char[] pattern, java.lang.Object processed, int k)
          Finder for the given pattern in the text, starting at textStart, allowing k errors.
 int[] searchChars(char[] text, int textStart, int textEnd, char[] pattern, int k)
          Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing k errors.
 int searchChars(char[] text, int textStart, int textEnd, char[] pattern, java.lang.Object processed)
          Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing zero errors.
abstract  int[] searchChars(char[] text, int textStart, int textEnd, char[] pattern, java.lang.Object processed, int k)
          Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing k errors.
 int[] searchString(java.lang.String text, int textStart, int textEnd, java.lang.String pattern, int k)
          Convenience method to search for patterns in Strings.
 int[] searchString(java.lang.String text, int textStart, int textEnd, java.lang.String pattern, java.lang.Object processed, int k)
          Convenience method to search for patterns in Strings.
 int[] searchString(java.lang.String text, int textStart, java.lang.String pattern, int k)
          Convenience method to search for patterns in Strings.
 int[] searchString(java.lang.String text, int textStart, java.lang.String pattern, java.lang.Object processed, int k)
          Convenience method to search for patterns in Strings.
 int[] searchString(java.lang.String text, java.lang.String pattern, int k)
          Convenience method to search for patterns in Strings.
 int[] searchString(java.lang.String text, java.lang.String pattern, java.lang.Object processed, int k)
          Convenience method to search for patterns in Strings.
 
Methods inherited from class org.jscience.linguistics.search.StringSearch
createCharIntMap, createCharIntMap, equals, hashCode, index, processString, searchBytes, searchBytes, searchBytes, searchBytes, searchBytes, searchChars, searchChars, searchChars, searchChars, searchChars, searchString, searchString, searchString, searchString, searchString, searchString, toString, toStringBuffer, usesNative, usesReflection
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MismatchSearch

protected MismatchSearch()
Constructor for MismatchSearch. Note that it is not required to create multiple instances.

Method Detail

processBytes

public final java.lang.Object processBytes(byte[] pattern)
Pre-process the pattern, allowing zero errors.

Identical to process(pattern, 0)

Specified by:
processBytes in class StringSearch
Parameters:
pattern - the byte array containing the pattern, may not be null
Returns:
DOCUMENT ME!
See Also:
StringSearch.processBytes(byte[]), processBytes(byte[],int)

processBytes

public abstract java.lang.Object processBytes(byte[] pattern,
                                              int k)
Pre-processes the pattern, allowing k errors.

Parameters:
pattern - the byte array containing the pattern, may not be null
k - the editing distance
Returns:
an Object

processChars

public final java.lang.Object processChars(char[] pattern)
Pre-processes the pattern, allowing zero errors.

Identical to process(pattern, 0).

Specified by:
processChars in class StringSearch
Parameters:
pattern - a char array containing the pattern, may not be null
Returns:
an Object
See Also:
processChars(char[],int), StringSearch.processChars(char[])

processChars

public abstract java.lang.Object processChars(char[] pattern,
                                              int k)
Pre-processes a char array, allowing k errors.

Parameters:
pattern - a char array containing the pattern, may not be null
k - the editing distance
Returns:
an Object

processString

public final java.lang.Object processString(java.lang.String pattern,
                                            int k)
Pre-processes a String, allowing k errors. This method should not be used directly because it is implicitly called in the StringSearch.searchString(String,String) methods.

Parameters:
pattern - the String containing the pattern, may not be null
k - the editing distance
Returns:
an Object

searchBytes

public final int searchBytes(byte[] text,
                             int textStart,
                             int textEnd,
                             byte[] pattern,
                             java.lang.Object processed)
DOCUMENT ME!

Specified by:
searchBytes in class StringSearch
Parameters:
text - DOCUMENT ME!
textStart - DOCUMENT ME!
textEnd - DOCUMENT ME!
pattern - DOCUMENT ME!
processed - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
StringSearch.searchBytes(byte[], int,int,byte[],Object), searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public final int[] searchBytes(byte[] text,
                               byte[] pattern,
                               int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the byte array containing the text, may not be null
pattern - the byte array containing the pattern, may not be null
k - the editing distance
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public final int[] searchBytes(byte[] text,
                               byte[] pattern,
                               java.lang.Object processed,
                               int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the byte array containing the text, may not be null
pattern - the byte array containing the pattern, may not be null
processed - an Object as returned from processBytes(byte[], int), may not be null
k - the editing distance
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public final int[] searchBytes(byte[] text,
                               int textEnd,
                               byte[] pattern,
                               int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the byte array containing the text, may not be null
textEnd - at which position in the text the comparing should start
pattern - the byte array containing the pattern, may not be null
k - the editing distance
Returns:
int the position in the text or -1 if the pattern was not found
See Also:
searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public final int[] searchBytes(byte[] text,
                               int textEnd,
                               byte[] pattern,
                               java.lang.Object processed,
                               int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the byte array containing the text, may not be null
textEnd - at which position in the text the comparing should start
pattern - the pattern to search for, may not be null
processed -
k - the editing distance
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public final int[] searchBytes(byte[] text,
                               int textStart,
                               int textEnd,
                               byte[] pattern,
                               int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - text the byte array containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the byte array containing the pattern, may not be null
k - the editing distance
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchBytes(byte[],int,int,byte[],Object,int)

searchBytes

public abstract int[] searchBytes(byte[] text,
                                  int textStart,
                                  int textEnd,
                                  byte[] pattern,
                                  java.lang.Object processed,
                                  int k)
Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - text the byte array containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the pattern to search for, may not be null
processed - an Object as returned from processBytes(byte[], int), may not be null
k - the editing distance
Returns:
the position in the text or -1 if the pattern was not found
See Also:
processBytes(byte[],int)

searchChars

public final int searchChars(char[] text,
                             int textStart,
                             int textEnd,
                             char[] pattern,
                             java.lang.Object processed)
Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing zero errors.

Specified by:
searchChars in class StringSearch
Parameters:
text - DOCUMENT ME!
textStart - DOCUMENT ME!
textEnd - DOCUMENT ME!
pattern - DOCUMENT ME!
processed - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
StringSearch.searchChars(char[],int,int,char[],Object), processChars(char[],int)

searchChars

public final int[] searchChars(char[] text,
                               char[] pattern,
                               int k)
Finder for the given pattern in the text, allowing k errors.

Parameters:
text - the String containing the text, may not be null
pattern - the pattern to search for, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)

searchChars

public final int[] searchChars(char[] text,
                               char[] pattern,
                               java.lang.Object processed,
                               int k)
Finder for the given pattern in the text, allowing k errors.

Parameters:
text - the String containing the text, may not be null
pattern - the pattern to search for, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)

searchChars

public final int[] searchChars(char[] text,
                               int textStart,
                               char[] pattern,
                               int k)
Finder for the given pattern in the text, starting at textStart, allowing k errors.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
pattern - the pattern to search for, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object)

searchChars

public final int[] searchChars(char[] text,
                               int textStart,
                               char[] pattern,
                               java.lang.Object processed,
                               int k)
Finder for the given pattern in the text, starting at textStart, allowing k errors.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
pattern - the pattern to search for, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)

searchChars

public final int[] searchChars(char[] text,
                               int textStart,
                               int textEnd,
                               char[] pattern,
                               int k)
Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing k errors.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the pattern to search for, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found

searchChars

public abstract int[] searchChars(char[] text,
                                  int textStart,
                                  int textEnd,
                                  char[] pattern,
                                  java.lang.Object processed,
                                  int k)
Finder for the given pattern in the text, starting at textStart and comparing to at most textEnd, allowing k errors.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the pattern to search for, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found

searchString

public final int[] searchString(java.lang.String text,
                                java.lang.String pattern,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
pattern - the String containing the pattern, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],int)

searchString

public final int[] searchString(java.lang.String text,
                                java.lang.String pattern,
                                java.lang.Object processed,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
pattern - the String containing the pattern, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)

searchString

public final int[] searchString(java.lang.String text,
                                int textStart,
                                java.lang.String pattern,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
pattern - the String containing the pattern, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],int)

searchString

public final int[] searchString(java.lang.String text,
                                int textStart,
                                java.lang.String pattern,
                                java.lang.Object processed,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
pattern - the String containing the pattern, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)

searchString

public final int[] searchString(java.lang.String text,
                                int textStart,
                                int textEnd,
                                java.lang.String pattern,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the String containing the pattern, may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],int)

searchString

public final int[] searchString(java.lang.String text,
                                int textStart,
                                int textEnd,
                                java.lang.String pattern,
                                java.lang.Object processed,
                                int k)
Convenience method to search for patterns in Strings. Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.

Parameters:
text - the String containing the text, may not be null
textStart - at which position in the text the comparing should start
textEnd - at which position in the text comparing should stop
pattern - the String containing the pattern, may not be null
processed - an Object as returned from processChars(char[], int) or processString(String,int), may not be null
k - the maximum number of mismatches (the editing distance)
Returns:
the position in the text or -1 if the pattern was not found
See Also:
searchChars(char[],int,int,char[],Object,int)