Commit b0c4f975 by 陶然

优化

parent 2a2b5a49
...@@ -27,20 +27,25 @@ namespace Njust.Pdf.Analysis ...@@ -27,20 +27,25 @@ namespace Njust.Pdf.Analysis
rtns = stringBuilder.ToString(); rtns = stringBuilder.ToString();
return rtns; return rtns;
} }
public static string AutoAnalyse(string text, TemplateDetail templateDetail) public static string AutoAnalyse(this AnalyseAll analyse, TemplateDetail templateDetail)
{ {
var rtns = string.Empty; var rtns = string.Empty;
if (templateDetail == null) return rtns; if (templateDetail == null) return rtns;
var text = analyse.Allbody;
//不是英文才会去掉空格 //不是英文才会去掉空格
Match mInfo = Regex.Match(templateDetail.BeginKeyword, @"^[A-Za-z]+$"); //str.matches("[a-zA-Z]+") Match mInfo = Regex.Match(templateDetail.BeginKeyword, @"^[A-Za-z]+$"); //str.matches("[a-zA-Z]+")
if (!mInfo.Success) text = text.Replace(" ", ""); if (!mInfo.Success) text = text.Replace(" ", "");
try
{
int beginIndex = text.IndexOf(templateDetail.BeginKeyword); int beginIndex = text.IndexOf(templateDetail.BeginKeyword);
int endIndex = beginIndex + templateDetail.BeginKeyword.Length; int endIndex = beginIndex + templateDetail.BeginKeyword.Length;
if (!string.IsNullOrEmpty(templateDetail.EndKeyword)) if (!string.IsNullOrEmpty(templateDetail.EndKeyword))
{ {
endIndex = text.IndexOf(templateDetail.EndKeyword); if (templateDetail.EndKeyword == "null") endIndex = text.Length;
else endIndex = text.IndexOf(templateDetail.EndKeyword);
} }
var length = endIndex - beginIndex - templateDetail.BeginKeyword.Length; var length = endIndex - beginIndex - templateDetail.BeginKeyword.Length;
if (length <= 0) if (length <= 0)
...@@ -50,6 +55,10 @@ namespace Njust.Pdf.Analysis ...@@ -50,6 +55,10 @@ namespace Njust.Pdf.Analysis
rtns = rtns.Substring(0, index); rtns = rtns.Substring(0, index);
} }
else rtns = text.Substring(beginIndex + templateDetail.BeginKeyword.Length, endIndex - beginIndex - templateDetail.BeginKeyword.Length); else rtns = text.Substring(beginIndex + templateDetail.BeginKeyword.Length, endIndex - beginIndex - templateDetail.BeginKeyword.Length);
}
catch
{
}
if (rtns.StartsWith(":")) rtns = rtns.Replace(":", ""); if (rtns.StartsWith(":")) rtns = rtns.Replace(":", "");
if (rtns.StartsWith(":")) rtns = rtns.Replace(":", ""); if (rtns.StartsWith(":")) rtns = rtns.Replace(":", "");
......
using Kivii; using Kivii;
using Njust.Pdf.Analysis.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -7,15 +8,15 @@ using System.Threading.Tasks; ...@@ -7,15 +8,15 @@ using System.Threading.Tasks;
namespace Njust.Pdf.Analysis.Features namespace Njust.Pdf.Analysis.Features
{ {
//public class AnalyseFeature : IPlugin,IPreInitPlugin public class AnalyseFeature : IPlugin, IPreInitPlugin
//{ {
// public void Configure(IAppHost appHost) public void Configure(IAppHost appHost)
// { {
// Kivii.PdfBox.Instance.Initialize(); KiviiContext.GetOpenedDbConnection<AnalyseAll>();
// } }
// public void Register(IAppHost appHost) public void Register(IAppHost appHost)
// { {
// } }
//} }
} }
...@@ -15,7 +15,7 @@ using System.Runtime.InteropServices; ...@@ -15,7 +15,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
//[assembly:AssemblyLoadFeature(typeof(AnalyseFeature))] [assembly: AssemblyLoadFeature(typeof(AnalyseFeature))]
// 将 ComVisible 设置为 false 会使此程序集中的类型 // 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
......
...@@ -28,6 +28,25 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -28,6 +28,25 @@ namespace Njust.Pdf.Analysis.Tranforms
[RequiresAnyRole(SystemRoles.Everyone)] [RequiresAnyRole(SystemRoles.Everyone)]
public class AnalyseDelete : RestfulDelete<Analyse> public class AnalyseDelete : RestfulDelete<Analyse>
{ {
public override bool OnPostRestfulDelete(IRequest req, IResponse res, System.Data.IDbConnection dbConnection, IRestfulDeleteResponse<Analyse> rtns)
{
var updateAuthors = dbConnection.From<Author>();
updateAuthors=updateAuthors.Update(o => o.Status);
updateAuthors=updateAuthors.Where(o => Sql.In(o.AnalyseKvid, Kvids));
dbConnection.UpdateOnly(new Author { Status = -1 }, updateAuthors);
var updateKeywords = dbConnection.From<Keyword>();
updateKeywords = updateKeywords.Update(o => o.Status);
updateKeywords = updateKeywords.Where(o => Sql.In(o.AnalyseKvid, Kvids));
dbConnection.UpdateOnly(new Keyword { Status = -1 }, updateKeywords);
var updateOrgans = dbConnection.From<Organ>();
updateOrgans = updateOrgans.Update(o => o.Status);
updateOrgans = updateOrgans.Where(o => Sql.In(o.AnalyseKvid, Kvids));
dbConnection.UpdateOnly(new Organ { Status = -1 }, updateOrgans);
return base.OnPostRestfulDelete(req, res, dbConnection, rtns);
}
} }
[RequiresAnyRole(SystemRoles.Everyone)] [RequiresAnyRole(SystemRoles.Everyone)]
...@@ -118,8 +137,10 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -118,8 +137,10 @@ namespace Njust.Pdf.Analysis.Tranforms
var rtns = new RestfulQueryResponse<Analyse>(); var rtns = new RestfulQueryResponse<Analyse>();
rtns.Results = new List<Analyse>(); rtns.Results = new List<Analyse>();
//调用平台功能 打开数据库连接 //调用平台功能 打开数据库连接
var conn = KiviiContext.GetOpenedDbConnection<Analyse>(); var conn = KiviiContext.GetOpenedDbConnection<AnalyseAll>();
conn.InitEntityType<Template>();
conn.InitEntityType<AnalyseAll>();
var template = conn.SingleById<Template>(TemplateKvid); var template = conn.SingleById<Template>(TemplateKvid);
var preInserts = new List<AnalyseAll>(); var preInserts = new List<AnalyseAll>();
...@@ -146,6 +167,9 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -146,6 +167,9 @@ namespace Njust.Pdf.Analysis.Tranforms
} }
analyse.HashCode = hashCode; analyse.HashCode = hashCode;
analyse.Kvid = analyseKvid; analyse.Kvid = analyseKvid;
analyse.IsAnlysis = false;
analyse.IsChecked = false;
analyse.IsImaged = false;
if (template != null) if (template != null)
{ {
analyse.TemplateKvid = template.Kvid; analyse.TemplateKvid = template.Kvid;
...@@ -177,7 +201,25 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -177,7 +201,25 @@ namespace Njust.Pdf.Analysis.Tranforms
} }
try try
{ {
var authors = item.Author.Split(',', ',', ';', ';').ToList();
authors.RemoveAll(o => o.IsNullOrEmpty());
item.Author = string.Join(";", authors);
conn.Insert(item); conn.Insert(item);
#region Author
if (!item.Author.IsNullOrEmpty())
{
foreach (var auth in authors)
{
var author = new Author();
author.Name = auth;
author.DomainName = item.DomainName;
author.Language = item.Language;
author.AnalyseKvid = item.Kvid;
conn.Insert(author);
}
}
#endregion
item.RemoveAllOnlyProperties(); item.RemoveAllOnlyProperties();
var rtn = new Analyse(); var rtn = new Analyse();
rtn.PopulateWith(item); rtn.PopulateWith(item);
...@@ -185,9 +227,9 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -185,9 +227,9 @@ namespace Njust.Pdf.Analysis.Tranforms
stream.Position = 0; stream.Position = 0;
KiviiContext.VirtualFiles.WriteFile(item.ImportPath, stream); KiviiContext.VirtualFiles.WriteFile(item.ImportPath, stream);
} }
catch(Exception ex) catch (Exception ex)
{ {
continue; throw ex;
} }
} }
...@@ -237,21 +279,36 @@ namespace Njust.Pdf.Analysis.Tranforms ...@@ -237,21 +279,36 @@ namespace Njust.Pdf.Analysis.Tranforms
exist.AddOnlyProperties(o => o.TemplateKvid); exist.AddOnlyProperties(o => o.TemplateKvid);
exist.TemplateTitle = template.Title; exist.TemplateTitle = template.Title;
exist.AddOnlyProperties(o => o.TemplateTitle); exist.AddOnlyProperties(o => o.TemplateTitle);
exist.Title = AnalyseExtension.AutoAnalyse(exist.Allbody, template.GetTemplateDetail("Title")); try
{
exist.Title = exist.Metadata.IsNullOrEmpty() ? string.Empty : exist.Metadata["Title"];
exist.Title = exist.Title.Replace("\n", "").Replace("\r", ""); exist.Title = exist.Title.Replace("\n", "").Replace("\r", "");
}
catch
{
exist.Title = string.Empty;
}
exist.AddOnlyProperties(o => o.Title); exist.AddOnlyProperties(o => o.Title);
exist.Author = AnalyseExtension.AutoAnalyse(exist.Allbody, template.GetTemplateDetail("Author")); try
{
exist.Author = exist.Metadata.IsNullOrEmpty() ? string.Empty : exist.Metadata["Author"];
exist.Author = exist.Author.Replace("\n", "").Replace("\r", ""); exist.Author = exist.Author.Replace("\n", "").Replace("\r", "");
}
catch
{
exist.Author = string.Empty;
}
exist.AddOnlyProperties(o => o.Author); exist.AddOnlyProperties(o => o.Author);
exist.Keywords = AnalyseExtension.AutoAnalyse(exist.Allbody, template.GetTemplateDetail("Keywords")); exist.Keywords = exist.AutoAnalyse(template.GetTemplateDetail("Keywords"));
exist.Keywords = exist.Keywords.Replace("\n", "").Replace("\r", ""); exist.Keywords = exist.Keywords.Replace("\n", "").Replace("\r", "");
exist.AddOnlyProperties(o => o.Keywords); exist.AddOnlyProperties(o => o.Keywords);
exist.Abstract = AnalyseExtension.AutoAnalyse(exist.Allbody, template.GetTemplateDetail("Abstract")); exist.Abstract = exist.AutoAnalyse(template.GetTemplateDetail("Abstract"));
exist.Abstract = exist.Abstract.Replace("\n", "").Replace("\r", ""); exist.Abstract = exist.Abstract.Replace("\n", "").Replace("\r", "");
exist.AddOnlyProperties(o => o.Abstract); exist.AddOnlyProperties(o => o.Abstract);
exist.Reference = AnalyseExtension.AutoAnalyse(exist.Allbody, template.GetTemplateDetail("Reference")); exist.Reference = exist.AutoAnalyse(template.GetTemplateDetail("Reference"));
exist.Reference = exist.Reference.Replace("\n", "").Replace("\r", ""); exist.Reference = exist.Reference.Replace("\n", "").Replace("\r", "");
exist.AddOnlyProperties(o => o.Reference); exist.AddOnlyProperties(o => o.Reference);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment