org.crosswire.common.diff

## Class Bitap

- java.lang.Object
- - org.crosswire.common.diff.Bitap

- All Implemented Interfaces:
    Locator

      public class Bitap
      extends Object
      implements Locator

  An implementation of the Bitap algorithm for finding a "fuzzy" location of a match. Based on the LGPL Diff_Match_Patch v1.5 javascript of Neil Fraser, Copyright (C) 2006
  http://neil.fraser.name/software/diff_match_patch/
  Author:
    DM Smith
  See Also:
    `The GNU Lesser General Public License for details.`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private Map<Character,Integer>` | `alphabet` Alphabet is the compiled representation of the pattern.
    `private static float` | `balance`
    `private static float` | `BALANCE` Tweak the relative importance (0.0 = accuracy, 1.0 = proximity)
    `private int` | `loc` The location in text to focus the search.
    `private static int` | `MAXBITS` The maximum number of bits in an int.
    `private static int` | `maxLength`
    `private static int` | `MAXLENGTH`
    `private static int` | `minLength`
    `private static int` | `MINLENGTH` The min and max cutoffs used when computing text lengths.
    `private String` | `pattern` The pattern to find in the text.
    `private int` | `scoreTextLength` The length of the string constrained between MINLENGHT and MAXLENGTH
    `private String` | `text` The text to search.
    `private static float` | `threshold`
    `private static float` | `THRESHOLD` At what point is no match declared (0.0 = perfection, 1.0 = very loose)

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Bitap(String text, String pattern, int loc)` Locate the best instance of 'pattern' in 'text' near 'loc'.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `alphabet()`
    `private double` | `bitapScore(int e, int x)` Compute and return the score for a match with e errors and x location.
    `protected Map<Character,Integer>` | `getAlphabet()`
    `int` | `locate()` Locate the best match of a pattern in text near a supplied location.
    `int` | `maxPatternLength()` The maximum length a pattern can be.
    `static void` | `setBalance(float newBalance)`
    `static void` | `setMaxLength(int newMaxLength)`
    `static void` | `setMinLength(int newMinLength)`
    `static void` | `setThreshold(float newThreshold)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAXBITS

          private static final int MAXBITS

      The maximum number of bits in an int. Change this to 64 if long is used by alphabet.
      See Also:
        Constant Field Values

    - #### BALANCE

          private static final float BALANCE

      Tweak the relative importance (0.0 = accuracy, 1.0 = proximity)
      See Also:
        Constant Field Values

    - #### balance

          private static float balance

    - #### THRESHOLD

          private static final float THRESHOLD

      At what point is no match declared (0.0 = perfection, 1.0 = very loose)
      See Also:
        Constant Field Values

    - #### threshold

          private static float threshold

    - #### MINLENGTH

          private static final int MINLENGTH

      The min and max cutoffs used when computing text lengths.
      See Also:
        Constant Field Values

    - #### minLength

          private static int minLength

    - #### MAXLENGTH

          private static final int MAXLENGTH

      See Also:
        Constant Field Values

    - #### maxLength

          private static int maxLength

    - #### text

          private String text

      The text to search.

    - #### pattern

          private String pattern

      The pattern to find in the text.

    - #### loc

          private int loc

      The location in text to focus the search.

    - #### scoreTextLength

          private int scoreTextLength

      The length of the string constrained between MINLENGHT and MAXLENGTH

    - #### alphabet

          private Map<Character,Integer> alphabet

      Alphabet is the compiled representation of the pattern.

  - ### Constructor Detail

    - #### Bitap

          public Bitap(String text,
               String pattern,
               int loc)

      Locate the best instance of 'pattern' in 'text' near 'loc'.
      Parameters:
        `text` - The text to search
        `pattern` - The pattern to search for
        `loc` - The location to search around

  - ### Method Detail

    - #### maxPatternLength

          public int maxPatternLength()

      Description copied from interface: `Locator`
      The maximum length a pattern can be.
      Specified by:
        `maxPatternLength` in interface `Locator`
      Returns:
        maximum pattern length.

    - #### locate

          public int locate()

      Description copied from interface: `Locator`
      Locate the best match of a pattern in text near a supplied location.
      Specified by:
        `locate` in interface `Locator`
      Returns:
        Best match index or -1, if no match found

    - #### getAlphabet

          protected Map<Character,Integer> getAlphabet()

    - #### bitapScore

          private double bitapScore(int e,
                          int x)

      Compute and return the score for a match with e errors and x location.
      Parameters:
        `e` - Number of errors in match
        `x` - Location of match
      Returns:
        Overall score for match

    - #### alphabet

          protected void alphabet()

    - #### setBalance

          public static void setBalance(float newBalance)

    - #### setThreshold

          public static void setThreshold(float newThreshold)

    - #### setMinLength

          public static void setMinLength(int newMinLength)

    - #### setMaxLength

          public static void setMaxLength(int newMaxLength)