From 28be6aa9c8a6ba00912c9c324131d70dd410e225 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 27 Mar 2022 17:21:21 +0430 Subject: [PATCH] docs: #302 a utitlity function (_AreSimilar) copied from my old codes --- RMuseum/RMuseum.xml | 3 + .../GanjoorService-DuplicateFinder.cs | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-DuplicateFinder.cs diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 5d5465ee..76e08a59 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -12687,6 +12687,9 @@ IGanjoorService implementation + + IGanjoorService implementation + diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-DuplicateFinder.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-DuplicateFinder.cs new file mode 100644 index 00000000..66e5cf2c --- /dev/null +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-DuplicateFinder.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore; +using RMuseum.DbContext; +using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; +using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor; +using RSecurityBackend.Models.Generic; +using RSecurityBackend.Models.Generic.Db; +using RSecurityBackend.Services.Implementation; +using System; +using System.Collections.Generic; +using System.Data; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; + +namespace RMuseum.Services.Implementation +{ + /// + /// IGanjoorService implementation + /// + public partial class GanjoorService : IGanjoorService + { + private async Task> _FindCateryPoemsDuplicates(RMuseumDbContext context, int srcCatId, int destCatId) + { + try + { + var poems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == srcCatId).ToListAsync(); + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + + private static bool _AreSimilar(string str1, string str2, bool reverse) + { + if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2)) + return false; + + string[] words2 = str2.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + int total = words2.Length; + int found = 0; + for (int i = 0; i < total; i++) + { + if (str1.IndexOf(words2[i]) != -1) + found++; + } + + if (!reverse) + return (float)found / total > 0.7f; + + return (float)found / total > 0.7f && _AreSimilar(str2, str1, false); + } + } +} \ No newline at end of file