Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class NGramDistance

    N-Gram version of edit distance based on paper by Grzegorz Kondrak, "N-gram similarity and distance". Proceedings of the Twelfth International Conference on String Processing and Information Retrieval (SPIRE 2005), pp. 115-126, Buenos Aires, Argentina, November 2005. http://www.cs.ualberta.ca/~kondrak/papers/spire05.pdf

    This implementation uses the position-based optimization to compute partial matches of n-gram sub-strings and adds a null-character prefix of size n-1 so that the first character is contained in the same number of n-grams as a middle character. Null-character prefix matches are discounted so that strings with no matching characters will return a distance of 0.

    Inheritance
    object
    NGramDistance
    Implements
    IStringDistance
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Search.Spell
    Assembly: Lucene.Net.Suggest.dll
    Syntax
    public class NGramDistance : IStringDistance

    Constructors

    NGramDistance()

    Creates an N-Gram distance measure using n-grams of size 2.

    Declaration
    public NGramDistance()

    NGramDistance(int)

    Creates an N-Gram distance measure using n-grams of the specified size.

    Declaration
    public NGramDistance(int size)
    Parameters
    Type Name Description
    int size

    The size of the n-gram to be used to compute the string distance.

    Methods

    Equals(object)

    Determines whether the specified object is equal to the current object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The object to compare with the current object.

    Returns
    Type Description
    bool

    true if the specified object is equal to the current object; otherwise, false.

    Overrides
    object.Equals(object)

    GetDistance(string, string)

    Returns a float between 0 and 1 based on how similar the specified strings are to one another.
    Returning a value of 1 means the specified strings are identical and 0 means the string are maximally different.

    Declaration
    public virtual float GetDistance(string source, string target)
    Parameters
    Type Name Description
    string source
    string target
    Returns
    Type Description
    float

    a float between 0 and 1 based on how similar the specified strings are to one another.

    GetHashCode()

    Serves as the default hash function.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hash code for the current object.

    Overrides
    object.GetHashCode()

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()

    Implements

    IStringDistance
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.