# Class SimilarityScoreFrom<R>

java.lang.Object
org.apache.commons.text.similarity.SimilarityScoreFrom<R>

Type Parameters:
  `R` - This is the type of similarity score used by the SimilarityScore function.

public class SimilarityScoreFrom<R> extends Object
Stores a `SimilarityScore` implementation and a `CharSequence` "left" string. The `apply(CharSequence right)` method accepts the "right" string and invokes the comparison function for the pair of strings.

The following is an example which finds the most similar string:

    SimilarityScore<Integer> similarityScore = new LevenshteinDistance();
    String target = "Apache";
    SimilarityScoreFrom<Integer> similarityScoreFrom =
        new SimilarityScoreFrom<Integer>(similarityScore, target);
    String mostSimilar = null;
    Integer shortestDistance = null;

    for (String test : new String[] { "Appaloosa", "a patchy", "apple" }) {
        Integer distance = similarityScoreFrom.apply(test);
        if (shortestDistance == null || distance < shortestDistance) {
            shortestDistance = distance;
            mostSimilar = test;
        }
    }

    System.out.println("The string most similar to \"" + target + "\" "
        + "is \"" + mostSimilar + "\" because "
        + "its distance is only " + shortestDistance + ".");

Since:
  1.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SimilarityScoreFrom(SimilarityScore<R> similarityScore, CharSequence left)`
  Constructs a new instance for a similarity score implementation and the "left" string.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `R`
  `apply(CharSequence right)`
  Compares "left" field against the "right" parameter using the "similarity score" implementation.
  `CharSequence`
  `getLeft()`
  Gets the left parameter.
  `SimilarityScore<R>`
  `getSimilarityScore()`
  Gets the edit distance.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### SimilarityScoreFrom

    public SimilarityScoreFrom(SimilarityScore<R> similarityScore, CharSequence left)
    Constructs a new instance for a similarity score implementation and the "left" string.
    Parameters:
      `similarityScore` - This may not be null.
      `left` - This may be null here, but the SimilarityScore#compare(CharSequence left, CharSequence right) implementation may not accept nulls.

- ## Method Details

  - ### apply

    public R apply(CharSequence right)
    Compares "left" field against the "right" parameter using the "similarity score" implementation.
    Parameters:
      `right` - the second CharSequence.
    Returns:
      The similarity score between two CharSequences.

  - ### getLeft

    public CharSequence getLeft()
    Gets the left parameter.
    Returns:
      The left parameter.

  - ### getSimilarityScore

    public SimilarityScore<R> getSimilarityScore()
    Gets the edit distance.
    Returns:
      The edit distance.