From ab3b468778f09a71083792c6b9084b82dae385cf Mon Sep 17 00:00:00 2001 From: Giorgos Komninos Date: Tue, 28 Mar 2023 22:46:55 +0300 Subject: [PATCH] Only considers first occurence of house number --- README.md | 2 ++ addressparser/libpostal/libpostal.go | 9 ++++++++- main.go | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04e1b77..0c448f5 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/addressparser/libpostal/libpostal.go b/addressparser/libpostal/libpostal.go index f9acb4b..c449aca 100644 --- a/addressparser/libpostal/libpostal.go +++ b/addressparser/libpostal/libpostal.go @@ -1,6 +1,8 @@ package libpostal import ( + "strings" + "github.com/gosom/kit/logging" postal "github.com/openvenues/gopostal/parser" "golang.org/x/text/cases" @@ -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) @@ -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": @@ -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 } diff --git a/main.go b/main.go index c2b967a..3a89930 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" "embed" + "fmt" "os" "github.com/gosom/kit/logging" @@ -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)