com.aliasi.spell.JaccardDistance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliasi-lingpipe Show documentation
Show all versions of aliasi-lingpipe Show documentation
This is the original Lingpipe:
http://alias-i.com/lingpipe/web/download.html
There were not made any changes to the source code.
/*
* LingPipe v. 4.1.0
* Copyright (C) 2003-2011 Alias-i
*
* This program is licensed under the Alias-i Royalty Free License
* Version 1 WITHOUT ANY WARRANTY, without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Alias-i
* Royalty Free License Version 1 for more details.
*
* You should have received a copy of the Alias-i Royalty Free License
* Version 1 along with this program; if not, visit
* http://alias-i.com/lingpipe/licenses/lingpipe-license-1.txt or contact
* Alias-i, Inc. at 181 North 11th Street, Suite 401, Brooklyn, NY 11211,
* +1 (718) 290-9170.
*/
package com.aliasi.spell;
import com.aliasi.tokenizer.TokenizerFactory;
import java.util.Set;
/**
* The JaccardDistance
class implements a notion of
* distance based on token overlap. The tokens are generated
* from the character sequences being compared by a tokenizer
* factory that is supplied at construction time. A distance of
* zero (0
) is a perfect match, a distance of
* one (1
0 a perfect mismatch.
*
* Suppose termSet(cs)
is the set of tokens extracted from
* the character sequence cs
. With these terms,
* the proximity underlying Jaccard distance is defined
* as the percentage of tokens that appear in both
* character sequences:
*
*
* proximity(cs1,cs2)
* = size(termSet(cs1) INTERSECT termSet(cs2))
* / size(termSet(cs1) UNION termSet(cs2))
*
*
* Proximities run between 0 and 1. A proximity of 0 means the
* character sequences share no terms in common and a proximity of 1
* means the character sequences share all of their terms.
*
* Distance is then defined in terms of proximity by subtraction. * *
* * Distances also run between 0 and 1. A distance of 0 means the * character sequences share all of their terms, whereas a distance of * 1 means they have no terms in common. * * @author Bob Carpenter * @version 3.8 * @since LingPipe2.4 */ public class JaccardDistance extends TokenizedDistance { /** * Construct an instance of Jaccard string distance using * the specified tokenizer factory. * * @param factory Tokenizer factory for distance. */ public JaccardDistance(TokenizerFactory factory) { super(factory); } /** * Returns the Jaccard distance between the specified character * sequence. See the class definition above for a definition. * * @param cSeq1 First character sequence. * @param cSeq2 Second character sequence. * @return Jaccard distance between the sequences. */ public double distance(CharSequence cSeq1, CharSequence cSeq2) { return 1.0 - proximity(cSeq1,cSeq2); } /** * Returns the proximity between the specified character * sequences. * * @param cSeq1 First character sequence. * @param cSeq2 Second character sequence. * @return Jaccard proximity between the sequences. */ public double proximity(CharSequence cSeq1, CharSequence cSeq2) { Set* distance(cs1,cs2) = 1 - proximity(cs1,cs2) *
© 2015 - 2025 Weber Informatics LLC | Privacy Policy