33 lines
3.7 KiB
C#
33 lines
3.7 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using PlotLine.Models;
|
|
using PlotLine.Services;
|
|
using PlotLine.ViewModels;
|
|
internal static class NameVerificationBrowserFixture
|
|
{
|
|
public static NameTextSearch Search(string name,bool zero=false)
|
|
{
|
|
var scope=new NameManuscriptScope{Fingerprint=new string('A',64),BookCount=2,SnapshotBooks=1,LegacyBooks=1};
|
|
if(zero)return NameTextMatcher.Match(name,scope,[]);
|
|
return NameTextMatcher.Match(name,scope,[new(){BookID=12,BookTitle="Synthetic first book",ChapterID=10,SceneID=22,SceneTitle="Synthetic scene",ParagraphID=Guid.Parse("11111111-1111-4111-8111-111111111111"),ParagraphOrdinal=0,ManuscriptID=Guid.Parse("33333333-3333-4333-8333-333333333333"),Revision=1,SourceKind="Paragraph snapshot",Text=$"{name} placed a {name.ToLowerInvariant()} on the table.",TotalCandidateParagraphs=2},new(){BookID=13,BookTitle="Synthetic second book",ChapterID=11,SceneID=23,SceneTitle="Another synthetic scene",ParagraphOrdinal=4,SourceKind="Saved scene text",Text=name+"?",TotalCandidateParagraphs=2}]);
|
|
}
|
|
public static NameVerificationView Result(string name,bool outdated=false,bool zero=false,bool interrupted=false)
|
|
{
|
|
var search=Search(name,zero);var result=new NameVerificationResult{Name=name,NormalisedName=NameIntelligenceService.NormaliseName(name),Fingerprint=search.Scope.Fingerprint,AlgorithmVersion=NameVerificationPlanner.AlgorithmVersion,CreatedUtc=new(2026,11,26,12,0,0,DateTimeKind.Utc),Scope=search.Scope,TextualMatches=search.TextualMatches,MatchesExact=true,Complete=true,ScannedParagraphs=search.ScannedParagraphs,CandidateParagraphs=search.CandidateParagraphs};
|
|
result.Findings=search.Contexts.Select((context,i)=>new NameVerifiedContext(context,i==0?"likely-name":i==1?"ordinary-language":"ambiguous","Synthetic qualified assessment for isolated browser acceptance.")).ToList();if(interrupted){result.Findings=result.Findings.Take(1).ToList();result.Complete=false;result.Interrupted=true;result.Limitations.Add("Processing stopped before every planned context was examined.");}return new(77,result,outdated);
|
|
}
|
|
public static async Task Render(HttpContext context)
|
|
{
|
|
var name=context.Request.Query["name"].FirstOrDefault()??"Rose";var zero=context.Request.Query["zero"]=="true";var outdated=context.Request.Query["outdated"]=="true";var part=context.Request.RouteValues["part"]?.ToString();var result=Result(name,outdated,zero,context.Request.Query["interrupted"]=="true");var offset=int.TryParse(context.Request.Query["offset"],out var n)?n:0;
|
|
object model=part switch{"textual"=>new NameTextOccurrencesViewModel(Search(name,zero),offset),"findings"=>new NameVerificationFindingsViewModel(result,offset,context.Request.Query["includeOrdinary"]=="true"),_=>result};var viewName=part switch{"textual"=>"_NameTextOccurrences","findings"=>"_NameVerificationFindings",_=>"_NameVerification"};
|
|
var action=new ActionContext(context,new RouteData(),new ActionDescriptor());var view=context.RequestServices.GetRequiredService<ICompositeViewEngine>().GetView(null,"/Views/Shared/"+viewName+".cshtml",false);using var writer=new StringWriter();await view.View!.RenderAsync(new ViewContext(action,view.View,new ViewDataDictionary(new EmptyModelMetadataProvider(),new ModelStateDictionary()){Model=model},new TempDataDictionary(context,context.RequestServices.GetRequiredService<ITempDataProvider>()),writer,new HtmlHelperOptions()));context.Response.ContentType="text/html";await context.Response.WriteAsync(writer.ToString());
|
|
}
|
|
}
|