MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getSimilarity

Function getSimilarity

src/core/diff/strategies/multi-search-replace.ts:11–31  ·  view source on GitHub ↗
(original: string, search: string)

Source from the content-addressed store, hash-verified

9const BUFFER_LINES = 40 // Number of extra context lines to show before and after matches
10
11function getSimilarity(original: string, search: string): number {
12 // Empty searches are no longer supported
13 if (search === "") {
14 return 0
15 }
16
17 // Use the normalizeString utility to handle smart quotes and other special characters
18 const normalizedOriginal = normalizeString(original)
19 const normalizedSearch = normalizeString(search)
20
21 if (normalizedOriginal === normalizedSearch) {
22 return 1
23 }
24
25 // Calculate Levenshtein distance using fastest-levenshtein's distance function
26 const dist = distance(normalizedOriginal, normalizedSearch)
27
28 // Calculate similarity ratio (0 to 1, where 1 is an exact match)
29 const maxLength = Math.max(normalizedOriginal.length, normalizedSearch.length)
30 return 1 - dist / maxLength
31}
32
33/**
34 * Performs a "middle-out" search of `lines` (between [startIndex, endIndex]) to find

Callers 2

fuzzySearchFunction · 0.85
applyDiffMethod · 0.85

Calls 1

normalizeStringFunction · 0.90

Tested by

no test coverage detected