Skip to content

Commit ab3b468

Browse files
committed
Only considers first occurence of house number
1 parent 74c1aa6 commit ab3b468

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ without the need for the libpostal library to be included as a dependency in the
1212
docker run -p 8080 gosom/address-parser-go-rest:v1.0.0
1313
```
1414

15+
This will take some time to load
16+
1517
then try a sample request
1618

1719
```

addressparser/libpostal/libpostal.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package libpostal
22

33
import (
4+
"strings"
5+
46
"github.com/gosom/kit/logging"
57
postal "github.com/openvenues/gopostal/parser"
68
"golang.org/x/text/cases"
@@ -30,6 +32,7 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
3032
tag = r
3133
}
3234
}
35+
houseNumberFound := false
3336
for i := range components {
3437
if input.TitleCase {
3538
components[i].Value = cases.Title(tag, cases.NoLower).String(components[i].Value)
@@ -42,7 +45,10 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
4245
case "near":
4346
address.Near = components[i].Value
4447
case "house_number":
45-
address.HouseNumber = components[i].Value
48+
if !houseNumberFound {
49+
address.HouseNumber = components[i].Value
50+
houseNumberFound = true
51+
}
4652
case "road":
4753
address.Road = components[i].Value
4854
case "unit":
@@ -79,6 +85,7 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
7985
o.log.Warn("Unknown component", "component", components[i].Label)
8086
}
8187
}
88+
address.HouseNumber = strings.TrimSpace(address.HouseNumber)
8289
return address, nil
8390
}
8491

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"embed"
6+
"fmt"
67
"os"
78

89
"github.com/gosom/kit/logging"
@@ -69,6 +70,7 @@ func run(ctx context.Context) error {
6970
Host: addr,
7071
Router: router,
7172
}
73+
log.Info(fmt.Sprintf("Starting server at %s", addr))
7274
webSvc := web.NewHttpServer(webCfg)
7375

7476
return webSvc.ListenAndServe(ctx)

0 commit comments

Comments
 (0)