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 * Interface for <a href="https://en.wikipedia.org/wiki/Edit_distance">Edit Distances</a>.
021 *
022 * <p>
023 * An edit distance is a formal metric on the Kleene closure ({@code X<sup>*</sup>}) over an
024 * alphabet ({@code X}). Note, that a <a href="https://en.wikipedia.org/wiki/Metric_(mathematics)">metric</a>
025 * on a set {@code S} is a function {@code d: [S * S] -&gt; [0, INFINITY)} such
026 * that the following hold for {@code x,y,z} in
027 * the set {@code S}:
028 * </p>
029 * <ul>
030 *     <li>{@code d(x,y) &gt;= 0}, non-negativity or separation axiom</li>
031 *     <li>{@code d(x,y) == 0}, if and only if, {@code x == y}</li>
032 *     <li>{@code d(x,y) == d(y,x)}, symmetry, and</li>
033 *     <li>{@code d(x,z) &lt;=  d(x,y) + d(y,z)}, the triangle inequality</li>
034 * </ul>
035 *
036 *
037 * <p>
038 * This is a BiFunction&lt;CharSequence, CharSequence, R&gt;.
039 * The {@code apply} method
040 * accepts a pair of {@link CharSequence} parameters
041 * and returns an {@code R} type similarity score.
042 * </p>
043 *
044 * @param <R> The type of similarity score unit used by this EditDistance.
045 * @since 1.0
046 */
047public interface EditDistance<R> extends SimilarityScore<R> {
048
049    /**
050     * Compares two CharSequences.
051     *
052     * @param left the first CharSequence
053     * @param right the second CharSequence
054     * @return The similarity score between two CharSequences
055     */
056    @Override
057    R apply(CharSequence left, CharSequence right);
058
059}