Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
LAE
Overview
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
文靖昊
LAE
Commits
d1bc8007
Commit
d1bc8007
authored
9 months ago
by
文靖昊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重写地区识别模糊匹配
parent
2a0c9663
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
9 deletions
+33
-9
code.py
src/agent/code.py
+33
-9
No files found.
src/agent/code.py
View file @
d1bc8007
...
...
@@ -91,9 +91,14 @@ class AreaCodeTool:
# 模糊匹配
if
not
results
:
mask
=
self
.
df
[
'name'
]
.
str
.
contains
(
area_name
,
na
=
False
)
matches
=
self
.
df
[
mask
]
results
.
extend
([(
row
[
'name'
],
row
[
'code'
])
for
_
,
row
in
matches
.
iterrows
()])
for
name
in
self
.
full_name_map
.
keys
():
if
self
.
is_subsequence
(
name
,
area_name
):
results
.
append
((
area_name
,
self
.
full_name_map
[
name
]))
return
results
# mask = self.df['name'].str.contains(area_name, na=False)
# matches = self.df[mask]
# results.extend([(row['name'], row['code']) for _, row in matches.iterrows()])
return
results
...
...
@@ -113,18 +118,37 @@ class AreaCodeTool:
return
matches
.
iloc
[
0
][
'name'
]
return
None
def
is_subsequence
(
self
,
source
,
target
):
# 初始化两个索引,分别指向源字符串和目标字符串的开头
source_index
=
0
target_index
=
0
# 遍历源字符串,直到找到目标字符串的所有字符或者遍历完源字符串
while
source_index
<
len
(
source
)
and
target_index
<
len
(
target
):
# 如果当前源字符串的字符等于目标字符串的字符,则移动目标字符串的索引
if
source
[
source_index
]
==
target
[
target_index
]:
target_index
+=
1
# 无论是否匹配,都移动源字符串的索引
source_index
+=
1
# 如果目标字符串的索引已经遍历完,说明找到了完整的子序列
return
target_index
==
len
(
target
)
# 使用示例
def
example_usage
():
tool
=
AreaCodeTool
()
# 测试不同类型的查询
test_cases
=
[
"安徽省"
,
"安庆市"
,
"迎江区"
,
"安徽省安庆市"
,
"安徽省安庆市迎江区"
,
"安庆"
# 模糊查询
"贵州省"
,
"贵阳市"
,
"云岩区"
,
"贵州省贵阳市"
,
"贵州省贵阳市南明区"
,
"贵阳"
,
# 模糊查询
"贵州贵阳"
,
# 模糊查询
"贵州贵阳南明"
,
# 模糊查询
"贵州贵阳市南明"
,
# 模糊查询
]
for
query
in
test_cases
:
...
...
This diff is collapsed.
Click to expand it.
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