Modify

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Don-vip)

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)

filter.diff (1.0 KB ) - added by francians 6 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Don-vip, 6 years ago

Description: modified (diff)

comment:2 by francians, 6 years ago

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

comment:3 by francians, 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 francians, 6 years ago

Attachment: filter.diff added

comment:4 by francians, 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 francians, 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 francians, 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 simon04, 5 years ago

Resolution: wontfix
Status: newclosed

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 stoecker, 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 stoecker, 5 years ago

If with the / you have same syntax as for ; it can be ^([0-9]+[a-z]*[;/])*[0-9]+[a-z]*$

Last edited 5 years ago by stoecker (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.