001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.text.similarity;
019
020import java.util.function.BiFunction;
021
022/**
023 * Scores the similarity between two {@link Object}s of the same type.
024 *
025 * <p>
026 * 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
027 * score.
028 * </p>
029 * <p>
030 * A similarity score is the function {@code d: [X * X] -&gt; [0, INFINITY)} with the following properties:
031 * </p>
032 * <ul>
033 * <li>{@code d(x,y) &gt;= 0}, non-negativity or separation axiom</li>
034 * <li>{@code d(x,y) == d(y,x)}, symmetry.</li>
035 * </ul>
036 *
037 * <p>
038 * Notice, these are two of the properties that contribute to {@code d} being a metric.
039 * </p>
040 *
041 * @param <T> Input type
042 * @param <R> The type of similarity score unit used by this score.
043 * @since 1.13.0
044 */
045public interface ObjectSimilarityScore<T, R> extends BiFunction<T, T, R> {
046
047    /**
048     * Compares two Objects.
049     *
050     * @param left  the "left" or "first" input.
051     * @param right the "right" or "second" input.
052     * @return The similarity score between two Objects.
053     */
054    @Override
055    R apply(T left, T right);
056
057}