Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenkleinle committed Jan 21, 2022
1 parent c6bfe1f commit a038d82
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ class Map(private val logger: Logger) : PipelineStep<List<LbeAcceptingStore>, 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 {
val isStreetPolluted = street?.find { it.isDigit() } != null
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) {
Expand Down Expand Up @@ -110,7 +110,7 @@ class Map(private val logger: Logger) : PipelineStep<List<LbeAcceptingStore>, 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()) {
Expand Down

0 comments on commit a038d82

Please sign in to comment.