docs: #306 changes in database models and fixing some problems

This commit is contained in:
Hamid Reza Mohammadi 2022-04-02 19:03:30 +04:30
parent 25abc0c8f7
commit 18e7672144
4 changed files with 78 additions and 16 deletions

View File

@ -24,6 +24,16 @@
Couplet = 3,
}
/// <summary>
/// how GanjoorPoemSection is linked to GanjoorVerse
/// </summary>
public enum VersePoemSectionType
{
First = 1,
Second = 2,
Third = 3,
}
/// <summary>
/// Ganjoor Poem Section
/// </summary>
@ -44,6 +54,16 @@
/// </summary>
public GanjoorPoem Poem { get; set; }
/// <summary>
/// poet id might be different from GanjoorPoem.PoetId
/// </summary>
public int PoetId { get; set; }
/// <summary>
/// poet might be different from GanjoorPoem.PoetId
/// </summary>
public GanjoorPoet Poet { get; set; }
/// <summary>
/// use this field instead of Id for referencing to ease record deletion for verses, Index starts at 0, each poem should have at least one non-virtual part ordered by Index without break
/// </summary>
@ -59,6 +79,11 @@
/// </summary>
public PoemSectionType SectionType { get; set; }
/// <summary>
/// how GanjoorPoemSection is linked to GanjoorVerse
/// </summary>
public VersePoemSectionType VerseType { get; set; }
/// <summary>
/// prosody information
/// </summary>

View File

@ -43,12 +43,17 @@
/// <summary>
/// GanjoorPoemSection index
/// </summary>
public int? PoemSectionIndex { get; set; }
public int? SectionIndex { get; set; }
/// <summary>
/// second GanjoorPoemSection index
/// </summary>
public int? SecondPoemSectionIndex { get; set; }
public int? SecondSectionIndex { get; set; }
/// <summary>
/// third GanjoorPoemSection index
/// </summary>
public int? ThirdSectionIndex { get; set; }
public override string ToString()
{

View File

@ -6744,7 +6744,7 @@
poem section type
</summary>
</member>
<member name="F:RMuseum.Models.Ganjoor.PoemSectionType.Default">
<member name="F:RMuseum.Models.Ganjoor.PoemSectionType.WholePoem">
<summary>
sections like paragraphs or poems within paragraphs of text
</summary>
@ -6764,6 +6764,11 @@
couplets (virtual) for Masnavi
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.VersePoemSectionType">
<summary>
how GanjoorPoemSection is linked to GanjoorVerse
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.GanjoorPoemSection">
<summary>
Ganjoor Poem Section
@ -6784,6 +6789,16 @@
Poem
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.PoetId">
<summary>
poet id might be different from GanjoorPoem.PoetId
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.Poet">
<summary>
poet might be different from GanjoorPoem.PoetId
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.Index">
<summary>
use this field instead of Id for referencing to ease record deletion for verses, Index starts at 0, each poem should have at least one non-virtual part ordered by Index without break
@ -6799,6 +6814,11 @@
section type
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.VerseType">
<summary>
how GanjoorPoemSection is linked to GanjoorVerse
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.GanjoorMetreId">
<summary>
prosody information
@ -7244,16 +7264,21 @@
couplet index
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerse.PoemSectionIndex">
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerse.SectionIndex">
<summary>
GanjoorPoemSection index
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerse.SecondPoemSectionIndex">
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerse.SecondSectionIndex">
<summary>
second GanjoorPoemSection index
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerse.ThirdSectionIndex">
<summary>
third GanjoorPoemSection index
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorVerseNumber.Id">
<summary>
id

View File

@ -16,7 +16,7 @@ namespace RMuseum.Services.Implementation
/// </summary>
public partial class GanjoorService : IGanjoorService
{
public RServiceResult<bool> StartSectionizingPoems()
public RServiceResult<bool> StartSectionizingPoems(bool clearOldSections = false)
{
try
{
@ -31,7 +31,7 @@ namespace RMuseum.Services.Implementation
var job = (await jobProgressServiceEF.NewJob("SectionizingPoems", "Query data")).Result;
try
{
var poems = await context.GanjoorPoems.AsNoTracking().ToListAsync();
var poems = await context.GanjoorPoems.Include(p => p.Cat).AsNoTracking().ToListAsync();
int count = poems.Count;
int progress = 0;
for (int i = 0; i < count; i++)
@ -40,6 +40,7 @@ namespace RMuseum.Services.Implementation
var oldSections = await context.GanjoorPoemSections.Where(s => s.PoemId == poem.Id).ToListAsync();
if (oldSections.Count > 0)
{
if (!clearOldSections) continue;
context.RemoveRange(oldSections);
await context.SaveChangesAsync();
}
@ -50,7 +51,9 @@ namespace RMuseum.Services.Implementation
GanjoorPoemSection mainSection = new GanjoorPoemSection()
{
PoemId = poem.Id,
PoetId = poem.Cat.PoetId,
SectionType = PoemSectionType.WholePoem,
VerseType = VersePoemSectionType.First,
Index = 0,
Number = 1,
GanjoorMetreId = poem.GanjoorMetreId,
@ -68,21 +71,23 @@ namespace RMuseum.Services.Implementation
context.Add(mainSection);//having a main section for مثنوی inside normal text helps keep track of related versess
foreach (var verse in verses)
{
verse.PoemSectionIndex = mainSection.Index;
verse.SecondPoemSectionIndex = null;//clear previous indices
verse.SectionIndex = mainSection.Index;
verse.SecondSectionIndex = null;//clear previous indices
verse.ThirdSectionIndex = null;//clear previous indices
}
int index = 0;
//checking for مثنوی phase 2
if (verses.Count > 2 && string.IsNullOrEmpty(mainSection.RhymeLetters))
var nonCommentVerses = verses.Where(v => v.VersePosition != VersePosition.Comment).ToList();
if (nonCommentVerses.Count > 2 && string.IsNullOrEmpty(mainSection.RhymeLetters))
{
if(_IsMasnavi(verses))
if(_IsMasnavi(verses.Where(v => v.VersePosition != VersePosition.Comment).ToList()))
{
for (int v = 0; v < verses.Count; v += 2)
for (int v = 0; v < nonCommentVerses.Count; v += 2)
{
index++;
var rightVerse = verses[v];
var leftVerse = verses[v + 1];
var rightVerse = nonCommentVerses[v];
var leftVerse = nonCommentVerses[v + 1];
List<GanjoorVerse> coupletVerses = new List<GanjoorVerse>();
coupletVerses.Add(rightVerse);
coupletVerses.Add(leftVerse);
@ -91,15 +96,17 @@ namespace RMuseum.Services.Implementation
GanjoorPoemSection verseSection = new GanjoorPoemSection()
{
PoemId = poem.Id,
PoetId = poem.Cat.PoetId,
SectionType = PoemSectionType.Couplet,
VerseType = VersePoemSectionType.Second,
Index = index,
Number = index,//couplet number
GanjoorMetreId = poem.GanjoorMetreId,
RhymeLetters = res.Rhyme
};
rightVerse.SecondPoemSectionIndex = verseSection.Index;
leftVerse.SecondPoemSectionIndex = verseSection.Index;
rightVerse.SecondSectionIndex = verseSection.Index;
leftVerse.SecondSectionIndex = verseSection.Index;
context.Add(verseSection);
}