Browse Source

cleanup, doc analyzation results save/load, verification point begin

ganahrhr 3 years ago
parent
commit
d548ced9e0
8 changed files with 161 additions and 774 deletions
  1. 5 2
      AppData.cs
  2. 101 3
      Models/ArticleModel.cs
  3. 22 15
      MySQLConnector.cs
  4. 4 4
      Pages/Blockchains.razor
  5. 7 10
      Pages/Desktop.razor
  6. 20 13
      Pages/Desktop.razor.cs
  7. 0 695
      Pages/source_index.html
  8. 2 32
      Shared/MainLayout.razor

+ 5 - 2
AppData.cs

@@ -3,6 +3,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using HyperCube.Models;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Authorization;
+using Microsoft.AspNetCore.Identity;
 using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube
@@ -11,9 +14,9 @@ namespace HyperCube
     /// Синглтон приложения
     /// </summary>
     public class AppData
-    {        
+    {
         public ReportModel Report { get; set; } = new();
-        public AccountModel CurrentAccount;
+        public AccountModel CurrentAccount { get; set; }
         public ArticleModel CurrentArticle { get; set; }
         public ArticleModel CurrentArticleClone { get; set; }
 

+ 101 - 3
Models/ArticleModel.cs

@@ -26,7 +26,9 @@ namespace HyperCube.Models
     public class ArticleModel : ICloneable
     {
         public int ID { get; set; }
+        [Required]
         public string Filename { get; set; }
+        [Required]
         public string HashSum { get; set; }
         public string FilenameReal { get { return ID + "_" + Filename; } }
         [Required]        
@@ -43,6 +45,16 @@ namespace HyperCube.Models
 
         public ArticleStatus Status { get; set; } = ArticleStatus.New;
 
+        /// fields for recognited text
+        public string NounGroups { get; set; }
+        public string Entities { get; set; }
+        public string Morph { get; set; }
+        public string Keywords1 { get; set; }
+        public string Keywords2 { get; set; }
+
+        /// collection for history of verification
+        public Dictionary<int, VerificationPoint> VerificationHistory { get; set; }
+
         public int? Rating
         {
             get { return rating; }
@@ -79,7 +91,7 @@ namespace HyperCube.Models
                 stringSQL += $"WHERE article_id={this.ID} AND acc_id='{acc_id}'";
 
             int count = await dbCon.SQLSelectCount(stringSQL);
-            //dbCon.Close();
+            
             return count;
         }
 
@@ -96,8 +108,7 @@ namespace HyperCube.Models
                     $"JOIN actions_history ON actions_history.article_id = articles.id " +
                     $"WHERE articles.id={this.ID} AND action_type={(int)ArticleStatus.Saved}";
 
-                initiatorUUID = await dbCon.SQLSelectUUID(stringSQL);
-                //dbCon.Close();                
+                initiatorUUID = await dbCon.SQLSelectUUID(stringSQL);                               
             }
             else
                 Console.WriteLine("initiatorUUID already set");
@@ -105,9 +116,96 @@ namespace HyperCube.Models
             return initiatorUUID;
         }
 
+        public async Task<Dictionary<int, VerificationPoint>> GetVerificationHistory(int articleid, string acc_uuid)
+        {
+            Console.WriteLine($"GetVerificationHistory for article [{articleid}]");
+
+            Dictionary<int, VerificationPoint> verificationHistory = new();
+            VerificationPoint verificationPoint;
+
+            var vps = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FFROM articles_verification WHERE article_id='{articleid}'"); //AND acc_id='{acc_uuid}'
+            if (vps.Count > 0)
+            {
+                foreach (var vp in vps)
+                {
+                    verificationPoint = new()
+                    {
+                        ID = Convert.ToInt32(vp["id"]),
+                        RulesViolation = Convert.ToBoolean(vp["rules_violation"]),
+                        NonExpert = Convert.ToBoolean(vp["nonexpert"]),
+                        AdditionalVerificationRequired = Convert.ToBoolean(vp["additional_verification_required"]),
+                        Rejected = Convert.ToBoolean(vp["rejected"]),
+                        RejectReason = Convert.ToString(vp["reject_reason"]),
+                        Tags = Convert.ToString(vp["tags"]),
+                        DateAdd = Convert.ToDateTime(vp["date_add"])
+                    };
+                    Console.WriteLine($"add verificationPoint. id: {verificationPoint.ID}, rules_violation: {verificationPoint.RulesViolation}, date_add: {verificationPoint.DateAdd}");
+                    verificationHistory.Add(verificationPoint.ID, verificationPoint);
+                }
+            }
+            else
+                Console.WriteLine($"Article [{articleid}] has no history yet.");
+
+            return verificationHistory;
+        }
+
+        public async Task SaveVerificationPoint(VerificationPoint verificationPoint, string acc_uuid)
+        {
+            //Console.WriteLine($"SaveVerificationPoint");
+            
+            int rules_violation = Convert.ToInt32(verificationPoint.RulesViolation);
+            int nonexpert = Convert.ToInt32(verificationPoint.RulesViolation);
+            int additional_verification_required = Convert.ToInt32(verificationPoint.RulesViolation);
+            int rejected = Convert.ToInt32(verificationPoint.RulesViolation);            
+
+            if (verificationPoint.ID == 0) ///new point
+            {
+                Console.WriteLine($"SaveVerificationPoint. New point to save");
+
+                long id = await MySQLConnector.Instance().SQLInsert($"INSERT INTO articles_verification " +
+                                $"(article_id, acc_id, rules_violation, nonexpert, additional_verification_required, rejected, reject_reason, tags) " +
+                                $"VALUES ('{this.ID}','{acc_uuid}','{rules_violation}', '{nonexpert}', '{additional_verification_required}', " +
+                                $"'{rejected}', '{verificationPoint.RejectReason}', '{verificationPoint.Tags}')");
+                if (id > 0)
+                {
+                    verificationPoint.ID = (int)id;
+                    VerificationHistory.Add(verificationPoint.ID, verificationPoint);
+
+                    Console.WriteLine($"SaveVerificationPoint. Point saved, id: {id}");
+                }
+                else
+                    Console.WriteLine($"SaveVerificationPoint. Something went wrong, id < 1");
+            }
+            else ///existed
+            {
+                Console.WriteLine($"SaveVerificationPoint. Existed point to save, id: {verificationPoint.ID}");
+
+                await MySQLConnector.Instance().SQLInsert($"UPDATE articles_verification SET " +                                    
+                                    $"acc_id='{acc_uuid}', rules_violation='{rules_violation}', nonexpert='{nonexpert}', additional_verification_required={additional_verification_required}, " +
+                                    $"rejected={rejected}, reject_reason={verificationPoint.RejectReason}, tags={verificationPoint.Tags}) " +
+                                    $"WHERE id={verificationPoint.ID}");
+            }
+        }
+
         public object Clone()
         {
             return MemberwiseClone();
         }
     }
+
+    public class VerificationPoint
+    {
+        public int ID;
+        public bool RulesViolation;
+        public bool NonExpert;
+        public bool AdditionalVerificationRequired;
+        public bool Rejected;
+        public string RejectReason;
+        public string Tags;
+        public DateTime DateAdd;        
+
+        public VerificationPoint()
+        {
+        }        
+    }
 }

+ 22 - 15
MySQLConnector.cs

@@ -288,7 +288,7 @@ namespace HyperCube
         public async Task<ArticleModel> SQLSelectArticle(string sql)
         {
             Console.WriteLine($"SQLSelectArticle");
-            ArticleModel articleModel = new();
+            ArticleModel article = new();
 
             bool connected = await IsConnect();
             if (connected)
@@ -296,24 +296,31 @@ namespace HyperCube
                 SQLcom = new(sql, Connection);
                 MySqlDataReader rdr = SQLcom.ExecuteReader();
 
-                while (rdr.Read())  ///id, filename, article_name, authors, date_publish, annotation, keywords, action_type/status, rating, file_hash
+                ///0=id, filename, article_name, authors, date_publish, annotation, keywords, action_type/status, rating, file_hash, 
+                ///10=doc_noungroups, doc_entities, doc_morph, doc_keywords1, doc_keywords2
+                while (rdr.Read())
                 {
-                    articleModel.ID = rdr.GetInt32(0);
-                    articleModel.Filename = rdr.GetString(1);
-                    articleModel.Name = rdr.GetString(2);
-                    articleModel.Authors = rdr.GetString(3);
-                    articleModel.PublishDate = rdr.GetDateTime(4);
-                    articleModel.Annotation = rdr.GetString(5);
-                    articleModel.Keywords = rdr.GetString(6);
-                    articleModel.Status = (ArticleStatus)rdr.GetInt16(7);
-                    if (!rdr.IsDBNull(8)) articleModel.Rating = rdr.GetInt16(8);
-                    articleModel.HashSum = rdr.GetString(9);
-
-                    Console.WriteLine($"Got article, ID: {articleModel.ID}.");
+                    article.ID = rdr.GetInt32(0);
+                    article.Filename = rdr.GetString(1);
+                    article.Name = rdr.GetString(2);
+                    article.Authors = rdr.GetString(3);
+                    article.PublishDate = rdr.GetDateTime(4);
+                    article.Annotation = rdr.GetString(5);
+                    article.Keywords = rdr.GetString(6);
+                    article.Status = (ArticleStatus)rdr.GetInt16(7);
+                    if (!rdr.IsDBNull(8)) article.Rating = rdr.GetInt16(8);
+                    article.HashSum = rdr.GetString(9);
+                    article.NounGroups = rdr.GetString(10);
+                    article.Entities = rdr.GetString(11);
+                    article.Morph = rdr.GetString(12);
+                    article.Keywords1 = rdr.GetString(13);
+                    if (!rdr.IsDBNull(14)) article.Keywords2 = rdr.GetString(14);                    
+
+                    Console.WriteLine($"Got article, ID: {article.ID}.");
                 }                
                 rdr.Close();
                 await Task.WhenAll();
-                return articleModel;
+                return article;
             }
             else
                 Console.WriteLine("Not connected to DB.");

+ 4 - 4
Pages/Blockchains.razor

@@ -12,7 +12,8 @@
 @inject ProtectedSessionStorage storage
 
 @attribute [Authorize]
-<div class="tabs__content">
+
+@*<div class="tabs__content">
     <div class="tabs__controls">
         @if (account.Roles.Contains(Role.Admin) || account.Roles.Contains(Role.Initiator))
         {
@@ -29,9 +30,8 @@
         }
     </div>
 </div>
-<br>
+<br>*@
 
-@*<h1>Blazor is @Smart!</h1>*@
 @code
 {
     string hidecontr = "visible";
@@ -96,7 +96,7 @@
 
 @if (Blockchain.blockChainsInitialized)
 {
-    <select @bind="account.blockchain_selected" style="color:green">
+    <select @bind="account.blockchain_selected" style="color:green; width:30%; margin:20px; margin-left:0px">
         <option value=0>Ethereum Dev Network</option>
         <option value=1>Ethereum Test Network</option>
     </select>

+ 7 - 10
Pages/Desktop.razor

@@ -157,10 +157,6 @@
             <label class="сheckbox__label" for="radio3">
                 Требуется дополнительная экспертиза
             </label>
-            <input type="checkbox" class="checkbox__input" name="verify" id="radio4">
-            <label class="сheckbox__label" for="radio4">
-                Требуется дополнительная экспертиза
-            </label>
             <input type="checkbox" class="checkbox__input" name="verify" id="radio5">
             <label class="сheckbox__label" for="radio5">
                 Отклонить, указать причину
@@ -169,7 +165,8 @@
                 <textarea placeholder="Причина" class="form-control upload__textarea"></textarea>
             </label>
             <label class="upload__label">
-                <textarea placeholder="Указать через запятую теги" class="form-control upload__textarea"></textarea>
+                <textarea placeholder="Теги" class="form-control upload__textarea"></textarea>
+                <div class="upload__input-descr">+ Добавить тэг. Указывать тэги через запятую</div>
             </label>
             <div class="second-block__form__button">
                 <button class="btn_grey" @onclick="Verify_OnClick">Валидация</button>
@@ -241,35 +238,35 @@
                     </ChildContent>
                 </Collapsible>
             </div>
-            @((MarkupString)_report.NounGroups)
+            @((MarkupString)_article.NounGroups)
         </ChildContent>
     </Collapsible>
 
     <Collapsible LabelText="Entities:"
                  Collapsed="true">
         <ChildContent>
-            @((MarkupString)_report.Entities)
+            @((MarkupString)_article.Entities)
         </ChildContent>
     </Collapsible>
 
     <Collapsible LabelText="Morph:"
                  Collapsed="true">
         <ChildContent>
-            @((MarkupString)_report.EntitiesNounGroups)
+            @((MarkupString)_article.Morph)
         </ChildContent>
     </Collapsible>
 
     <Collapsible LabelText="Keywords1:"
                  Collapsed="true">
         <ChildContent>
-            @((MarkupString)_report.Keywords1)
+            @((MarkupString)_article.Keywords1)
         </ChildContent>
     </Collapsible>
 
     <Collapsible LabelText="Keywords2:"
                  Collapsed="true">
         <ChildContent>
-            @((MarkupString)_report.Keywords2)
+            @((MarkupString)_article.Keywords2)
         </ChildContent>
     </Collapsible>
 </div>

+ 20 - 13
Pages/Desktop.razor.cs

@@ -226,8 +226,8 @@ namespace HyperCube.Pages
                             continue;
                         // получилось, выводим в нормализованном виде
                         //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)}] "; 
-
+                        //_report.NounGroups += $"[{npt.GetSourceText()}=>{npt.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false)}] ";
+                        _article.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));
 
                         // указатель на последний токен именной группы
@@ -242,11 +242,13 @@ namespace HyperCube.Pages
                         foreach (Pullenti.Ner.Referent en in ar.Entities)
                         {
                             //Console.WriteLine($"{en.TypeName}: {en}");
-                            _report.Entities += $"{en.TypeName}: {en}\r\n";
+                            //_report.Entities += $"{en.TypeName}: {en}\r\n";
+                            _article.Entities += $"{en.TypeName}: {en}\r\n";
                             foreach (Pullenti.Ner.Slot s in en.Slots)
                             {
                                 //Console.WriteLine($"   {s.TypeName}: {s.Value}");
-                                _report.Entities += $"   {s.TypeName}: {s.Value}<br>";
+                                //_report.Entities += $"   {s.TypeName}: {s.Value}<br>";
+                                _article.Entities += $"   {s.TypeName}: {s.Value}<br>";
                             }
                         }
                         // пример выделения именных групп
@@ -262,7 +264,8 @@ namespace HyperCube.Pages
                             if (npt == null)
                                 continue;
                             //Console.WriteLine(npt.ToString());
-                            _report.EntitiesNounGroups += $"{npt}<br>";
+                            //_report.EntitiesNounGroups += $"{npt}<br>";
+                            _article.Morph += $"{npt}<br>";
                             // указатель перемещаем на последний токен группы
                             t = npt.EndToken;
                         }
@@ -275,7 +278,8 @@ namespace HyperCube.Pages
                         {
                             if (en is Pullenti.Ner.Keyword.KeywordReferent)
                                 //Console.WriteLine(en.ToString());
-                                _report.Keywords1 += $"{en}<br>";
+                                //_report.Keywords1 += $"{en}<br>";
+                                _article.Keywords1 += $"{en}<br>";
                         }
                         //Console.WriteLine("\r\n==========================================\r\nKeywords2: ");
                         for (Pullenti.Ner.Token t = ar.FirstToken; t != null; t = t.Next)
@@ -287,7 +291,8 @@ namespace HyperCube.Pages
                                     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}");
-                                _report.Keywords2 += $"{kwstr} = {kw}<br>";
+                                //_report.Keywords2 += $"{kwstr} = {kw}<br>";
+                                _article.Keywords2 += $"{kwstr} = {kw}<br>";
                             }
                         }
                     }                   
@@ -309,7 +314,7 @@ namespace HyperCube.Pages
                         //Console.WriteLine($"Name: {result.Name}, Count: {result.Count}");                        
                     }
 
-                    AppData.Report = _report;                    
+                    //AppData.Report = _report;
                 }
                 else
                 {
@@ -378,9 +383,11 @@ namespace HyperCube.Pages
                 {
                     _modalLoading.Open();
 
-                    stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash) " +
+                    stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash, " +
+                        $"doc_noungroups, doc_entities, doc_morph, doc_keywords1, doc_keywords2) " +
                         $"VALUES ('{_article.Filename}', '{_article.Name}', '{_article.Authors}', '{_article.PublishDate:yyyy-MM-dd}'," +
-                        $"'{_article.Annotation}', '{_article.Keywords}', '{_article.HashSum}')";
+                        $"'{_article.Annotation}', '{_article.Keywords}', '{_article.HashSum}'," +
+                        $"'{_article.NounGroups}', '{_article.Entities}', '{_article.Morph}', '{_article.Keywords1}', '{_article.Keywords2}' )";
                     id = await dbCon.SQLInsert(stringSQL);
                     _article.ID = (int)id;
 
@@ -422,13 +429,13 @@ namespace HyperCube.Pages
             {
                 MySQLConnector dbCon = MySQLConnector.Instance();
 
-                string stringSQL = $"SELECT articles.id, filename, article_name, authors, date_publish, annotation, keywords, action_type, rating, file_hash " +
+                string stringSQL = $"SELECT articles.id, filename, article_name, authors, date_publish, annotation, keywords, action_type, rating, file_hash, " +
+                    $"doc_noungroups, doc_entities, doc_morph, doc_keywords1, doc_keywords2 " +
                     $"FROM articles " +
                     $"JOIN actions_history ON actions_history.article_id = articles.id " +
                     $"WHERE articles.id={docid} " +
                     $"ORDER BY actions_history.id DESC LiMIT 1";
-                //_articleClone = await dbCon.SQLSelectArticle(stringSQL);
-                //_article = (ArticleModel)_articleClone.Clone();
+                
                 AppData.CurrentArticleClone = await dbCon.SQLSelectArticle(stringSQL);
                 AppData.CurrentArticle = (ArticleModel)AppData.CurrentArticleClone.Clone();
 

File diff suppressed because it is too large
+ 0 - 695
Pages/source_index.html


+ 2 - 32
Shared/MainLayout.razor

@@ -1,5 +1,4 @@
-@using HyperCube.Models;
-@inherits LayoutComponentBase
+@inherits LayoutComponentBase
 <AuthorizeView>
     <Authorized>
         <div class="wrap">
@@ -7,39 +6,10 @@
             <div class="main-content">
                 @Body
                 <Footer />
-            </div>
+            </div>    
         </div>
     </Authorized>
     <NotAuthorized>
         @Body
     </NotAuthorized>
 </AuthorizeView>
-
-@code {
-    List<string> Networks = new();
-    bool connected = false;
-
-    protected override async Task OnInitializedAsync()
-    {
-        //try
-        //{
-        //    //await Blockchain.GetInstance().Initialize();
-        //    Console.WriteLine("OnInitializedAsync RegisterNetworks");
-        //    await Blockchain.RegisterNetworks();
-        //    //if (Blockchain.Connected != "" && Blockchain.Connected != "none")
-        //    //{
-        //    //    connected = true;
-        //    //    Networks.Add(Blockchain.Connected);
-        //    //}
-        //    //else
-        //    //{
-        //    //    connected = false;
-        //    //    Networks.Add("Blockchain not connected");
-        //    //}
-        //}
-        //catch (Exception e)
-        //{
-        //    Console.WriteLine(e.Message + ", stack trace:" + e.StackTrace);
-        //}
-    }
-}