Skip to content

Writer language improved parsing #663

Closed

Description

@lincomatic

The language matcher in OSMUtils.java only handles the alpha-2 code of ISO 639-1:

private static final Pattern NAME_LANGUAGE_PATTERN = Pattern.compile("(name)(:)([a-z]{2})");

However, I've found language specifiers in OSM data which contain more than two characters...
e.g.

    <tag k="name:zh-py" v="Gāoxióng Shì"/>

In the OpenStreetMaps wiki, there is also an example

name:ko_rm=Mweonga (the name in Romanised Korean)

which is later corrected to

name:ko_Latn=Mweonga

The pattern matcher should just allow arbitrary characters. I would rewrite it myself, but I am not very good with regular expressions.

Activity

  1. lincomatic commented on Aug 31, 2015

    @lincomatic
    ContributorAuthor

    This appears to work OK:

    private static final Pattern NAME_LANGUAGE_PATTERN = Pattern.compile("(name)(:)(.{2,})");
    

    or maybe should we should just use:

    private static final Pattern NAME_LANGUAGE_PATTERN = Pattern.compile("(name)(:)(.++)");
    
  2. devemux86 commented on Sep 1, 2015

    @devemux86
    Collaborator

    That's a valid proposal.
    Thanks @lincomatic for the regular expression examples.

  3. ludwigb commented on Sep 1, 2015

    @ludwigb
    Collaborator

    +1

    The proposed implementation is easy and should be done separately.

    But when I read it I thought this should support something a bit more
    complicated like falling back onto the main language if the sub-set is not
    there, e.g. use es_ar if argentinian name is provided, else use es. There
    must be some official algorithm for this, so we should not reinvent the
    wheel.

    Ludwig.

    On 1 September 2015 at 14:44, Emux [email protected] wrote:

    That's a valid proposal.
    Thanks @lincomatic https://github.com/lincomatic for the regular
    expression examples.

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

  4. devemux86 commented on Sep 1, 2015

    @devemux86
    Collaborator
  5. devemux86 commented on Sep 1, 2015

    @devemux86
    Collaborator
  6. lincomatic commented on Sep 1, 2015

    @lincomatic
    ContributorAuthor

    This regular express is for the client (reader) side to handle potential fallback, correct?

    NAME_LANGUAGE_PATTERN which I specified above is for the writer, which receives tags of the form:

    name:language

    unless we want to throw an exception where “language” isn’t specified in a specific way, using a more specific regex will just result in localized names to be thrown out.

    From: Emux [mailto:[email protected]]
    Sent: Tuesday, September 1, 2015 9:21 AM
    To: mapsforge/mapsforge
    Cc: lincomatic
    Subject: Re: [mapsforge] Preferred Language Extraction should allow more than 2 Characters for Language Specification (#663)

    Based on http://www.w3.org/TR/xmlschema11-2/#language we could use something like:

    [a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*

  7. lincomatic commented on Sep 1, 2015

    @lincomatic
    ContributorAuthor

    Also, based on the example I extracted from the wiki above, the "_" may appear in a language specification as well.

  8. devemux86 commented on Sep 1, 2015

    @devemux86
    Collaborator

    I wrote strictly a language regular expression (without the name: prefix).

    This issue is about the writer, correct? What language we put in map file.
    The reader will show what it'll find.

  9. devemux86 commented on Sep 1, 2015

    @devemux86
    Collaborator

    Also, based on the example I extracted from the wiki above, the "_" may appear in a language specification as well.

    (Following the rules in tagging is an never ending story)
    We can always make regex more versatile.

  10. ludwigb commented on Sep 2, 2015

    @ludwigb
    Collaborator

    Based on http://www.w3.org/TR/xmlschema11-2/#language we could use
    something like:
    [a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*
    @ludwigb https://github.com/ludwigb fall back with regular expression
    or by code?

    I think we should stick with the official regular expression. There will be
    cases in OSM data where yet more, but wrong codes are used. We cannot cater
    to every OSM data bug and probably using a few names is not the end of the
    world (if it is important, this should be fixed in OSM data).

    I think the fallback mechanism is difficult and not a regex problem.
    Android must have an implementation of some sort as it falls back onto a
    more general language when the specific one is not there. Maybe we should
    just provide a simple implementation (e.g. fall back to 2-letter code if
    longer code is not available, with a hook option it a user wanted a more
    complicated mechanism).

    Ludwig

    On 2 September 2015 at 03:12, Emux [email protected] wrote:

    Also, based on the example I extracted from the wiki above, the "_" may
    appear in a language specification as well.

    (Following the rules in tagging is an old story)
    We can always make regex more versatile.

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

  11. devemux86 commented on Sep 2, 2015

    @devemux86
    Collaborator

    I think we should stick with the official regular expression.

    @ludwigb which are you referring to?

    About fallback +1.

  12. applantation commented on Sep 2, 2015

    @applantation
    Collaborator

    [a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*

    On 3 September 2015 at 00:27, Emux [email protected] wrote:

    I think we should stick with the official regular expression.

    @ludwigb https://github.com/ludwigb which are you referring to?

    About fallback +1.

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

  13. added this to the milestone on Sep 2, 2015
  14. changed the title [-]Preferred Language Extraction should allow more than 2 Characters for Language Specification[/-] [+]Map-Writer Preferred Language Extraction should allow more than 2 Characters for Language Specification[/+] on Sep 2, 2015
  15. 12 remaining items

  16. devemux86 commented on Sep 10, 2015

    @devemux86
    Collaborator
  17. devemux86 commented on Sep 10, 2015

    @devemux86
    Collaborator

    With 94b0557 I pushed merging of '_' to '-' in writer.

  18. lincomatic commented on Sep 10, 2015

    @lincomatic
    ContributorAuthor

    Yes, because the data contains both “pt_br” and “pt-br,” which are obviously equivalent.

    I propose that “-“ be used rather than “_” because “-“ is more common.

    From: Emux [mailto:[email protected]]
    Sent: Wednesday, September 9, 2015 11:18 PM
    To: mapsforge/mapsforge
    Cc: lincomatic
    Subject: Re: [mapsforge] Map-Writer Preferred Language Extraction should allow more than 2 Characters for Language Specification (#663)

    @lincomatic https://github.com/lincomatic thanks for checking that.
    I'm reopening the issue to review the regular expression.

    I would also like to propose that all "_" characters be rewritten as "-"
    This way, "pt-br" will get merged with "pt_br," for instance.

    You mean by code to make that conversion, the reason (and why not the reverse) ?

    —
    Reply to this email directly or view it on GitHub #663 (comment) . https://github.com/notifications/beacon/ABWzan5Wz30eo_9itNbUn_lwRQ5NAiqYks5owRgQgaJpZM4F1VTC.gif

  19. ludwigb commented on Sep 11, 2015

    @ludwigb
    Collaborator

    As usual, there is a data quality issue in OSM. Is there really a point to
    have a preferred_languages=* option? Without additional folding this does
    not seem to be useful to anyone. I just cannot imagine a use case where
    this makes sense.

    As lincomatic's planet scan has shown, all these tags exist, but in the
    whole scheme of things they are few, many of them errors, many (probably
    well-) meant to mean something else, but the data such tagged is just not
    useful.

    To make this useful, additional folding would be needed, which would be
    better spent on fixing the data in OSM.

    Ludwig

    On 11 September 2015 at 07:07, lincomatic [email protected] wrote:

    Yes, because the data contains both “pt_br” and “pt-br,” which are
    obviously equivalent.

    I propose that “-“ be used rather than “_” because “-“ is more common.

    From: Emux [mailto:[email protected]]
    Sent: Wednesday, September 9, 2015 11:18 PM
    To: mapsforge/mapsforge
    Cc: lincomatic
    Subject: Re: [mapsforge] Map-Writer Preferred Language Extraction should
    allow more than 2 Characters for Language Specification (#663)

    @lincomatic https://github.com/lincomatic thanks for checking that.
    I'm reopening the issue to review the regular expression.

    I would also like to propose that all "_" characters be rewritten as "-"
    This way, "pt-br" will get merged with "pt_br," for instance.

    You mean by code to make that conversion, the reason (and why not the
    reverse) ?

    —
    Reply to this email directly or view it on GitHub <
    https://github.com/mapsforge/mapsforge/issues/663#issuecomment-139127738>
    . <
    https://github.com/notifications/beacon/ABWzan5Wz30eo_9itNbUn_lwRQ5NAiqYks5owRgQgaJpZM4F1VTC.gif>

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

  20. devemux86 commented on Sep 11, 2015

    @devemux86
    Collaborator

    Is there really a point to have a preferred_languages=* option?

    I'd say removing both * and - options.
    1st leads to maps with practically unknown language content and 2nd is covered by not setting the option.
    Not confusing the users, they should see a minimal command line API, i.e. setting only the needed languages or none.

  21. applantation commented on Sep 11, 2015

    @applantation
    Collaborator

    +1

    On 11 September 2015 at 14:11, Emux [email protected] wrote:

    Is there really a point to have a preferred_languages=* option?

    I'd vote removing both * and - options.
    1st leads to maps with practically unknown language content and 2nd is
    covered by not setting the option.
    Not confusing the users, they should see a minimal command line API, i.e.
    setting only the needed languages or none.

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

  22. devemux86 commented on Sep 11, 2015

    @devemux86
    Collaborator

    But this doesn't work because it results in a match for "name:left" as "name" + ":" + "lef".

    I cannot confirm that in Java, "name:left" fails matching with 1-3.
    (online regex testers may behave differently)

  23. devemux86 commented on Sep 11, 2015

    @devemux86
    Collaborator

    I pushed an improved regex pattern, setting the 1st field to 1-3 characters and using non capturing group for the rest.

  24. lincomatic commented on Sep 11, 2015

    @lincomatic
    ContributorAuthor

    That’s fine with me. I put * because it’s quite useful for testing/debugging the quality of the data, and mainly to see what languages are actually present.

    From: Ludwig [mailto:[email protected]]
    Sent: Thursday, September 10, 2015 11:41 PM
    To: mapsforge/mapsforge
    Cc: lincomatic
    Subject: Re: [mapsforge] Map-Writer Preferred Language Extraction should allow more than 2 Characters for Language Specification (#663)

    +1

    On 11 September 2015 at 14:11, Emux [email protected] wrote:

    Is there really a point to have a preferred_languages=* option?

    I'd vote removing both * and - options.
    1st leads to maps with practically unknown language content and 2nd is
    covered by not setting the option.
    Not confusing the users, they should see a minimal command line API, i.e.
    setting only the needed languages or none.

    —
    Reply to this email directly or view it on GitHub
    #663 (comment)
    .

    —
    Reply to this email directly or view it on GitHub #663 (comment) . https://github.com/notifications/beacon/ABWzavUsBumWZEJkowLvXz44QOEB8U6Rks5owm8SgaJpZM4F1VTC.gif

  25. changed the title [-]Map-Writer Preferred Language Extraction should allow more than 2 Characters for Language Specification[/-] [+]Writer language improved parsing[/+] on Sep 13, 2015
  26. devemux86 commented on Sep 17, 2015

    @devemux86
    Collaborator

    @ludwigb @lincomatic
    Have you tested latest language regex pattern, is it ok?

  27. lincomatic commented on Sep 21, 2015

    @lincomatic
    ContributorAuthor

    Looks good

    From: Emux [mailto:[email protected]]
    Sent: Wednesday, September 16, 2015 11:31 PM
    To: mapsforge/mapsforge
    Cc: lincomatic
    Subject: Re: [mapsforge] Writer language improved parsing (#663)

    @ludwigb https://github.com/ludwigb @lincomatic https://github.com/lincomatic
    Have you tested latest language regex pattern, is it ok?

  28. devemux86 commented on Sep 22, 2015

    @devemux86
    Collaborator

    Ok, as I have not seen either any problems, I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions