public void TestReadRatio() { IRatio r = Reader("{\"~#ratio\": [\"~n1\",\"~n2\"]}").Read <IRatio>(); Assert.AreEqual(BigInteger.One, r.Numerator); Assert.AreEqual(BigInteger.One + 1, r.Denominator); Assert.AreEqual(0.5d, r.GetValue(), 0.01d); }
/// <summary> /// Gets an ordered list of the highest scored number of results. /// </summary> /// <param name="query">The query string</param> /// <param name="choices">The list of choices</param> /// <param name="limit">The max number of <see cref="ExtractedResult"/> to return</param> /// <param name="ratio">Optional - The comparison ratio to use</param> /// <returns>An ordered list of <see cref="ExtractedResult"/></returns> public IEnumerable <ExtractedResult> ExtractTop(string query, IEnumerable <string> choices, int limit = int.MaxValue, IRatio ratio = null) { ratio = ValidateRatio(ratio); var extracted = ExtractWithoutOrder(query, choices, ratio); return(extracted.OrderByDescending(x => x.Score).Take(limit)); }
public override object Representation(object obj) { IRatio r = (IRatio)obj; BigInteger[] l = new BigInteger[2]; l[0] = r.Numerator; l[1] = r.Denominator; return(l); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.SecondaryRatio == null)) { IRatio secondaryRatioCasted = item.As <IRatio>(); if ((secondaryRatioCasted != null)) { this._parent.SecondaryRatio = secondaryRatioCasted; return; } } if ((this._parent.NominalRatio == null)) { IRatio nominalRatioCasted = item.As <IRatio>(); if ((nominalRatioCasted != null)) { this._parent.NominalRatio = nominalRatioCasted; return; } } if ((this._parent.PrimaryRatio == null)) { IRatio primaryRatioCasted = item.As <IRatio>(); if ((primaryRatioCasted != null)) { this._parent.PrimaryRatio = primaryRatioCasted; return; } } if ((this._parent.TertiaryRatio == null)) { IRatio tertiaryRatioCasted = item.As <IRatio>(); if ((tertiaryRatioCasted != null)) { this._parent.TertiaryRatio = tertiaryRatioCasted; return; } } }
private static IRatio ValidateRatio(IRatio ratio) { return(ratio ?? new WeightedRatio()); }
/// <summary> /// Find the single best match in a list of choices /// </summary> /// <param name="query">The query string</param> /// <param name="choices">The list of choices</param> /// <param name="ratio">Optional - The comparison ratio to use</param> /// <returns>An <see cref="ExtractedResult"/></returns> public ExtractedResult ExtractBest(string query, IEnumerable <string> choices, IRatio ratio = null) { ratio = ValidateRatio(ratio); var extracted = ExtractWithoutOrder(query, choices, ratio); return(extracted.Aggregate((x, y) => x.Score >= y.Score ? x : y)); }
/// <summary> /// Returns the list of choices with their associated scores of similarity in a list /// </summary> /// <param name="query">The query string</param> /// <param name="choices">The list of choices</param> /// <param name="ratio">Optional - The comparison ratio to use</param> /// <returns>An IEnumerable to Results with a Score and Value</returns> public IEnumerable <ExtractedResult> ExtractWithoutOrder(string query, IEnumerable <string> choices, IRatio ratio = null) { ratio = ValidateRatio(ratio); var results = new List <ExtractedResult>(); foreach (var choice in choices) { var score = ratio.Score(query, choice); if (score >= _cutoff) { results.Add(new ExtractedResult { Score = score, Value = choice }); } } return(results); }
/// <summary> /// Create a new TokenSet Ratio /// </summary> /// <param name="ratio">The Ratio to use when calculating scores</param> public TokenSet(IRatio ratio) { _ratio = ratio; }