New: Try matching with "Unabridged" removed from title

pull/1237/head
ta264 3 years ago
parent 6325432a34
commit bdcee8c7c1

@ -163,6 +163,22 @@ namespace NzbDrone.Core.Test.MediaFiles.BookImport.Identification
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
}
[Test]
public void test_add_string_multiple_options_multiple_values_match()
{
var dist = new Distance();
dist.AddString("string", new List<string> { "cat", "dog" }, new List<string> { "dog", "mouse" });
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
}
[Test]
public void test_add_string_multiple_options_multiple_values_no_match()
{
var dist = new Distance();
dist.AddString("string", new List<string> { "cat", "dog" }, new List<string> { "y", "z" });
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
}
[Test]
public void test_distance()
{

@ -173,6 +173,22 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Identification
}
}
public void AddString(string key, List<string> values, List<string> options)
{
if (!values.Any() && !options.Any())
{
Add(key, 0.0);
}
else if (!values.Any() || !options.Any())
{
Add(key, 1.0);
}
else
{
Add(key, values.Min(v => options.Min(o => StringScore(v, o))));
}
}
public void AddBool(string key, bool expr)
{
Add(key, expr ? 1.0 : 0.0);

@ -19,6 +19,8 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Identification
private static readonly RegexReplace StripSeriesRegex = new RegexReplace(@"\([^\)].+?\)$", string.Empty, RegexOptions.Compiled);
private static readonly RegexReplace CleanTitleCruft = new RegexReplace(@"\((?:unabridged)\)", string.Empty, RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static Distance BookDistance(List<LocalBook> localTracks, Edition edition)
{
var dist = new Distance();
@ -68,8 +70,10 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Identification
}
}
dist.AddString("book", title, titleOptions);
Logger.Trace("book: '{0}' vs '{1}'; {2}", title, titleOptions.ConcatToString("' or '"), dist.NormalizedDistance());
var fileTitles = new[] { title, CleanTitleCruft.Replace(title) }.Distinct().ToList();
dist.AddString("book", fileTitles, titleOptions);
Logger.Trace("book: '{0}' vs '{1}'; {2}", fileTitles.ConcatToString("' or '"), titleOptions.ConcatToString("' or '"), dist.NormalizedDistance());
var isbn = localTracks.MostCommon(x => x.FileTrackInfo.Isbn);
if (isbn.IsNotNullOrWhiteSpace() && edition.Isbn13.IsNotNullOrWhiteSpace())

Loading…
Cancel
Save