File size: 5,650 Bytes
ab2012f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import re
from typing import List
from config import COLOR_HARMONY, CLOTHING_TYPES

def extract_clothing_info(text: str) -> dict:
    text_lower = text.lower()
    
    colors = list(COLOR_HARMONY.keys())
    found_color = None
    for color in colors:
        if color in text_lower:
            found_color = color
            break
    
    found_types = []
    for clothing_type in CLOTHING_TYPES:
        if clothing_type in text_lower:
            found_types.append(clothing_type)
    
    existing_item = None
    requested_item = None
    
    question_patterns = ["what kind of", "what", "which", "suggest", "recommend"]
    is_question = any(pattern in text_lower for pattern in question_patterns)
    
    if is_question and len(found_types) > 0:
        if "my" in text_lower or "i have" in text_lower or "i'm wearing" in text_lower:
            for i, word in enumerate(text_lower.split()):
                if word == "my" and i + 1 < len(text_lower.split()):
                    next_words = " ".join(text_lower.split()[i+1:i+4])
                    for ct in found_types:
                        if ct in next_words:
                            existing_item = ct
                            break
                if existing_item:
                    break
        
        for ct in found_types:
            if "match" in text_lower or "go with" in text_lower or "pair" in text_lower:
                ct_pos = text_lower.find(ct)
                match_pos = text_lower.find("match")
                if ct_pos > match_pos or "what kind of" in text_lower[:ct_pos]:
                    requested_item = ct
                    break
    
    if not existing_item and not requested_item and found_types:
        if is_question:
            requested_item = found_types[0]
        else:
            existing_item = found_types[0]
    
    return {
        "color": found_color,
        "type": existing_item or requested_item,
        "existing_item": existing_item,
        "requested_item": requested_item,
        "is_question": is_question,
        "raw_text": text
    }

def get_color_matches(color: str) -> List[str]:
    color_lower = color.lower()
    return COLOR_HARMONY.get(color_lower, ["white", "black", "grey", "beige"])

def extract_colors_from_query(query: str) -> tuple:
    query_lower = query.lower()
    colors = list(COLOR_HARMONY.keys())
    
    extended_colors = ["navy blue", "wine", "burgundy", "maroon", "crimson", "scarlet", "mauve", "taupe", "olive", "teal", "turquoise", "indigo", "cobalt"]
    all_colors = extended_colors + colors
    
    color_mapping = {
        "wine": "red", "burgundy": "red", "maroon": "red",
        "mauve": "purple", "taupe": "beige", "olive": "green",
        "teal": "blue", "turquoise": "blue", "indigo": "navy", "cobalt": "blue",
        "navy blue": "navy"
    }
    
    found_colors = []
    seen_mapped = set()
    for color in all_colors:
        if color in query_lower:
            mapped = color_mapping.get(color, color)
            if mapped not in seen_mapped:
                found_colors.append((color, mapped))
                seen_mapped.add(mapped)
    
    return found_colors

def detect_query_type(message: str) -> str:
    message_lower = message.lower()
    
    color_comparison_patterns = ["does", "do", "will", "can"]
    comparison_keywords = ["go with", "match", "work with", "pair with", "combine with"]
    color_suggestion_patterns = ["what color", "which color", "colors go with", "colors match", "better color", "color to match"]
    
    has_two_colors = len(extract_colors_from_query(message)) >= 2
    
    if any(pattern in message_lower for pattern in color_comparison_patterns) and any(kw in message_lower for kw in comparison_keywords) and has_two_colors:
        return "color_compatibility"
    
    outfit_request_patterns = ["suggest", "recommend", "outfit", "wear", "dress", "thinking of", "what should i wear", "what can i wear", "what to wear"]
    what_matches_patterns = ["what will go", "what goes with", "what matches", "what will match", "what can go"]
    
    if any(pattern in message_lower for pattern in what_matches_patterns) and any(item in message_lower for item in CLOTHING_TYPES):
        return "outfit_suggestion"
    
    if any(pattern in message_lower for pattern in outfit_request_patterns):
        return "outfit_suggestion"
    
    if any(pattern in message_lower for pattern in color_suggestion_patterns):
        return "color_suggestion"
    
    if any(ct in message_lower for ct in CLOTHING_TYPES) and any(c in message_lower for c in ["with", "match", "go", "pair", "style", "stylish", "look"]):
        return "outfit_suggestion"
    
    if len(extract_colors_from_query(message)) > 0 and any(word in message_lower for word in ["match", "with", "go", "pair"]):
        return "color_suggestion"
    
    if any(ct in message_lower for ct in CLOTHING_TYPES):
        return "outfit_suggestion"
    
    return "outfit_suggestion"

def is_greeting(message: str) -> bool:
    message_lower = message.lower().strip()
    greetings = [
        "hello", "hi", "hey", "good morning", "good afternoon", "good evening",
        "greetings", "howdy", "what's up", "whats up", "sup", "yo"
    ]
    return any(message_lower.startswith(g) or message_lower == g for g in greetings)

def is_name_question(message: str) -> bool:
    message_lower = message.lower().strip()
    name_patterns = [
        "what is your name", "what's your name", "whats your name",
        "who are you", "what are you", "tell me your name", "your name"
    ]
    return any(pattern in message_lower for pattern in name_patterns)