Blame view

tests/test_style_intent.py 1.12 KB
cda1cd62   tangwang   意图分析&应用 baseline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  from types import SimpleNamespace
  
  from config import QueryConfig
  from query.style_intent import StyleIntentDetector, StyleIntentRegistry
  
  
  def test_style_intent_detector_matches_original_and_translated_queries():
      query_config = QueryConfig(
          style_intent_terms={
              "color": [["black", "黑色", "black"]],
              "size": [["xl", "x-large", "加大码"]],
          },
          style_intent_dimension_aliases={
              "color": ["color", "颜色"],
              "size": ["size", "尺码"],
          },
      )
      detector = StyleIntentDetector(
          StyleIntentRegistry.from_query_config(query_config),
          tokenizer=lambda text: text.split(),
      )
  
      parsed_query = SimpleNamespace(
          original_query="黑色 连衣裙",
          query_normalized="黑色 连衣裙",
          rewritten_query="黑色 连衣裙",
          translations={"en": "black dress xl"},
      )
  
      profile = detector.detect(parsed_query)
  
      assert profile.is_active is True
      assert profile.get_canonical_values("color") == {"black"}
      assert profile.get_canonical_values("size") == {"xl"}
      assert len(profile.query_variants) == 2