Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ccran
/
lufa-contract
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5a0ce740
authored
Jul 21, 2026
by
ccran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add memory export filter;
parent
2708fc78
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
2 deletions
+48
-2
core/config.py
+1
-0
core/memory.py
+9
-2
core/tools/memory_export_filter.py
+38
-0
data/rules.xlsx
+0
-0
No files found.
core/config.py
View file @
5a0ce740
...
@@ -39,6 +39,7 @@ FULL_TEXT_SEGMENT_ID = -1
...
@@ -39,6 +39,7 @@ FULL_TEXT_SEGMENT_ID = -1
## 规则集ID列表,需与rules.xlsx中的sheet名称保持一致!!!
## 规则集ID列表,需与rules.xlsx中的sheet名称保持一致!!!
ALL_RULESET_IDS
=
[
ALL_RULESET_IDS
=
[
"通用"
,
"通用"
,
"通用 (新)"
,
"借款"
,
"借款"
,
"担保"
,
"担保"
,
"财务口"
,
"财务口"
,
...
...
core/memory.py
View file @
5a0ce740
...
@@ -13,6 +13,7 @@ from utils.http_util import upload_file
...
@@ -13,6 +13,7 @@ from utils.http_util import upload_file
from
utils.doc_util
import
DocBase
from
utils.doc_util
import
DocBase
from
core.config
import
META_KEY
,
FILE_SUFFIX
,
use_lufa
from
core.config
import
META_KEY
,
FILE_SUFFIX
,
use_lufa
from
core.finding_preprocessor
import
FindingPreprocessor
from
core.finding_preprocessor
import
FindingPreprocessor
from
core.tools.memory_export_filter
import
MemoryExportFilter
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -84,6 +85,7 @@ class MemoryStore:
...
@@ -84,6 +85,7 @@ class MemoryStore:
self
.
merge_facts
:
List
[
Dict
[
str
,
Any
]]
=
[]
self
.
merge_facts
:
List
[
Dict
[
str
,
Any
]]
=
[]
self
.
findings
:
Dict
[
str
,
List
[
Finding
]]
=
{}
self
.
findings
:
Dict
[
str
,
List
[
Finding
]]
=
{}
self
.
_finding_preprocessor
=
FindingPreprocessor
()
self
.
_finding_preprocessor
=
FindingPreprocessor
()
self
.
_export_filter
=
MemoryExportFilter
()
self
.
_load
()
self
.
_load
()
# ---------------------- facts ----------------------
# ---------------------- facts ----------------------
...
@@ -333,7 +335,10 @@ class MemoryStore:
...
@@ -333,7 +335,10 @@ class MemoryStore:
(
"suggestion"
,
"建议"
),
(
"suggestion"
,
"建议"
),
]
]
grouped_items
=
list
(
self
.
findings
.
items
())
grouped_items
=
[
(
key
,
self
.
_export_filter
.
filter_findings
(
values
))
for
key
,
values
in
self
.
findings
.
items
()
]
if
grouped_items
:
if
grouped_items
:
first_key
,
first_values
=
grouped_items
[
0
]
first_key
,
first_values
=
grouped_items
[
0
]
ws_first
=
wb
.
active
ws_first
=
wb
.
active
...
@@ -456,7 +461,9 @@ class MemoryStore:
...
@@ -456,7 +461,9 @@ class MemoryStore:
target_key
=
self
.
_normalize_finding_key
(
finding_key
)
target_key
=
self
.
_normalize_finding_key
(
finding_key
)
with
self
.
_lock
:
with
self
.
_lock
:
target_findings
=
list
(
self
.
_get_findings_bucket
(
target_key
))
target_findings
=
self
.
_export_filter
.
filter_findings
(
self
.
_get_findings_bucket
(
target_key
)
)
comments
:
List
[
Dict
[
str
,
Any
]]
=
[]
comments
:
List
[
Dict
[
str
,
Any
]]
=
[]
for
idx
,
f
in
enumerate
(
target_findings
,
start
=
1
):
for
idx
,
f
in
enumerate
(
target_findings
,
start
=
1
):
segment_id
=
int
(
f
.
segment_id
or
0
)
segment_id
=
int
(
f
.
segment_id
or
0
)
...
...
core/tools/memory_export_filter.py
0 → 100644
View file @
5a0ce740
from
__future__
import
annotations
from
collections.abc
import
Iterable
,
Mapping
from
typing
import
Any
,
List
,
Optional
,
TypeVar
FindingType
=
TypeVar
(
"FindingType"
)
class
MemoryExportFilter
:
"""Filter findings from an export without changing the memory store."""
DEFAULT_EXCLUDED_TITLES
=
frozenset
({
"通用审查"
})
def
__init__
(
self
,
excluded_titles
:
Optional
[
Iterable
[
str
]]
=
None
)
->
None
:
titles
=
(
self
.
DEFAULT_EXCLUDED_TITLES
if
excluded_titles
is
None
else
excluded_titles
)
self
.
_excluded_titles
=
{
str
(
title
)
.
strip
()
for
title
in
titles
if
str
(
title
)
.
strip
()
}
def
filter_findings
(
self
,
findings
:
Iterable
[
FindingType
])
->
List
[
FindingType
]:
return
[
finding
for
finding
in
findings
if
self
.
should_export
(
finding
)]
def
should_export
(
self
,
finding
:
Any
)
->
bool
:
rule_title
=
self
.
_get_rule_title
(
finding
)
.
strip
()
return
rule_title
not
in
self
.
_excluded_titles
@staticmethod
def
_get_rule_title
(
finding
:
Any
)
->
str
:
if
isinstance
(
finding
,
Mapping
):
rule_title
=
finding
.
get
(
"rule_title"
)
or
""
else
:
rule_title
=
getattr
(
finding
,
"rule_title"
,
""
)
return
str
(
rule_title
)
data/rules.xlsx
View file @
5a0ce740
No preview for this file type
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