#18166 closed enhancement (wontfix)
[PATCH][RFC] New mapcss function: "filter". to validate Italian housenumber tag
Reported by: | francians | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core validator | Version: | |
Keywords: | mapcss filter italian housenumber validator | Cc: |
Description (last modified by )
Hello,
I built my regex this way:
*[addr:housenumber][addr:housenumber !~ /^[0-9]+(([a-z]*)|(\/[0-9]+))(\b rosso\b)?$/][inside("IT")] { throwWarning: tr("Numero Civico"); group: "MapThisWay"; }
to check all possible italian values:
- 1 <---- will match
- 1bis <---- will match
- 1/1 <---- will match
- 1a rosso <---- will match
- 1;3 <---- will not match
- 1,3 <---- will not match
but I don't know a way to check each value when it's a csv (semicolon or comma separated).
I could do: if value contains comma, split by comma else split by semicolon... right?
But with the list I cannot check if every value matches my rule...
What do you think about a "filter" method that given regex + list could return all matching elements?
So to close the circle, I can count original list, count filtered list and if the number is not the same give the error.
Please let me know what you think and if it could be helpful a patch
Many Thanks
Francesco
Attachments (1)
Change History (10)
comment:1 by , 6 years ago
Description: | modified (diff) |
---|
comment:2 by , 6 years ago
comment:3 by , 6 years ago
Hello,
please find an example of what I wish to implement:
public static List<Object> filter(String regex, List<?> src) { // NO_UCD (unused code) List<Object> dst = new ArrayList<Object>(); src.stream() .filter(obj -> obj.toString().matches(regex)) .forEach(str -> dst.add(str)); return dst; }
Be aware it's compile-tested only
Cheers
Francesco
by , 6 years ago
Attachment: | filter.diff added |
---|
comment:4 by , 6 years ago
Summary: | [RFC] New tag proposal: "filter" → [PATCH][RFC] New tag proposal: "filter" |
---|
I went ahead and sent a patch.
It works with the case I need it:
/* mtw numerocivicoerrato */ *[tag("addr:housenumber") != join_list(";",filter("^[0-9]+(([a-z]*)|(\\/[0-9]+))(\\b rosso\\b)?$",split(";",tag("addr:housenumber"))))][inside("IT")] { throwWarning: tr("Numero civico"); group: "MapThisWay"; }
Please let me know what you think
comment:5 by , 6 years ago
Hello,
this is my last reply to this post... With this expression I'm able to warn against any bad Italian housenumber:
/* mtw numerocivicoerrato */ *["addr:housenumber"][replace(tag("addr:housenumber"),",",";") != join_list(";",filter("^[0-9]+(([a-z]*)|(\\/[0-9]+))(\\b rosso\\b)?$",split(";",replace(tag("addr:housenumber"),",",";"))))][inside("IT")] { throwWarning: tr("Numero civico"); group: "MapThisWay"; }
it also address the comma vs semicolon case that wasn't handled in previous version.
In case of interest from your side please ping me via mail: francians [at] gmail
Thanks
Francesco
comment:6 by , 6 years ago
Keywords: | mapcss filter italian housenumber validator added |
---|---|
Summary: | [PATCH][RFC] New tag proposal: "filter" → [PATCH][RFC] New mapcss function: "filter". to validate Italian housenumber tag |
comment:7 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
We already have a bunch of regexp_*
function, see Help/Styles/MapCSSImplementation#Evalexpressions. I don't want to add yet another one without a strong argument why the existing one do not suffice.
comment:8 by , 5 years ago
What about ^([0-9]+[a-z]*;)*[0-9]+[a-z]*$
That will match all your examples except the / one, feel free to expand as necessary.
comment:9 by , 5 years ago
If with the / you have same syntax as for ; it can be ^([0-9]+[a-z]*[;/])*[0-9]+[a-z]*$
Hello,
Any chance to get a comment about this?
I could hack around it this weekend and hopefully to send a patch.
Cheers,
Best
Francesco