Skip to content

Commit

Permalink
Merge pull request #1167 from nyaruka/fix-matching-french-words-locat…
Browse files Browse the repository at this point in the history
…ions

Support hyphen in locations name as one word
  • Loading branch information
rowanseymour authored May 3, 2023
2 parents 89d0546 + c3b3a47 commit acc7ebb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flows/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (r *assetLocationResolver) FindLocationsFuzzy(text string, level envs.Locat
}

// try on each tokenized word
words := regexp.MustCompile(`[\s\p{P}]+`).Split(text, -1)
re := regexp.MustCompile(`[\p{L}\d]+(-[\p{L}\d]+)*`)
words := re.FindAllString(text, -1)
for _, word := range words {
if locations := r.FindLocations(word, level, parent); len(locations) > 0 {
return locations
Expand Down
7 changes: 7 additions & 0 deletions flows/routers/cases/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ var locationHierarchyJSON = `{
"aliases": ["Q.C", "Le Québec", "Quebec", "Que,", "Que", "Qc", "Québec"],
"children": []
},
{
"name": "Île-de-France",
"aliases": [],
"children": []
},
{
"name": "Paktika",
"aliases": ["Janikhel", "Terwa", "Yahyakhel", "Yusufkhel", "\u067e\u06a9\u062a\u06cc\u06a9\u0627", "\u062a\u0631\u0648\u0648", "\u06cc\u062d\u06cc\u06cc \u062e\u06cc\u0644", "\u06cc\u0648\u0633\u0641 \u062e\u06cc\u0644"],
Expand Down Expand Up @@ -300,6 +305,8 @@ var testTests = []struct {
{"has_state", []types.XValue{xs("Québec")}, result(xs("Rwanda > Québec"))},
{"has_state", []types.XValue{xs("Je suis dans la province du Québec")}, result(xs("Rwanda > Québec"))},

{"has_state", []types.XValue{xs("Je suis dans la province de l'Île-de-France")}, result(xs("Rwanda > Île-de-France"))},

{"has_state", []types.XValue{xs("kigali city")}, result(xs("Rwanda > Kigali City"))},
{"has_state", []types.XValue{xs("¡Kigali!")}, result(xs("Rwanda > Kigali City"))},

Expand Down

0 comments on commit acc7ebb

Please sign in to comment.