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 */
017package org.apache.commons.text.similarity;
018
019/**
020 * Scores {@link CharSequence} similarity, like a {@link String}.
021 * <p>
022 * A string similarity score is intended to have <em>some</em> of the properties of a metric, yet
023 * allowing for exceptions, like the Jaro-Winkler similarity score.
024 * </p>
025 * <p>
026 * A similarity score is the function {@code d: [X * X] -&gt; [0, INFINITY)} with the
027 * following properties:
028 * </p>
029 * <ul>
030 *     <li>{@code d(x,y) &gt;= 0}, non-negativity or separation axiom</li>
031 *     <li>{@code d(x,y) == d(y,x)}, symmetry.</li>
032 * </ul>
033 * <p>
034 * Notice, these are two of the properties that contribute to {@code d} being a metric.
035 * </p>
036 * <p>
037 * Further, this intended to be BiFunction&lt;CharSequence, CharSequence, R&gt;.
038 * The {@code apply} method accepts a pair of {@link CharSequence} parameters
039 * and returns an {@code R} type similarity score.
040 * </p>
041 *
042 * @param <R> The type of similarity score unit.
043 * @since 1.0
044 */
045public interface SimilarityScore<R> extends ObjectSimilarityScore<CharSequence, R> {
046
047    /**
048     * Compares two CharSequences.
049     *
050     * @param left  the "left" or "first" input.
051     * @param right the "right" or "second" input.
052     * @return The similarity score between two CharSequences.
053     */
054    @Override
055    R apply(CharSequence left, CharSequence right);
056
057}