New algorithm for detecting multiple conflicting features

This commit is contained in:
Eli Ribble 2026-04-16 04:21:11 +00:00
parent f490e4a1a4
commit d395699dc4
No known key found for this signature in database
2 changed files with 34 additions and 13 deletions

View file

@ -165,14 +165,35 @@ func allFeaturesIdenticalEnough(features []stadia.GeocodeFeature) bool {
if len(features) < 2 {
return true
}
f := features[0].Properties
// We may have a 'fallback feature' which is a match for a street, but not the rest
// We therefore search for a feature that is 'full' or has all the properties we care about
// So long as we find only one, and no conflicts, we're fine.
var full_feature *stadia.GeocodeFeature
for _, feature := range features {
if feature.Properties.CountryCode != f.CountryCode ||
feature.Properties.County != f.County ||
feature.Properties.HouseNumber != f.HouseNumber ||
feature.Properties.Locality != f.Locality ||
feature.Properties.RegionA != f.RegionA {
return false
if feature.Number() != "" &&
feature.Street() != "" &&
feature.Locality() != "" &&
feature.Region() != "" {
if full_feature == nil {
full_feature = &feature
} else if feature.Number() == full_feature.Number() &&
feature.Street() == full_feature.Street() &&
feature.Locality() == full_feature.Locality() &&
feature.Region() == full_feature.Region() {
continue
} else {
log.Info().
Str("ff_number", full_feature.Number()).
Str("ff_street", full_feature.Street()).
Str("ff_locality", full_feature.Locality()).
Str("ff_region", full_feature.Region()).
Str("number", feature.Number()).
Str("street", feature.Street()).
Str("locality", feature.Locality()).
Str("region", feature.Region()).
Msg("This is where the features first disagreed")
return false
}
}
}
return true

View file

@ -162,7 +162,7 @@ func (gf GeocodeFeature) CountryCode() string {
if gf.Properties.Context.WhosOnFirst.Country.Abbreviation != "" {
return gf.Properties.Context.WhosOnFirst.Country.Abbreviation
}
return "none"
return ""
}
func (gf GeocodeFeature) Locality() string {
if gf.Properties.Locality != "" {
@ -171,7 +171,7 @@ func (gf GeocodeFeature) Locality() string {
if gf.Properties.Context.WhosOnFirst.Locality.Name != "" {
return gf.Properties.Context.WhosOnFirst.Locality.Name
}
return "none"
return ""
}
func (gf GeocodeFeature) Number() string {
if gf.Properties.AddressComponents.Number != "" {
@ -180,7 +180,7 @@ func (gf GeocodeFeature) Number() string {
if gf.Properties.HouseNumber != "" {
return gf.Properties.HouseNumber
}
return "none"
return ""
}
func (gf GeocodeFeature) PostalCode() string {
if gf.Properties.PostalCode != "" {
@ -189,7 +189,7 @@ func (gf GeocodeFeature) PostalCode() string {
if gf.Properties.AddressComponents.PostalCode != "" {
return gf.Properties.AddressComponents.PostalCode
}
return "none"
return ""
}
func (gf GeocodeFeature) Region() string {
if gf.Properties.Region != "" {
@ -198,7 +198,7 @@ func (gf GeocodeFeature) Region() string {
if gf.Properties.Context.WhosOnFirst.Region.Name != "" {
return gf.Properties.Context.WhosOnFirst.Region.Name
}
return "none"
return ""
}
func (gf GeocodeFeature) Street() string {
if gf.Properties.Street != "" {
@ -207,5 +207,5 @@ func (gf GeocodeFeature) Street() string {
if gf.Properties.AddressComponents.Street != "" {
return gf.Properties.AddressComponents.Street
}
return "none"
return ""
}