-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification nouveaux JDD : répare matching avec mots-clefs #4413
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,9 @@ defmodule Transport.Jobs.NewDatagouvDatasetsJob do | |
"trottinette", | ||
"vls", | ||
"scooter", | ||
"scooters", | ||
"libre-service", | ||
"libre service", | ||
"scooter" | ||
"libre service" | ||
]), | ||
formats: MapSet.new(["gbfs"]) | ||
}, | ||
|
@@ -51,7 +51,7 @@ defmodule Transport.Jobs.NewDatagouvDatasetsJob do | |
"etalab/schema-comptage-mobilites-measure", | ||
"etalab/schema-comptage-mobilites-site" | ||
], | ||
tags: MapSet.new(["cyclable", "parking", "stationnement", "vélo"]), | ||
tags: MapSet.new(["cyclable", "cyclables", "parking", "parkings", "stationnement", "vélo", "vélos"]), | ||
formats: MapSet.new([]) | ||
}, | ||
%{ | ||
|
@@ -221,7 +221,17 @@ defmodule Transport.Jobs.NewDatagouvDatasetsJob do | |
|
||
defp string_matches?(str, %{formats: formats, tags: tags} = _rule) when is_binary(str) do | ||
searches = MapSet.union(formats, tags) |> MapSet.to_list() |> Enum.map(&normalize/1) | ||
str |> normalize() |> String.contains?(searches) | ||
{words_with_spaces, words_without_spaces} = Enum.split_with(searches, &String.contains?(&1, " ")) | ||
|
||
match_without_spaces = | ||
not (str | ||
|> normalize() | ||
|> String.split(~r/\s+/) | ||
|> MapSet.new() | ||
|> MapSet.disjoint?(MapSet.new(words_without_spaces))) | ||
|
||
match_with_spaces = str |> normalize() |> String.contains?(words_with_spaces) | ||
match_without_spaces || match_with_spaces | ||
end | ||
|
||
defp tags_is_relevant?(%{"tags" => tags} = _dataset, rule) do | ||
|
@@ -257,8 +267,26 @@ defmodule Transport.Jobs.NewDatagouvDatasetsJob do | |
"velo" | ||
iex> normalize("Châteauroux") | ||
"chateauroux" | ||
iex> normalize("J'adore manger") | ||
"j'adore manger" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Précédemment on avait ça iex> "J'adore manger" |> String.normalize(:nfd) |> String.replace(~r/[^A-z]/u, "") |> String.downcase()
"jadoremanger" ce n'était pas attendu, les espaces sont importants à converser pour le matching avec les mots-clefs |
||
""" | ||
def normalize(value) do | ||
value |> String.normalize(:nfd) |> String.replace(~r/[^A-z]/u, "") |> String.downcase() | ||
value | ||
|> String.downcase() | ||
|> String.graphemes() | ||
|> Enum.map_join("", &normalize_grapheme/1) | ||
end | ||
|
||
defp normalize_grapheme(grapheme) do | ||
case String.normalize(grapheme, :nfd) do | ||
<<first, rest::binary>> when is_binary(rest) -> | ||
case String.valid?(<<first>>) do | ||
true -> <<first>> | ||
false -> "" | ||
end | ||
|
||
_ -> | ||
grapheme | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Était en double précédemment, j'ai ajouté le pluriel aussi