diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/Map.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/Map.kt index ce8a0ceec..289c08145 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/Map.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/Map.kt @@ -40,23 +40,23 @@ class Map(private val logger: Logger) : PipelineStep, Li } private fun houseNumberRegex(): Regex { - // House number prefix, e.g. "B[200]", "H[7]" (mostly in industrial parks) + // E.g. "B[200]", "H[7]" (mostly in industrial parks) @Language("RegExp") - val houseNumberPrefix = """[A-Z]?""" + val prefix = """[A-Z]?""" - // House number range, e.g. "[5] - 7", "[2]+3" or "[11] und 12" + // E.g. "[5] - 7", "[2]+3" or "[11] und 12" @Language("RegExp") - val houseNumberRange = """\s?(-|\+|u\.|und|/)\s?[0-9]+""" + val range = """\s?(-|\+|u\.|und|/)\s?[0-9]+""" - // Additional house number info, e.g. "[13] 1/2" or "[1] 3/4" (must not be followed by another digit) + // E.g. "[13] 1/2" or "[1] 3/4" (must not be followed by another digit) @Language("RegExp") - val houseNumberAdditionFraction = """\s?[0-9]/[0-9]""" + val fraction = """\s?[0-9]/[0-9]""" - // Additional house number info, e.g. "[12]a" or "[2] B" (must be followed by a whitespace or the end of the string) + // E.g. "[12]a" or "[2] B" (must be followed by a whitespace or the end of the string) @Language("RegExp") - val houseNumberAdditionLetter = """\s?[a-zA-Z]($|\s)""" + val letter = """\s?[a-zA-Z]($|\s)""" - return """$houseNumberPrefix[0-9]+(($houseNumberRange)|($houseNumberAdditionFraction)|($houseNumberAdditionLetter))?""".toRegex() + return Regex("""$prefix[0-9]+(($range)|($fraction)|($letter))?""") } private fun AcceptingStore.sanitizeStreetHouseNumber(): AcceptingStore { @@ -64,7 +64,7 @@ class Map(private val logger: Logger) : PipelineStep, Li val isHouseNumberPolluted = houseNumber != null && !houseNumberRegex.matches(houseNumber) if (isStreetPolluted || isHouseNumberPolluted) { - val address = listOfNotNull(street, houseNumber).joinToString(" ").replace(Regex("""\s{2,}"""), " ") + val address = listOfNotNull(street, houseNumber).joinToString(" ") val match = houseNumberRegex.find(address) if (match == null) { @@ -110,7 +110,7 @@ class Map(private val logger: Logger) : PipelineStep, Li private fun LbeAcceptingStore.cleanPostalCode(): String? { val oldPostalCode = postalCode ?: return null - val fiveDigitRegex = """[0-9]{5}""".toRegex() + val fiveDigitRegex = Regex("""[0-9]{5}""") val newPostalCode = fiveDigitRegex.find(oldPostalCode)?.value if (newPostalCode != oldPostalCode.clean()) {