Top Description Fields Constructors Methods
info.debatty.java.stringsimilarity

public Class NGram

extends Object
implements NormalizedStringDistance
Class Inheritance
All Implemented Interfaces
info.debatty.java.stringsimilarity.interfaces.NormalizedStringDistance, info.debatty.java.stringsimilarity.interfaces.StringDistance, java.io.Serializable
Annotations
@Immutable
Imports
info.debatty.java.stringsimilarity.interfaces.NormalizedStringDistance, net.jcip.annotations.Immutable

N-Gram Similarity as defined by Kondrak, "N-Gram Similarity and Distance", String Processing and Information Retrieval, Lecture Notes in Computer Science Volume 3772, 2005, pp 115-126. The algorithm uses affixing with special character '\n' to increase the weight of first characters. The normalization is achieved by dividing the total similarity score the original length of the longest word. http://webdocs.cs.ualberta.ca/~kondrak/papers/spire05.pdf

Field Summary

Modifier and TypeField and Description
private static final int
private final int
n

Constructor Summary

AccessConstructor and Description
public
NGram(final int n)

Instantiate with given value for n-gram length.

public
NGram()

Instantiate with default value for n-gram length (2).

Method Summary

Modifier and TypeMethod and Description
public final double

Returns:

The computed n-gram distance in the range [0, 1]
distance
(final String
The first string to compare.
s0
,
final String
The second string to compare.
s1
)

Implements info.debatty.java.stringsimilarity.interfaces.StringDistance.distance.

Compute n-gram distance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_Nback to summary
private static final int DEFAULT_N
nback to summary
private final int n

Constructor Detail

NGramback to summary
public NGram(final int n)

Instantiate with given value for n-gram length.

NGramback to summary
public NGram()

Instantiate with default value for n-gram length (2).

Method Detail

distanceback to summary
public final double distance(final String s0, final String s1)

Implements info.debatty.java.stringsimilarity.interfaces.StringDistance.distance.

Compute n-gram distance.

Parameters
s0:String

The first string to compare.

s1:String

The second string to compare.

Returns:double

The computed n-gram distance in the range [0, 1]

Exceptions
NullPointerException:
if s0 or s1 is null.