Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
Njust.Pdf.Analysis.V4.5
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶然
Njust.Pdf.Analysis.V4.5
Commits
b0c4f975
Commit
b0c4f975
authored
Oct 08, 2021
by
陶然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
2a2b5a49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
33 deletions
+100
-33
AnalyseExtension.cs
Src/Extensions/AnalyseExtension.cs
+21
-12
AnalyseFeature.cs
Src/Features/AnalyseFeature.cs
+11
-10
AssemblyInfo.cs
Src/Properties/AssemblyInfo.cs
+1
-1
RestfulAnalyse.cs
Src/Tranforms/RestfulAnalyse.cs
+67
-10
No files found.
Src/Extensions/AnalyseExtension.cs
View file @
b0c4f975
...
...
@@ -27,29 +27,38 @@ namespace Njust.Pdf.Analysis
rtns
=
stringBuilder
.
ToString
();
return
rtns
;
}
public
static
string
AutoAnalyse
(
string
text
,
TemplateDetail
templateDetail
)
public
static
string
AutoAnalyse
(
this
AnalyseAll
analyse
,
TemplateDetail
templateDetail
)
{
var
rtns
=
string
.
Empty
;
if
(
templateDetail
==
null
)
return
rtns
;
var
text
=
analyse
.
Allbody
;
//不是英文才会去掉空格
Match
mInfo
=
Regex
.
Match
(
templateDetail
.
BeginKeyword
,
@"^[A-Za-z]+$"
);
//str.matches("[a-zA-Z]+")
if
(!
mInfo
.
Success
)
text
=
text
.
Replace
(
" "
,
""
);
int
beginIndex
=
text
.
IndexOf
(
templateDetail
.
BeginKeyword
);
int
endIndex
=
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
;
if
(!
string
.
IsNullOrEmpty
(
templateDetail
.
EndKeyword
))
try
{
endIndex
=
text
.
IndexOf
(
templateDetail
.
EndKeyword
);
int
beginIndex
=
text
.
IndexOf
(
templateDetail
.
BeginKeyword
);
int
endIndex
=
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
;
if
(!
string
.
IsNullOrEmpty
(
templateDetail
.
EndKeyword
))
{
if
(
templateDetail
.
EndKeyword
==
"null"
)
endIndex
=
text
.
Length
;
else
endIndex
=
text
.
IndexOf
(
templateDetail
.
EndKeyword
);
}
var
length
=
endIndex
-
beginIndex
-
templateDetail
.
BeginKeyword
.
Length
;
if
(
length
<=
0
)
{
rtns
=
text
.
Substring
(
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
);
int
index
=
rtns
.
IndexOf
(
"\n"
);
rtns
=
rtns
.
Substring
(
0
,
index
);
}
else
rtns
=
text
.
Substring
(
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
,
endIndex
-
beginIndex
-
templateDetail
.
BeginKeyword
.
Length
);
}
var
length
=
endIndex
-
beginIndex
-
templateDetail
.
BeginKeyword
.
Length
;
if
(
length
<=
0
)
catch
{
rtns
=
text
.
Substring
(
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
);
int
index
=
rtns
.
IndexOf
(
"\n"
);
rtns
=
rtns
.
Substring
(
0
,
index
);
}
else
rtns
=
text
.
Substring
(
beginIndex
+
templateDetail
.
BeginKeyword
.
Length
,
endIndex
-
beginIndex
-
templateDetail
.
BeginKeyword
.
Length
);
if
(
rtns
.
StartsWith
(
":"
))
rtns
=
rtns
.
Replace
(
":"
,
""
);
if
(
rtns
.
StartsWith
(
":"
))
rtns
=
rtns
.
Replace
(
":"
,
""
);
...
...
Src/Features/AnalyseFeature.cs
View file @
b0c4f975
using
Kivii
;
using
Njust.Pdf.Analysis.Entities
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
@@ -7,15 +8,15 @@ using System.Threading.Tasks;
namespace
Njust.Pdf.Analysis.Features
{
//public class AnalyseFeature : IPlugin,
IPreInitPlugin
//
{
//
public void Configure(IAppHost appHost)
//
{
// Kivii.PdfBox.Instance.Initialize
();
//
}
public
class
AnalyseFeature
:
IPlugin
,
IPreInitPlugin
{
public
void
Configure
(
IAppHost
appHost
)
{
KiviiContext
.
GetOpenedDbConnection
<
AnalyseAll
>
();
}
//
public void Register(IAppHost appHost)
//
{
//
}
//
}
public
void
Register
(
IAppHost
appHost
)
{
}
}
}
Src/Properties/AssemblyInfo.cs
View file @
b0c4f975
...
...
@@ -15,7 +15,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//[assembly:
AssemblyLoadFeature(typeof(AnalyseFeature))]
[assembly:
AssemblyLoadFeature(typeof(AnalyseFeature))]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
...
...
Src/Tranforms/RestfulAnalyse.cs
View file @
b0c4f975
...
...
@@ -28,6 +28,25 @@ namespace Njust.Pdf.Analysis.Tranforms
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
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
)]
...
...
@@ -118,8 +137,10 @@ namespace Njust.Pdf.Analysis.Tranforms
var
rtns
=
new
RestfulQueryResponse
<
Analyse
>();
rtns
.
Results
=
new
List
<
Analyse
>();
//调用平台功能 打开数据库连接
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Analyse
>();
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Analyse
All
>();
conn
.
InitEntityType
<
Template
>();
conn
.
InitEntityType
<
AnalyseAll
>();
var
template
=
conn
.
SingleById
<
Template
>(
TemplateKvid
);
var
preInserts
=
new
List
<
AnalyseAll
>();
...
...
@@ -146,6 +167,9 @@ namespace Njust.Pdf.Analysis.Tranforms
}
analyse
.
HashCode
=
hashCode
;
analyse
.
Kvid
=
analyseKvid
;
analyse
.
IsAnlysis
=
false
;
analyse
.
IsChecked
=
false
;
analyse
.
IsImaged
=
false
;
if
(
template
!=
null
)
{
analyse
.
TemplateKvid
=
template
.
Kvid
;
...
...
@@ -177,7 +201,25 @@ namespace Njust.Pdf.Analysis.Tranforms
}
try
{
var
authors
=
item
.
Author
.
Split
(
','
,
','
,
';'
,
';'
).
ToList
();
authors
.
RemoveAll
(
o
=>
o
.
IsNullOrEmpty
());
item
.
Author
=
string
.
Join
(
";"
,
authors
);
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
();
var
rtn
=
new
Analyse
();
rtn
.
PopulateWith
(
item
);
...
...
@@ -185,9 +227,9 @@ namespace Njust.Pdf.Analysis.Tranforms
stream
.
Position
=
0
;
KiviiContext
.
VirtualFiles
.
WriteFile
(
item
.
ImportPath
,
stream
);
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
continue
;
throw
ex
;
}
}
...
...
@@ -237,21 +279,36 @@ namespace Njust.Pdf.Analysis.Tranforms
exist
.
AddOnlyProperties
(
o
=>
o
.
TemplateKvid
);
exist
.
TemplateTitle
=
template
.
Title
;
exist
.
AddOnlyProperties
(
o
=>
o
.
TemplateTitle
);
exist
.
Title
=
AnalyseExtension
.
AutoAnalyse
(
exist
.
Allbody
,
template
.
GetTemplateDetail
(
"Title"
));
exist
.
Title
=
exist
.
Title
.
Replace
(
"\n"
,
""
).
Replace
(
"\r"
,
""
);
try
{
exist
.
Title
=
exist
.
Metadata
.
IsNullOrEmpty
()
?
string
.
Empty
:
exist
.
Metadata
[
"Title"
];
exist
.
Title
=
exist
.
Title
.
Replace
(
"\n"
,
""
).
Replace
(
"\r"
,
""
);
}
catch
{
exist
.
Title
=
string
.
Empty
;
}
exist
.
AddOnlyProperties
(
o
=>
o
.
Title
);
exist
.
Author
=
AnalyseExtension
.
AutoAnalyse
(
exist
.
Allbody
,
template
.
GetTemplateDetail
(
"Author"
));
exist
.
Author
=
exist
.
Author
.
Replace
(
"\n"
,
""
).
Replace
(
"\r"
,
""
);
try
{
exist
.
Author
=
exist
.
Metadata
.
IsNullOrEmpty
()
?
string
.
Empty
:
exist
.
Metadata
[
"Author"
];
exist
.
Author
=
exist
.
Author
.
Replace
(
"\n"
,
""
).
Replace
(
"\r"
,
""
);
}
catch
{
exist
.
Author
=
string
.
Empty
;
}
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
.
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
.
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
.
AddOnlyProperties
(
o
=>
o
.
Reference
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment