From c86fca8449b6d76f491f79ab4fca807213bb90a3 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Tue, 4 Aug 2026 07:42:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(client):=20=E5=85=A8=E9=9D=A2=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E7=AB=99=E5=90=8D=E6=A8=A1=E7=B3=8A=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=B7=B7=E6=8E=92=E5=85=B3=E9=94=AE=E8=AF=8D=E6=8F=90?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增 `Utils.getKeywords(text)`:自动提取所有关键信息: - 包含中划线的字母数字组合(如 CE-03) - 连续的字母数字(如 CRH01) - 中文字符串,并在提取时自动过滤掉“站台”、“轨道”、“号”、“线”等噪音词。 2. 将 `Utils.getKeywords` 的匹配逻辑集成至 `Utils.isFuzzyMatch` 的最终校验中,即使在 `Utils.getBaseName` 无法精确比较的情况下,也能通过核心关键字(特别是纯中文关键字)判断两者是否为同一站台。 3. 将列车在站判定(`isAtStation`)对未知列车的目的站比较逻辑统一切换为使用强化的 `Utils.isFuzzyMatch`,保证时刻表、列车站名、NBT、显示器等来源的中英文站名信息均能互相精准匹配。 --- station_broadcast.lua | 46 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index f30caf4..8b725ea 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -676,6 +676,33 @@ function Utils.getBaseName(name) return name:match("^%s*(.-)%s*$") end +function Utils.getKeywords(text) + if not text then return {} end + local s = tostring(text):lower() + + local keywords = {} + + for code in s:gmatch("[%a%d]+%-[%a%d]+") do + keywords[code] = true + end + for code in s:gmatch("%a+%d+") do + keywords[code] = true + end + + for zh in s:gmatch("[\128-\255]+") do + local cleanZh = zh:gsub("站台", ""):gsub("轨道", ""):gsub("号", ""):gsub("线", "") + if cleanZh and cleanZh ~= "" then + keywords[cleanZh] = true + end + end + + local list = {} + for k, _ in pairs(keywords) do + table.insert(list, k) + end + return list +end + function Utils.isFuzzyMatch(str, pattern) if not str or not pattern then return false end str = tostring(str):lower():match("^%s*(.-)%s*$") @@ -710,6 +737,17 @@ function Utils.isFuzzyMatch(str, pattern) return true end + -- 4. Extracted Keywords comparison (especially for Chinese + Code mixes) + local k1 = Utils.getKeywords(str) + local k2 = Utils.getKeywords(pattern) + for _, w1 in ipairs(k1) do + for _, w2 in ipairs(k2) do + if w1 == w2 or w1:find(w2, 1, true) or w2:find(w1, 1, true) then + return true + end + end + end + return false end @@ -2729,9 +2767,7 @@ function Main.loop() if State.currentTrain then if State.currentTrain.id == trainName then if trainName == "???" or trainName == "Unknown" or trainName == "" then - local currentDest = Utils.getBaseName(State.currentTrain.dest) - local nbtDest = Utils.getBaseName(destination) - if currentDest == nbtDest or currentDest:find(nbtDest, 1, true) or nbtDest:find(currentDest, 1, true) then + if Utils.isFuzzyMatch(State.currentTrain.dest, destination) then isAtStation = true end else @@ -2880,9 +2916,7 @@ function Main.loop() if State.currentTrain then if State.currentTrain.id == tName then if tName == "???" or tName == "Unknown" or tName == "" then - local currentDest = Utils.getBaseName(State.currentTrain.dest) - local nbtDest = Utils.getBaseName(dest) - if currentDest == nbtDest or currentDest:find(nbtDest, 1, true) or nbtDest:find(currentDest, 1, true) then + if Utils.isFuzzyMatch(State.currentTrain.dest, dest) then isAtStation = true end else