Package org.apache.commons.text.similarity

## Class FuzzyScore

- java.lang.Object
- - org.apache.commons.text.similarity.FuzzyScore

-     public class FuzzyScore
      extends Object

  A matching algorithm that is similar to the searching algorithms implemented in editors such as Sublime Text, TextMate, Atom and others.

  One point is given for every matched character. Subsequent matches yield two bonus points. A higher score indicates a higher similarity.

  This code has been adapted from Apache Commons Lang 3.3.

  Since:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FuzzyScore​(Locale locale)` | This returns a `Locale`-specific `FuzzyScore`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Integer` | `fuzzyScore​(CharSequence term, CharSequence query)` | Find the Fuzzy Score which indicates the similarity score between two Strings.
    `Locale` | `getLocale()` | Gets the locale.

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

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

- - ### Constructor Detail

    - #### FuzzyScore

          public FuzzyScore​(Locale locale)

      This returns a `Locale`-specific `FuzzyScore`.

      Parameters:
        `locale` - The string matching logic is case insensitive. A `Locale` is necessary to normalize both Strings to lower case.
      Throws:
        `IllegalArgumentException` - This is thrown if the `Locale` parameter is `null`.

  - ### Method Detail

    - #### fuzzyScore

          public Integer fuzzyScore​(CharSequence term,
                                    CharSequence query)

      Find the Fuzzy Score which indicates the similarity score between two Strings.

           score.fuzzyScore(null, null, null)                                    = IllegalArgumentException
           score.fuzzyScore("", "", Locale.ENGLISH)                              = 0
           score.fuzzyScore("Workshop", "b", Locale.ENGLISH)                     = 0
           score.fuzzyScore("Room", "o", Locale.ENGLISH)                         = 1
           score.fuzzyScore("Workshop", "w", Locale.ENGLISH)                     = 1
           score.fuzzyScore("Workshop", "ws", Locale.ENGLISH)                    = 2
           score.fuzzyScore("Workshop", "wo", Locale.ENGLISH)                    = 4
           score.fuzzyScore("Apache Software Foundation", "asf", Locale.ENGLISH) = 3

      Parameters:
        `term` - a full term that should be matched against, must not be null
        `query` - the query that will be matched against a term, must not be null
      Returns:
        result score
      Throws:
        `IllegalArgumentException` - if either CharSequence input is `null`

    - #### getLocale

          public Locale getLocale()

      Gets the locale.
      Returns:
        the locale

Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.