File size: 3,806 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
4552666
63bcd5a
 
4552666
63bcd5a
 
4552666
63bcd5a
 
4552666
63bcd5a
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
4552666
63bcd5a
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
6459fd1
 
63bcd5a
6459fd1
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import re
from typing import List

GENERIC_PATTERNS = [
    "dashboard",
    "login",
    "signup",
    "authentication",
    "admin panel",
    "analytics system",
    "analytics platform",
    "management system",
    "tracking system",
    "monitoring system",
    "ai module",
    "smart system",
    "web platform",
    "mobile app",
    "website",
    "reports page",
    "user management"
]

BAD_STARTS = [
    "here are",
    "below are",
    "these are",
    "the following",
    "project ideas",
    "features include"
]

LOW_VALUE_WORDS = [
    "system",
    "platform",
    "application",
    "website",
    "solution"
]

def clean_text(text: str) -> str:

    if not text:
        return ""

    text = str(text).strip()

    
    text = re.sub(r"^\d+[\)\.\-\s]+", "", text)

    
    text = re.sub(r"^[\-\*\•\→\▪\s]+", "", text)

    
    text = text.replace("**", "")

    
    text = text.replace('"', "").replace("'", "")

    
    text = re.sub(r"\(.*?\)", "", text)

    
    if ":" in text and len(text.split()) > 6:
        text = text.split(":")[0]

    
    text = re.sub(r"^(assistant|bot)\s*[:\-]\s*", "", text, flags=re.I)

    
    text = re.sub(r"[.,\-:;]+$", "", text)

    
    text = re.sub(r"\s+", " ", text).strip()

    return text

def normalize_key(text: str) -> str:

    text = text.lower()

    text = re.sub(r"[^a-z0-9\s]", "", text)

    text = re.sub(r"\s+", " ", text).strip()

    return text

def is_generic(text: str) -> bool:

    low = normalize_key(text)

    for pattern in GENERIC_PATTERNS:
        if pattern in low:
            return True

    return False

def is_low_quality(text: str) -> bool:

    low = normalize_key(text)

    words = low.split()

    
    if len(words) < 3:
        return True

    
    if len(words) > 12:
        return True

    
    if any(low.startswith(x) for x in BAD_STARTS):
        return True

    
    weak_count = sum(
        1 for w in words
        if w in LOW_VALUE_WORDS
    )

    if weak_count >= len(words) / 2:
        return True

    return False

def is_valid_item(text: str) -> bool:

    if not text:
        return False

    
    if is_generic(text):
        return False

    
    if is_low_quality(text):
        return False

    return True

def filter_items(items: List[str]) -> List[str]:

    final = []

    seen = set()

    for item in items:

        text = clean_text(item)

        if not text:
            continue

        if not is_valid_item(text):
            continue

        key = normalize_key(text)

        
        if key in seen:
            continue

        
        duplicate = False

        for old in seen:

            
            overlap = set(key.split()) & set(old.split())

            if len(overlap) >= max(2, min(len(key.split()), len(old.split())) - 1):
                duplicate = True
                break

        if duplicate:
            continue

        seen.add(key)

        final.append(text)

    return final

def smart_split(text: str) -> List[str]:

    if not text:
        return []

    text = text.replace("\r", "\n")

    lines = []

    for line in text.split("\n"):

        line = line.strip()

        if not line:
            continue

        
        parts = re.split(r"\d+[\.\)]\s*", line)

        for p in parts:

            p = p.strip()

            if not p:
                continue

            # Remove leading bullets or hyphens instead of splitting the whole string
            p = re.sub(r"^[-•▪*]\s*", "", p).strip()

            if p:
                lines.append(p)

    return lines

def validate_generated_list(
    text: str,
    top_k: int = 10
) -> List[str]:

    if not text:
        return []

    raw_items = smart_split(text)

    cleaned = filter_items(raw_items)

    return cleaned[:top_k]