Substring match with word-boundary filtering. e.g. "RTX 3060" should match "GeForce RTX 3060 12 GB" but NOT "GeForce RTX 3060 Ti".
(db, name: str)
| 130 | |
| 131 | |
| 132 | def _substring_search(db, name: str): |
| 133 | """Substring match with word-boundary filtering. |
| 134 | |
| 135 | e.g. "RTX 3060" should match "GeForce RTX 3060 12 GB" but NOT "GeForce RTX 3060 Ti". |
| 136 | """ |
| 137 | name_upper = name.upper() |
| 138 | candidates = [] |
| 139 | for db_name in db.names: |
| 140 | idx = db_name.upper().find(name_upper) |
| 141 | if idx < 0: |
| 142 | continue |
| 143 | after = db_name[idx + len(name) :] |
| 144 | # Accept if nothing follows, or what follows is VRAM/form-factor spec |
| 145 | # Reject if a variant suffix follows (Ti, SUPER, Mobile, Max-Q, etc.) |
| 146 | if not after or re.match(r"^(\s+(\d|GA\d|PCIe|SXM|NVL|CNX))", after): |
| 147 | candidates.append(db_name) |
| 148 | if candidates: |
| 149 | candidates.sort(key=len) |
| 150 | return db[candidates[0]] |
| 151 | return None |
| 152 | |
| 153 | |
| 154 | def _lookup_dbgpu(name: str) -> GPUSpecification | None: |