Skip to content

Commit

Permalink
Only considers first occurence of house number
Browse files Browse the repository at this point in the history
  • Loading branch information
gosom committed Mar 28, 2023
1 parent 74c1aa6 commit ab3b468
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ without the need for the libpostal library to be included as a dependency in the
docker run -p 8080 gosom/address-parser-go-rest:v1.0.0
```

This will take some time to load

then try a sample request

```
Expand Down
9 changes: 8 additions & 1 deletion addressparser/libpostal/libpostal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package libpostal

import (
"strings"

"github.com/gosom/kit/logging"
postal "github.com/openvenues/gopostal/parser"
"golang.org/x/text/cases"
Expand Down Expand Up @@ -30,6 +32,7 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
tag = r
}
}
houseNumberFound := false
for i := range components {
if input.TitleCase {
components[i].Value = cases.Title(tag, cases.NoLower).String(components[i].Value)
Expand All @@ -42,7 +45,10 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
case "near":
address.Near = components[i].Value
case "house_number":
address.HouseNumber = components[i].Value
if !houseNumberFound {
address.HouseNumber = components[i].Value
houseNumberFound = true
}
case "road":
address.Road = components[i].Value
case "unit":
Expand Down Expand Up @@ -79,6 +85,7 @@ func (o *libPostalParser) Parse(input addressparser.AddressParserInput) (address
o.log.Warn("Unknown component", "component", components[i].Label)
}
}
address.HouseNumber = strings.TrimSpace(address.HouseNumber)
return address, nil
}

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"embed"
"fmt"
"os"

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

return webSvc.ListenAndServe(ctx)
Expand Down

0 comments on commit ab3b468

Please sign in to comment.