#151 api for assigning or analyzing prosody information of a poem
This commit is contained in:
parent
bbda452385
commit
c8b915af01
@ -432,7 +432,7 @@ namespace RMuseum.Controllers
|
||||
[HttpPut]
|
||||
[Route("cat/startassigningrhymes/{id}/{retag}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public IActionResult FindCategoryPoemsRhymes(int id, bool retag)
|
||||
@ -445,6 +445,29 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// start assigning poem rhuthmes
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="retag"></param>
|
||||
/// <param name="rhythm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Route("cat/startassigningrhythms/{id}/{retag}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public IActionResult FindCategoryPoemsRhythms(int id, bool retag, string rhythm = "")
|
||||
{
|
||||
|
||||
RServiceResult<bool> res =
|
||||
_ganjoorService.FindCategoryPoemsRhythms(id, retag, rhythm);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// page by url
|
||||
/// </summary>
|
||||
|
||||
@ -778,6 +778,15 @@
|
||||
<param name="retag"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.FindCategoryPoemsRhythms(System.Int32,System.Boolean,System.String)">
|
||||
<summary>
|
||||
start assigning poem rhuthmes
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="retag"></param>
|
||||
<param name="rhythm"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPageByUrl(System.String,System.Boolean)">
|
||||
<summary>
|
||||
page by url
|
||||
@ -7503,6 +7512,15 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.FindCategoryPoemsRhythms(System.Int32,System.Boolean,System.String)">
|
||||
<summary>
|
||||
find category poem rhymes
|
||||
</summary>
|
||||
<param name="catId"></param>
|
||||
<param name="retag"></param>
|
||||
<param name="rhythm"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
@ -8850,6 +8868,14 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.FindCategoryPoemsRhymes(System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
find category poem rhymes
|
||||
</summary>
|
||||
<param name="catId"></param>
|
||||
<param name="retag"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.FindPoemRhythm(System.Int32)">
|
||||
<summary>
|
||||
find poem rhythm
|
||||
@ -8857,12 +8883,13 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.FindCategoryPoemsRhymes(System.Int32,System.Boolean)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.FindCategoryPoemsRhythms(System.Int32,System.Boolean,System.String)">
|
||||
<summary>
|
||||
find category poem rhymes
|
||||
</summary>
|
||||
<param name="catId"></param>
|
||||
<param name="retag"></param>
|
||||
<param name="rhythm"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.PreparePlainText(System.Collections.Generic.List{RMuseum.Models.Ganjoor.GanjoorVerse})">
|
||||
|
||||
@ -398,5 +398,14 @@ namespace RMuseum.Services
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<string>> FindPoemRhythm(int id);
|
||||
|
||||
/// <summary>
|
||||
/// find category poem rhymes
|
||||
/// </summary>
|
||||
/// <param name="catId"></param>
|
||||
/// <param name="retag"></param>
|
||||
/// <param name="rhythm"></param>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> FindCategoryPoemsRhythms(int catId, bool retag, string rhythm = "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2929,6 +2929,31 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find category poem rhymes
|
||||
/// </summary>
|
||||
/// <param name="catId"></param>
|
||||
/// <param name="retag"></param>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> FindCategoryPoemsRhymes(int catId, bool retag)
|
||||
{
|
||||
try
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
await _FindCategoryPoemsRhymesInternal(catId, retag);
|
||||
});
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find poem rhythm
|
||||
/// </summary>
|
||||
@ -2939,14 +2964,14 @@ namespace RMuseum.Services.Implementation
|
||||
try
|
||||
{
|
||||
var metres = (await GetGanjoorMetres()).Result.Select(m => m.Rhythm).ToArray();
|
||||
return await _FindPoemRhythm(id, _context, metres);
|
||||
return await _FindPoemRhythm(id, _context, _httpClient, metres);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<string>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
private async Task<RServiceResult<string>> _FindPoemRhythm(int id, RMuseumDbContext context, string[] metres)
|
||||
private async Task<RServiceResult<string>> _FindPoemRhythm(int id, RMuseumDbContext context, HttpClient httpClient, string[] metres)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -2958,7 +2983,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"http://sorud.info/?Text={HttpUtility.UrlEncode(LanguageUtils.MakeTextSearchable(verse.Text))}");
|
||||
var response = await httpClient.GetAsync($"http://sorud.info/?Text={HttpUtility.UrlEncode(LanguageUtils.MakeTextSearchable(verse.Text))}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
string result = await response.Content.ReadAsStringAsync();
|
||||
if (result.IndexOf("آهنگِ همهی بندها شناسایی نشد.") != -1)
|
||||
@ -3037,13 +3062,65 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
private async Task _FindCategoryPoemsRhythmsInternal(int catId, bool retag, string rhythm)
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
|
||||
var job = (await jobProgressServiceEF.NewJob($"FindCategoryPoemsRhythms Cat {catId}", "Query data")).Result;
|
||||
try
|
||||
{
|
||||
var metres = await context.GanjoorMetres.OrderBy(m => m.Rhythm).AsNoTracking().ToArrayAsync();
|
||||
var rhythms = metres.Select(m => m.Rhythm).ToArray();
|
||||
|
||||
GanjoorMetre preDeterminedMetre = string.IsNullOrEmpty(rhythm) ? null : metres.Where(m => m.Rhythm == rhythm).Single();
|
||||
|
||||
var poems = await context.GanjoorPoems.Where(p => p.CatId == catId).ToListAsync();
|
||||
|
||||
int i = 0;
|
||||
using(HttpClient httpClient = new HttpClient())
|
||||
{
|
||||
foreach (var poem in poems)
|
||||
{
|
||||
if (retag || poem.GanjoorMetreId == null)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, i++);
|
||||
if (preDeterminedMetre == null)
|
||||
{
|
||||
var res = await _FindPoemRhythm(poem.Id, context, httpClient, rhythms);
|
||||
if (!string.IsNullOrEmpty(res.Result))
|
||||
{
|
||||
poem.GanjoorMetreId = metres.Where(m => m.Rhythm == res.Result).Single().Id;
|
||||
context.GanjoorPoems.Update(poem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
poem.GanjoorMetreId = preDeterminedMetre.Id;
|
||||
context.GanjoorPoems.Update(poem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 99);
|
||||
await context.SaveChangesAsync();
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find category poem rhymes
|
||||
/// </summary>
|
||||
/// <param name="catId"></param>
|
||||
/// <param name="retag"></param>
|
||||
/// <param name="rhythm"></param>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> FindCategoryPoemsRhymes(int catId, bool retag)
|
||||
public RServiceResult<bool> FindCategoryPoemsRhythms(int catId, bool retag, string rhythm = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -3051,17 +3128,19 @@ namespace RMuseum.Services.Implementation
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
await _FindCategoryPoemsRhymesInternal(catId, retag);
|
||||
await _FindCategoryPoemsRhythmsInternal(catId, retag, rhythm);
|
||||
});
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch(Exception exp)
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// make plain text
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user