Helpers: Add Normalizer to normalize street names in addresses

This commit is contained in:
2026-09-29 19:04:12 +02:00
parent d8126e254d
commit fda337c3cb
9 changed files with 3193 additions and 8 deletions
+11 -2
View File
@@ -170,16 +170,25 @@ namespace Elwig.Helpers {
SavedChanges += OnSavedChanges;
}
private static void CreateFunctions(SqliteConnection cnx) {
cnx.CreateFunction<string, string?, bool?>("REGEXP", (pattern, value) => {
return value == null ? null : Regex.IsMatch(value, pattern);
}, true);
cnx.CreateFunction<string?, string?, string?>("NORMALIZE_ADDRESS", (address, locality) => {
return string.IsNullOrWhiteSpace(address) ? null : Normalizer.NormalizeAddress(address, locality);
}, true);
}
public static SqliteConnection Connect(string? connectionString = null) {
var cnx = new SqliteConnection(connectionString ?? ConnectionString);
cnx.CreateFunction<string, string?, bool?>("REGEXP", (pattern, value) => value == null ? null : Regex.Match(value, pattern).Success, true);
CreateFunctions(cnx);
cnx.Open();
return cnx;
}
public static async Task<SqliteConnection> ConnectAsync(string? connectionString = null) {
var cnx = new SqliteConnection(connectionString ?? ConnectionString);
cnx.CreateFunction<string, string?, bool?>("REGEXP", (pattern, value) => value == null ? null : Regex.Match(value, pattern).Success, true);
CreateFunctions(cnx);
await cnx.OpenAsync();
return cnx;
}