View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.text.similarity;
19  
20  import java.util.function.BiFunction;
21  
22  /**
23   * Scores the similarity between two {@link Object}s of the same type.
24   *
25   * <p>
26   * A string similarity score is intended to have <em>some</em> of the properties of a metric, yet allowing for exceptions, like the Jaro-Winkler similarity
27   * score.
28   * </p>
29   * <p>
30   * A similarity score is the function {@code d: [X * X] -&gt; [0, INFINITY)} with the following properties:
31   * </p>
32   * <ul>
33   * <li>{@code d(x,y) &gt;= 0}, non-negativity or separation axiom</li>
34   * <li>{@code d(x,y) == d(y,x)}, symmetry.</li>
35   * </ul>
36   *
37   * <p>
38   * Notice, these are two of the properties that contribute to {@code d} being a metric.
39   * </p>
40   *
41   * @param <T> Input type
42   * @param <R> The type of similarity score unit used by this score.
43   * @since 1.13.0
44   */
45  public interface ObjectSimilarityScore<T, R> extends BiFunction<T, T, R> {
46  
47      /**
48       * Compares two Objects.
49       *
50       * @param left  the "left" or "first" input.
51       * @param right the "right" or "second" input.
52       * @return The similarity score between two Objects.
53       */
54      @Override
55      R apply(T left, T right);
56  
57  }