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 package org.apache.commons.text.similarity; 18 19 /** 20 * Scores {@link CharSequence} similarity, like a {@link String}. 21 * <p> 22 * A string similarity score is intended to have <em>some</em> of the properties of a metric, yet 23 * allowing for exceptions, like the Jaro-Winkler similarity score. 24 * </p> 25 * <p> 26 * A similarity score is the function {@code d: [X * X] -> [0, INFINITY)} with the 27 * following properties: 28 * </p> 29 * <ul> 30 * <li>{@code d(x,y) >= 0}, non-negativity or separation axiom</li> 31 * <li>{@code d(x,y) == d(y,x)}, symmetry.</li> 32 * </ul> 33 * <p> 34 * Notice, these are two of the properties that contribute to {@code d} being a metric. 35 * </p> 36 * <p> 37 * Further, this intended to be BiFunction<CharSequence, CharSequence, R>. 38 * The {@code apply} method accepts a pair of {@link CharSequence} parameters 39 * and returns an {@code R} type similarity score. 40 * </p> 41 * 42 * @param <R> The type of similarity score unit. 43 * @since 1.0 44 */ 45 public interface SimilarityScore<R> extends ObjectSimilarityScore<CharSequence, R> { 46 47 /** 48 * Compares two CharSequences. 49 * 50 * @param left the "left" or "first" input. 51 * @param right the "right" or "second" input. 52 * @return The similarity score between two CharSequences. 53 */ 54 @Override 55 R apply(CharSequence left, CharSequence right); 56 57 }