统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
@@ -45,6 +45,21 @@ def _exact_spans(question, name):
|
||||
return spans
|
||||
|
||||
|
||||
def _prefix_right_boundary(text, end):
|
||||
"""Require a product-like boundary after a partial catalog name."""
|
||||
if end == len(text):
|
||||
return True
|
||||
char = text[end]
|
||||
if _WORD.fullmatch(char):
|
||||
return False
|
||||
if char.isspace() or unicodedata.category(char)[0] != 'L':
|
||||
return True
|
||||
# Chinese product names are not separated by spaces. Accept common query
|
||||
# particles/quality terms after a mentioned product, while rejecting an
|
||||
# arbitrary continuation of the product name itself.
|
||||
return bool(re.match(r'(?:的|之|为|是|规格|型号|产品|黑片|亮片|合格率|良率|报废|不良|重量|投入|趋势|排名|变化|质量|情况)', text[end:]))
|
||||
|
||||
|
||||
def identify_products(question, options, *, limit=20, respect_exclusions=False):
|
||||
"""Return explicit names and exact-dimension candidates, bounded for planning.
|
||||
|
||||
@@ -82,14 +97,53 @@ def identify_products(question, options, *, limit=20, respect_exclusions=False):
|
||||
exact = {name: spans for name, value in normalized_names.items()
|
||||
if (spans := [(start, end) for start, end in _exact_spans(text, value)
|
||||
if not is_other_field_value(start, end)])}
|
||||
exact_spans = [span for spans in exact.values() for span in spans]
|
||||
dimensional = {}
|
||||
for name, value in normalized_names.items():
|
||||
for match in _DIMENSIONS.finditer(value):
|
||||
dimensional.setdefault(_dimension_key(match.group()), set()).add(name)
|
||||
|
||||
# A boundary-delimited prefix can still name more than one authorized
|
||||
# product (for example, "合成产品0" with catalog entries 01..06). Treat
|
||||
# that as a candidate set, never as a product filter. Prefer the longest
|
||||
# prefix at each position and keep it inside the caller-provided catalog.
|
||||
prefix_names = {}
|
||||
max_prefix_length = 0
|
||||
for name, value in normalized_names.items():
|
||||
for length in range(3, min(len(value), len(text) + 1)):
|
||||
prefix = value[:length]
|
||||
if prefix.isdigit():
|
||||
continue
|
||||
prefix_names.setdefault(prefix, set()).add(name)
|
||||
max_prefix_length = max(max_prefix_length, length)
|
||||
dimension_spans = [match.span() for match in _DIMENSIONS.finditer(text)
|
||||
if not is_other_field_value(*match.span())]
|
||||
prefix_by_span = {}
|
||||
for start in range(len(text)):
|
||||
upper = min(len(text), start + max_prefix_length)
|
||||
for end in range(upper, start + 2, -1):
|
||||
if (start and _WORD.fullmatch(text[start - 1])) or (end < len(text) and _WORD.fullmatch(text[end])):
|
||||
continue
|
||||
if not _prefix_right_boundary(text, end):
|
||||
continue
|
||||
if is_other_field_value(start, end):
|
||||
continue
|
||||
if any(left <= start and end <= right for left, right in exact_spans + dimension_spans):
|
||||
continue
|
||||
candidates = prefix_names.get(text[start:end])
|
||||
if candidates:
|
||||
prefix_by_span[(start, end)] = candidates
|
||||
break
|
||||
|
||||
mentions = []
|
||||
full_candidates_by_span = {}
|
||||
excluded_names = set()
|
||||
def exclusion_for_span(start):
|
||||
prefix = re.split(r'[,,。;;!?!?]', text[:start])[-1]
|
||||
tail = r'(?:的|规格|尺寸|产品|为|是|:|:){0,6}$'
|
||||
return bool(respect_exclusions and re.search(
|
||||
r'(?:不要包含|不要包括|不包含|不包括|不计入|不要看|不看|排除|剔除|去除)'+tail,prefix)
|
||||
and not re.search(r'(?:不要|不用|不再|取消)(?:排除|剔除|去除)'+tail,prefix))
|
||||
for match in _DIMENSIONS.finditer(text):
|
||||
if is_other_field_value(match.start(), match.end()):
|
||||
continue
|
||||
@@ -104,11 +158,7 @@ def identify_products(question, options, *, limit=20, respect_exclusions=False):
|
||||
status = ('exact' if len(chosen) == 1 else 'unique' if not chosen and len(candidates) == 1 else
|
||||
'ambiguous' if candidates else 'none')
|
||||
end = match.end() + (len(suffix.group()) if suffix else 0)
|
||||
prefix = re.split(r'[,,。;;!?!?]',text[:match.start()])[-1]
|
||||
tail = r'(?:的|规格|尺寸|产品|为|是|:|:){0,6}$'
|
||||
excluded = bool(respect_exclusions and re.search(
|
||||
r'(?:不要包含|不要包括|不包含|不包括|不计入|不要看|不看|排除|剔除|去除)'+tail,prefix)
|
||||
and not re.search(r'(?:不要|不用|不再|取消)(?:排除|剔除|去除)'+tail,prefix))
|
||||
excluded = exclusion_for_span(match.start())
|
||||
if excluded: excluded_names.update(candidates)
|
||||
full_candidates_by_span[(match.start(),end)] = candidates
|
||||
mentions.append({'query': text[match.start():end], 'normalizedSpan': [match.start(), end],
|
||||
@@ -116,6 +166,18 @@ def identify_products(question, options, *, limit=20, respect_exclusions=False):
|
||||
'candidateCount': len(candidates), 'truncated': len(candidates) > limit,
|
||||
**({'intent':'exclude'} if excluded else {})})
|
||||
|
||||
for (start, end), candidate_set in sorted(prefix_by_span.items()):
|
||||
candidates = sorted(candidate_set)
|
||||
excluded = exclusion_for_span(start)
|
||||
if excluded:
|
||||
excluded_names.update(candidates)
|
||||
full_candidates_by_span[(start, end)] = candidates
|
||||
mentions.append({'query': text[start:end], 'normalizedSpan': [start, end],
|
||||
'status': 'ambiguous' if len(candidates) > 1 else 'unique',
|
||||
'candidates': records(candidates), 'candidateCount': len(candidates),
|
||||
'truncated': len(candidates) > limit, 'matchType': 'catalog_prefix',
|
||||
**({'intent':'exclude'} if excluded else {})})
|
||||
|
||||
if respect_exclusions:
|
||||
positive = []
|
||||
for mention in mentions:
|
||||
|
||||
Reference in New Issue
Block a user