basyx-python-sdk icon indicating copy to clipboard operation
basyx-python-sdk copied to clipboard

Fix `LangStringSet._check_language_tag_constraints` after the spec has been clarified

Open zrgt opened this issue 3 years ago • 7 comments

After the spec regarding language tags is clarified(https://github.com/admin-shell-io/aas-specs/issues/293), we need to adapt the method LangStringSet._check_language_tag_constraints

Currently we demand that language tags:

  • can only have one or zero extensions
  • the only possible extension is region

Relevant codesnippet: https://github.com/eclipse-basyx/basyx-python-sdk/blob/5eb895e1e64cdcd4ba98464d5fda4176292cf942/basyx/aas/model/base.py#L289C1-L296C56

    @classmethod
    def _check_language_tag_constraints(cls, ltag: str):
        split = ltag.split("-", 1)
        if len(split[0]) != 2 or not split[0].isalpha() or not split[0].islower():
            raise ValueError(f"The language code '{split[0]}' of the language tag '{ltag}' doesn't consist of exactly "
                             "two lower-case letters!")
        if len(split) > 1 and (len(split[1]) != 2 or not split[1].isalpha() or not split[1].isupper()):
            raise ValueError(f"The extension '{split[1]}' of the language tag '{ltag}' doesn't consist of exactly "
                             "two upper-case letters!")

zrgt avatar Nov 09 '23 17:11 zrgt

Temporary fix with #167

s-heppner avatar Nov 16 '23 13:11 s-heppner

@s-heppner please reopen the issue, as #167 is only a temporary solution. The spec issue is still not clarified.

zrgt avatar Nov 16 '23 21:11 zrgt

My bad, I also edited my comment above

s-heppner avatar Nov 18 '23 16:11 s-heppner

See the RDF Spec: https://www.w3.org/TR/rdf11-concepts/

zrgt avatar Aug 26 '25 12:08 zrgt

According to the decision in https://github.com/admin-shell-io/aas-specs/issues/293, it seems, the offical way is to check for the regex defined in BCP 47.

Therefore, I suggest following the implemention of aas-core.

s-heppner avatar Apr 15 '26 09:04 s-heppner

A close inspection of the BCP 47 regex implementation in aas-core, revealed two slight deviations from the syntax described in RFC 5646.

For the nonterminal extlang the RFC 5646 declares a format of 3 characters and up to two extensions of three characters. In contrast, the regex pattern requires the extension groups to appear exactly two times.

extlang = "[a-zA-Z]{3}(-[a-zA-Z]{3}){2}"

Additionally, the nonterminal privateuse is defined to start with a lower case "x", while the python implementation allows for lower- and uppercase "xX".

privateuse = f"[xX](-({alphanum}){{1,8}})+"

Although both deviations from RFC 5646 are small, I suggest correcting them for the use in this project in order to stay conform with the standard.

hpoeche avatar Apr 15 '26 14:04 hpoeche

I have to correct myself at this point, as the current implementation in the main branch of aas-core is correct.

The first mentioned error was fixed by commit 4ee616c, while the second rose from a false interpretation of the ABNF syntax by myself.

No changes in aas-core are necessary and the changes in #478 now reflect the implementation in aas-core.

hpoeche avatar Apr 20 '26 17:04 hpoeche