Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class SweetSpotSimilarity

    A similarity with a lengthNorm that provides for a "plateau" of equally good lengths, and tf helper functions.

    For lengthNorm, A min/max can be specified to define the plateau of lengths that should all have a norm of 1.0. Below the min, and above the max the lengthNorm drops off in a sqrt function.

    For tf, baselineTf and hyperbolicTf functions are provided, which subclasses can choose between.

    Inheritance
    object
    Similarity
    TFIDFSimilarity
    DefaultSimilarity
    SweetSpotSimilarity
    Inherited Members
    DefaultSimilarity.Coord(int, int)
    DefaultSimilarity.QueryNorm(float)
    DefaultSimilarity.EncodeNormValue(float)
    DefaultSimilarity.DecodeNormValue(long)
    DefaultSimilarity.SloppyFreq(int)
    DefaultSimilarity.ScorePayload(int, int, int, BytesRef)
    DefaultSimilarity.Idf(long, long)
    DefaultSimilarity.m_discountOverlaps
    DefaultSimilarity.DiscountOverlaps
    DefaultSimilarity.ToString()
    TFIDFSimilarity.IdfExplain(CollectionStatistics, TermStatistics)
    TFIDFSimilarity.IdfExplain(CollectionStatistics, TermStatistics[])
    TFIDFSimilarity.ComputeNorm(FieldInvertState)
    TFIDFSimilarity.ComputeWeight(float, CollectionStatistics, params TermStatistics[])
    TFIDFSimilarity.GetSimScorer(Similarity.SimWeight, AtomicReaderContext)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Misc
    Assembly: Lucene.Net.Misc.dll
    Syntax
    public class SweetSpotSimilarity : DefaultSimilarity

    Constructors

    SweetSpotSimilarity()

    A similarity with a lengthNorm that provides for a "plateau" of equally good lengths, and tf helper functions.

    For lengthNorm, A min/max can be specified to define the plateau of lengths that should all have a norm of 1.0. Below the min, and above the max the lengthNorm drops off in a sqrt function.

    For tf, baselineTf and hyperbolicTf functions are provided, which subclasses can choose between.

    Declaration
    public SweetSpotSimilarity()

    Methods

    BaselineTf(float)

    Implemented as:

    (x <= min) ? base : Math.Sqrt(x+(base**2)-min)

    ...but with a special case check for 0.

    This degrates to

    Math.Sqrt(x)
    when min and base are both 0
    Declaration
    public virtual float BaselineTf(float freq)
    Parameters
    Type Name Description
    float freq
    Returns
    Type Description
    float
    See Also
    SetBaselineTfFactors(float, float)

    ComputeLengthNorm(int)

    Implemented as:

    1/sqrt( steepness * (Math.Abs(x-min) + Math.Abs(x-max) - (max-min)) + 1 )
    .

    This degrades to

    1/Math.Sqrt(x)
    when min and max are both 1 and steepness is 0.5

    :TODO: potential optimization is to just flat out return 1.0f if numTerms is between min and max.

    Declaration
    public virtual float ComputeLengthNorm(int numTerms)
    Parameters
    Type Name Description
    int numTerms
    Returns
    Type Description
    float
    See Also
    SetLengthNormFactors(int, int, float, bool)

    HyperbolicTf(float)

    Uses a hyperbolic tangent function that allows for a hard max...

    tf(x)=min+(max-min)/2*(((base**(x-xoffset)-base**-(x-xoffset))/(base**(x-xoffset)+base**-(x-xoffset)))+1)

    This code is provided as a convenience for subclasses that want to use a hyperbolic tf function.

    Declaration
    public virtual float HyperbolicTf(float freq)
    Parameters
    Type Name Description
    float freq
    Returns
    Type Description
    float
    See Also
    SetHyperbolicTfFactors(float, float, double, float)

    LengthNorm(FieldInvertState)

    Implemented as state.Boost * ComputeLengthNorm(numTokens) where numTokens does not count overlap tokens if discountOverlaps is true by default or true for this specific field.

    Declaration
    public override float LengthNorm(FieldInvertState state)
    Parameters
    Type Name Description
    FieldInvertState state
    Returns
    Type Description
    float
    Overrides
    Lucene.Net.Search.Similarities.DefaultSimilarity.LengthNorm(Lucene.Net.Index.FieldInvertState)

    SetBaselineTfFactors(float, float)

    Sets the baseline and minimum function variables for baselineTf

    Declaration
    public virtual void SetBaselineTfFactors(float @base, float min)
    Parameters
    Type Name Description
    float base
    float min
    See Also
    BaselineTf(float)

    SetHyperbolicTfFactors(float, float, double, float)

    Sets the function variables for the hyperbolicTf functions

    Declaration
    public virtual void SetHyperbolicTfFactors(float min, float max, double @base, float xoffset)
    Parameters
    Type Name Description
    float min

    the minimum tf value to ever be returned (default: 0.0)

    float max

    the maximum tf value to ever be returned (default: 2.0)

    double base

    the base value to be used in the exponential for the hyperbolic function (default: 1.3)

    float xoffset

    the midpoint of the hyperbolic function (default: 10.0)

    See Also
    HyperbolicTf(float)

    SetLengthNormFactors(int, int, float, bool)

    Sets the default function variables used by lengthNorm when no field specific variables have been set.

    Declaration
    public virtual void SetLengthNormFactors(int min, int max, float steepness, bool discountOverlaps)
    Parameters
    Type Name Description
    int min
    int max
    float steepness
    bool discountOverlaps
    See Also
    ComputeLengthNorm(int)

    Tf(float)

    Delegates to baselineTf

    Declaration
    public override float Tf(float freq)
    Parameters
    Type Name Description
    float freq
    Returns
    Type Description
    float
    Overrides
    DefaultSimilarity.Tf(float)
    See Also
    BaselineTf(float)
    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.