Helpers: Add Normalizer to normalize street names in addresses

This commit is contained in:
lorenz.stechauner committed 2026-09-29 14:27:36 +02:00
1 parent d2f1b4b94c
commit c293fa0ac7
9 files changed
+3193 -8

No files matched your search

+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;
}