MatchesReferenceIdentifier🔗

Type: Pattern verification
Check that text is a valid reference identifier.

A reference identifier points to an attribute of a specific instance given by its identifier, e.g. , $sm("https://example.com/sm")#idShort or $sme("https://example.com/sm").someProperty#value. A quotation mark and a reverse solidus in the identifier are escaped as \" and \\, respectively.

See: https://industrialdigitaltwin.io/aas-specifications/IDTA-01002/v3.2/query-language.html#query-grammar

text🔗
Text to be checked
Return🔗
True if the text conforms to the pattern

Code

array_index = "(0|[1-9][0-9]*)"
optional_index = f"\\[{array_index}?\\]"
reference_clause = f"(type|keys{optional_index}\\.(type|value))"
semantic_id_clause = f"semanticId(\\.{reference_clause})?"
supplemental_semantic_id_clause = (
    f"supplementalSemanticIds({optional_index})?(\\.{reference_clause})?"
)
specific_asset_ids_clause = (
    f"specificAssetIds{optional_index}"
    f"\\.(name|value|externalSubjectId(\\.{reference_clause})?)"
)
id_short = "[A-Za-z]([A-Za-z0-9_-]*[A-Za-z0-9_])?"
id_short_path_segment = f"{id_short}({optional_index})*"
id_short_path = f"{id_short_path_segment}(\\.{id_short_path_segment})*"

# NOTE (mristin):
# The identifier is limited to the characters of an XML-serializable
# string, where the quotation mark and the reverse solidus need to be
# escaped.
# noinspection SpellCheckingInspection
identifier_character = (
    r"([\x09\x0A\x0D\x20-\x21\x23-\x5B\x5D-\uD7FF\uE000-\uFFFD"
    r'\U00010000-\U0010FFFF]|\\["\\])'
)
identifier_instance = f'\\("{identifier_character}+"\\)'

fields_aas = (
    f"(idShort|id|assetInformation\\.assetKind|assetInformation\\.assetType"
    f"|assetInformation\\.globalAssetId"
    f"|assetInformation\\.{specific_asset_ids_clause}"
    f"|submodels{optional_index}(\\.{reference_clause})?)"
)
fields_sm = f"({semantic_id_clause}|{supplemental_semantic_id_clause}|idShort|id)"
fields_sme = (
    f"({semantic_id_clause}|{supplemental_semantic_id_clause}"
    f"|idShort|value|valueType|language)"
)

pattern = (
    f"^(\\$aas{identifier_instance}#{fields_aas}"
    f"|\\$sm{identifier_instance}#{fields_sm}"
    f"|\\$cd{identifier_instance}#(idShort|id)"
    f"|\\$sme{identifier_instance}\\.{id_short_path}#{fields_sme})$"
)

return match(pattern, text) is not None