Skip to content

Commit

Permalink
Use LCS distance as metric for finding the best match
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jan 5, 2024
1 parent 18a562b commit ff4bfa9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/fwcd/swift-utils.git",
"state" : {
"revision" : "31ed21dabedba93b3892adc0ec617787c9bf515e",
"version" : "2.0.1"
"revision" : "3090d5171bc3bba4d8cdb495483c46cd7fad422c",
"version" : "2.1.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "0.3.2"),
.package(url: "https://github.com/fwcd/swift-qrcode-generator.git", from: "1.0.0"),
.package(url: "https://github.com/fwcd/swift-prolog.git", from: "0.1.0"),
.package(url: "https://github.com/fwcd/swift-utils.git", from: "2.0.1"),
.package(url: "https://github.com/fwcd/swift-utils.git", from: "2.1.0"),
.package(url: "https://github.com/fwcd/swift-graphics.git", from: "2.1.0"),
.package(url: "https://github.com/fwcd/swift-gif.git", from: "2.1.0"),
.package(url: "https://github.com/fwcd/swift-mensa.git", from: "0.1.10"),
Expand Down
6 changes: 5 additions & 1 deletion Sources/D2Commands/cau/exam/ExamCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public class ExamCommand: StringCommand {
exams.first { $0.module?.code == query }
?? exams.first { $0.module?.name == query }
?? exams.min(by: ascendingComparator {
($0.module?.name ?? $0.module?.code)?.levenshteinDistance(to: query) ?? .max
[$0.module?.name, $0.module?.code]
.compactMap { $0 }
.map { $0.lcsDistance(to: query, caseSensitive: false) }
.min()
?? .max
})
}

Expand Down

0 comments on commit ff4bfa9

Please sign in to comment.