ganahrhr 3 gadi atpakaļ
vecāks
revīzija
e752240a4e
7 mainītis faili ar 148 papildinājumiem un 16 dzēšanām
  1. 2 0
      AppData.cs
  2. 20 0
      Models/ReportModel.cs
  3. 30 0
      Pages/Collapsible.razor
  4. 27 14
      Pages/Desktop.razor.cs
  5. 66 0
      Pages/Report.razor
  6. 1 1
      Pages/Wallet.razor
  7. 2 1
      Startup.cs

+ 2 - 0
AppData.cs

@@ -34,6 +34,8 @@ namespace HyperCube
             }
         }
 
+        public ReportModel Report = new();
+
         private static Dictionary<int, ArticleModel> _articles;
         public static Dictionary<int, ArticleModel> Articles
         {

+ 20 - 0
Models/ReportModel.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HyperCube.Models
+{
+    public class ReportModel
+    {
+        public string FileName { get; set; }
+        public string FileFormat { get; set; }
+        public string FileSize { get; set; }
+        public string NounGroups { get; set; }
+        public string NounGroupsSorted { get; set; }
+        public string Entities { get; set; }
+        public string EntitiesNounGroups { get; set; }
+        public string Keywords1 { get; set; }
+        public string Keywords2 { get; set; }
+    }
+}

+ 30 - 0
Pages/Collapsible.razor

@@ -0,0 +1,30 @@
+<div class="second-block__input__file__label__box" @onclick="@Toggle">
+    <label for="input_file" class="second-block__input__file__label">
+        <span>@( this.Collapsed ? "+" : "-")</span>
+        <p>@LabelText</p>
+    </label>    
+</div>
+
+
+@if (!Collapsed)
+{
+    <div style="margin-top: 10px">
+        @ChildContent
+    </div>
+}
+
+@code {
+    [Parameter]
+    public RenderFragment ChildContent { get; set; }
+    [Parameter]
+    public bool Collapsed { get; set; } = true;
+
+    //input params coming from from page
+    [Parameter]
+    public string LabelText { get; set; }
+
+    void Toggle()
+    {
+        Collapsed = !Collapsed;
+    }
+}

+ 27 - 14
Pages/Desktop.razor.cs

@@ -20,6 +20,8 @@ namespace HyperCube.Pages
     {
         [Inject]
         NavigationManager _navigationManager { get; set; }
+        [Inject]
+        AppData _appData { get; set; }
 
         //const string FOLDER_NAME = "articles_storage";
         const long MAX_FILE_SIZE = 5120000; //bytes
@@ -118,6 +120,9 @@ namespace HyperCube.Pages
                     _articleClone.FileHashSum = hash;
                     _article = (ArticleModel)_articleClone.Clone();
 
+                    ReportModel report = _appData.Report;
+                    report.FileName = file.Name;
+                    report.FileSize = _memoryStream.Length.ToString();
 
                     _memoryStream.Position = 0;
                     byte[] content = _memoryStream.ToArray();
@@ -183,7 +188,7 @@ namespace HyperCube.Pages
 
                     Console.WriteLine($"Initializing SDK Pullenti ver {Pullenti.Sdk.Version} ({Pullenti.Sdk.VersionDate})... ");
                     Pullenti.Sdk.InitializeAll();
-                    Console.WriteLine($"OK (by ... ms), version {Pullenti.Ner.ProcessorService.Version}");
+                    //Console.WriteLine($"OK (by ... ms), version {Pullenti.Ner.ProcessorService.Version}");
 
                     List<string> npt_tokens = new();
 
@@ -199,7 +204,8 @@ namespace HyperCube.Pages
                         if (npt == null)
                             continue;
                         // получилось, выводим в нормализованном виде
-                        System.Console.Write($"[{npt.GetSourceText()}=>{npt.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false)}] ");
+                        //System.Console.Write($"[{npt.GetSourceText()}=>{npt.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false)}] ");
+                        report.NounGroups += $"[{npt.GetSourceText()}=>{npt.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false)}] "; 
 
                         npt_tokens.Add(npt.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false));
 
@@ -211,17 +217,19 @@ namespace HyperCube.Pages
                         // анализируем текст
                         Pullenti.Ner.AnalysisResult ar = proc.Process(new Pullenti.Ner.SourceOfAnalysis(plainText), null, null);
                         // результирующие сущности
-                        Console.WriteLine("\r\n==========================================\r\nEntities: ");
+                        //Console.WriteLine("\r\n==========================================\r\nEntities: ");
                         foreach (Pullenti.Ner.Referent en in ar.Entities)
                         {
-                            Console.WriteLine($"{en.TypeName}: {en}");
+                            //Console.WriteLine($"{en.TypeName}: {en}");
+                            report.Entities += $"{en.TypeName}: {en}\r\n";
                             foreach (Pullenti.Ner.Slot s in en.Slots)
                             {
-                                Console.WriteLine($"   {s.TypeName}: {s.Value}");
+                                //Console.WriteLine($"   {s.TypeName}: {s.Value}");
+                                report.Entities += $"   {s.TypeName}: {s.Value}<br>";
                             }
                         }
                         // пример выделения именных групп
-                        Console.WriteLine("\r\n==========================================\r\nNoun groups: ");
+                        //Console.WriteLine("\r\n==========================================\r\nNoun groups: ");
                         for (Pullenti.Ner.Token t = ar.FirstToken; t != null; t = t.Next)
                         {
                             // токены с сущностями игнорируем
@@ -232,7 +240,8 @@ namespace HyperCube.Pages
                             // не получилось
                             if (npt == null)
                                 continue;
-                            Console.WriteLine(npt.ToString());
+                            //Console.WriteLine(npt.ToString());
+                            report.EntitiesNounGroups += $"{npt}<br>";
                             // указатель перемещаем на последний токен группы
                             t = npt.EndToken;
                         }
@@ -240,13 +249,14 @@ namespace HyperCube.Pages
                     using (Pullenti.Ner.Processor proc = Pullenti.Ner.ProcessorService.CreateSpecificProcessor(Pullenti.Ner.Keyword.KeywordAnalyzer.ANALYZER_NAME))
                     {
                         Pullenti.Ner.AnalysisResult ar = proc.Process(new Pullenti.Ner.SourceOfAnalysis(plainText), null, null);
-                        Console.WriteLine("\r\n==========================================\r\nKeywords1: ");
+                        //Console.WriteLine("\r\n==========================================\r\nKeywords1: ");
                         foreach (Pullenti.Ner.Referent en in ar.Entities)
                         {
                             if (en is Pullenti.Ner.Keyword.KeywordReferent)
-                                Console.WriteLine(en.ToString());
+                                //Console.WriteLine(en.ToString());
+                                report.Keywords1 += $"{en}<br>";
                         }
-                        Console.WriteLine("\r\n==========================================\r\nKeywords2: ");
+                        //Console.WriteLine("\r\n==========================================\r\nKeywords2: ");
                         for (Pullenti.Ner.Token t = ar.FirstToken; t != null; t = t.Next)
                         {
                             if (t is Pullenti.Ner.ReferentToken)
@@ -255,12 +265,12 @@ namespace HyperCube.Pages
                                 if (kw == null)
                                     continue;
                                 string kwstr = Pullenti.Ner.Core.MiscHelper.GetTextValueOfMetaToken(t as Pullenti.Ner.ReferentToken, Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominativeSingle | Pullenti.Ner.Core.GetTextAttr.KeepRegister);
-                                Console.WriteLine($"{kwstr} = {kw}");
+                                //Console.WriteLine($"{kwstr} = {kw}");
+                                report.Keywords2 += $"{kwstr} = {kw}<br>";
                             }
                         }
                     }
-                    Console.WriteLine("Over!");
-
+                    Console.WriteLine("Analysis is over!");
                     
                     int res = (from x in npt_tokens
                                select x).Distinct().Count();
@@ -274,8 +284,11 @@ namespace HyperCube.Pages
                             select new { Name = g.Key, Count = count1 };
                     foreach (var result in query)
                     {
-                        Console.WriteLine($"Name: {result.Name}, Count: {result.Count}");                        
+                        report.NounGroupsSorted += $"{result.Name}, Count: {result.Count}<br>";
+                        //Console.WriteLine($"Name: {result.Name}, Count: {result.Count}");                        
                     }
+
+                    _navigationManager.NavigateTo("report");
                 }
                 else
                 {

+ 66 - 0
Pages/Report.razor

@@ -0,0 +1,66 @@
+@page "/report"
+
+@inject AppData _appData
+
+<div style="margin-left:10px ; margin-top: 10px">
+    <a href="desktop">Вернуться на рабочий стол</a>
+
+    <p>Имя файла: @_report.FileName</p>
+    <p>Размер: @_report.FileSize байт</p>
+    <p>Формат: @_report.FileFormat</p>
+
+    <Collapsible LabelText="Noun groups:"
+                 Collapsed="true">
+        <ChildContent>            
+            <div style="margin-left:50px">
+                <Collapsible LabelText="Grouped&Sorted"
+                             Collapsed="true">
+                    <ChildContent>
+                        @((MarkupString)_report.NounGroupsSorted)
+                    </ChildContent>
+                </Collapsible>
+            </div>
+            @((MarkupString)_report.NounGroups)            
+        </ChildContent>
+    </Collapsible>
+
+    <Collapsible LabelText="Entities:"
+                 Collapsed="true">
+        <ChildContent>
+            <div style="margin-left:50px">
+                <Collapsible LabelText="Noun groups:"
+                             Collapsed="true">
+                    <ChildContent>
+                        @((MarkupString)_report.EntitiesNounGroups)
+                    </ChildContent>
+                </Collapsible>
+            </div>
+            @((MarkupString)_report.Entities)
+        </ChildContent>
+    </Collapsible>
+
+    <Collapsible LabelText="Keywords1:"
+                 Collapsed="true">
+
+        <ChildContent>
+            @((MarkupString)_report.Keywords1)
+        </ChildContent>
+    </Collapsible>
+
+    <Collapsible LabelText="Keywords2:"
+                 Collapsed="true">
+
+        <ChildContent>
+            @((MarkupString)_report.Keywords2)
+        </ChildContent>
+    </Collapsible>
+</div>
+
+@code{
+    Models.ReportModel _report;
+
+    protected override async Task OnInitializedAsync()
+    {
+        _report = _appData.Report;
+    }
+}

+ 1 - 1
Pages/Wallet.razor

@@ -3,7 +3,7 @@
 @using HyperCube.Models;
 @using Microsoft.AspNetCore.Identity;
 @inject AuthenticationStateProvider AuthenticationStateProvider
-@inject UserManager<IdentityUser> UserManager;
+@inject UserManager<IdentityUser> UserManager
 
 @attribute [Authorize]
 

+ 2 - 1
Startup.cs

@@ -40,9 +40,10 @@ namespace HyperCube
                 .AddEntityFrameworkStores<ApplicationDbContext>();
             services.AddRazorPages();
             services.AddServerSideBlazor();
-            services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
+            services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();            
             services.AddDatabaseDeveloperPageExceptionFilter();
             services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
+            services.AddScoped<AppData>();
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.