docs: #317 finding poem rhymes according to sections

This commit is contained in:
Hamid Reza Mohammadi 2022-05-05 17:50:09 +04:30
parent ac87b282b1
commit c850fd756b
3 changed files with 28 additions and 11 deletions

View File

@ -322,7 +322,7 @@ namespace RMuseum.Services.Implementation
RhymeLetters = section.RhymeLetters,
PoemFormat = section.PoemFormat,
};
var sectionVerses = _GetSectionVerses(sectionCopy, targetPoemVerses);
var sectionVerses = FilterSectionVerses(sectionCopy, targetPoemVerses);
sectionCopy.HtmlText = PrepareHtmlText(sectionVerses);
sectionCopy.PlainText = PreparePlainText(sectionVerses);
try
@ -539,7 +539,7 @@ namespace RMuseum.Services.Implementation
RhymeLetters = section.RhymeLetters,
PoemFormat = section.PoemFormat,
};
var sectionVerses = _GetSectionVerses(sectionCopy, targetPoemVerses);
var sectionVerses = FilterSectionVerses(sectionCopy, targetPoemVerses);
sectionCopy.HtmlText = PrepareHtmlText(sectionVerses);
sectionCopy.PlainText = PreparePlainText(sectionVerses);
try

View File

@ -475,7 +475,13 @@ namespace RMuseum.Services.Implementation
context.UpdateRange(nonCommentVerses);
}
private List<GanjoorVerse> _GetSectionVerses(GanjoorPoemSection section, List<GanjoorVerse> verses)
/// <summary>
/// filter secion verses
/// </summary>
/// <param name="section"></param>
/// <param name="verses"></param>
/// <returns></returns>
public List<GanjoorVerse> FilterSectionVerses(GanjoorPoemSection section, List<GanjoorVerse> verses)
{
List<GanjoorVerse> sectionVerses = new List<GanjoorVerse>();
foreach (GanjoorVerse verse in verses)

View File

@ -3057,21 +3057,32 @@ namespace RMuseum.Services.Implementation
var job = (await jobProgressServiceEF.NewJob($"FindCategoryPoemsRhymes Cat {catId}", "Query data")).Result;
try
{
var poems = await context.GanjoorPoems.Where(p => p.CatId == catId).ToListAsync();
var poems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).ToListAsync();
int i = 0;
foreach (var poem in poems)
{
if (retag || string.IsNullOrEmpty(poem.RhymeLetters))
var verses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == poem.Id).OrderBy(v => v.VOrder).ToListAsync();
var sections = await context.GanjoorPoemSections.Where(s => s.PoemId == poem.Id).ToListAsync();
foreach (var section in sections)
{
await jobProgressServiceEF.UpdateJob(job.Id, i++);
var res = await _FindPoemRhyme(poem.Id, context);
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Rhyme))
if (retag || string.IsNullOrEmpty(section.RhymeLetters))
{
poem.RhymeLetters = res.Result.Rhyme;
context.GanjoorPoems.Update(poem);
await jobProgressServiceEF.UpdateJob(job.Id, i++);
var sectionVerses = FilterSectionVerses(section, verses);
try
{
var res = LanguageUtils.FindRhyme(sectionVerses);
if(!string.IsNullOrEmpty(res.Rhyme))
{
section.RhymeLetters = res.Rhyme;
context.GanjoorPoemSections.Update(section);
}
}
catch
{
}
}
}
}
await jobProgressServiceEF.UpdateJob(job.Id, 99);