Repository navigation
feat(ontology): add an optional document-level language tag - #689
rodrigo-fagundes wants to merge 1 commit into
Conversation
An ontology's descriptions and verbalizations are written in a natural language, but the closed root of ontology.json gave producers nowhere to say which one, so consumers that need it (OPC UA LocalizedText, RDF language-tagged literals, AI tools) had to guess. Add an optional root `language`: a BCP 47 (RFC 5646) tag restricted to language, optional script and optional region, in canonical case, so that tags compare as plain strings. Tags that name no single language (und, mul, zxx, mis, and the private-use range qaa-qtz) are rejected. The tag covers descriptions, verbalizations and ai_context, and never identifiers. An absent tag means the language is not stated, so every existing document still validates. Generated-by: Claude Code (claude-opus-5-5)
|
Thank you for your first contribution to Apache Ossie (incubating)! A committer will review your PR. In the meantime, please ensure:
No ICLA is required to contribute. If you are elected as a committer in the future, you will need an Individual Contributor License Agreement (ICLA) on file with the ASF. Questions? Ask in the PR comments or join us on Slack. We appreciate your contribution! |
orca-review-bot
left a comment
There was a problem hiding this comment.
Nice, tight addition. The pattern does what the PR says, the tests pin exactly one pattern error per rejection, and adding to the 0.2.0.dev0 history entry matches what #400 and #458 did. Main ask: the doc should say "well-formed" BCP 47, since registry validity isn't checked. Optional: add language: en to examples/flights.ontology.yaml so CI runs the field on a real document. For the core-spec follow-up, can we share this pattern as one $def so the two copies don't drift?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| description: "A generic agent (person, organization, etc.)" | ||
| ``` | ||
|
|
||
| The value is a language tag as defined by [BCP 47](https://www.rfc-editor.org/info/bcp47) |
There was a problem hiding this comment.
The schema only checks the tag's shape, so xx and qua pass even though they aren't registered subtags. Can we say "a well-formed BCP 47 tag" here and add that subtags aren't checked against the IANA registry?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| "language": { | ||
| "type": "string", | ||
| "pattern": "^(?!(und|mul|zxx|mis|q[a-t][a-z])(-|$))[a-z]{2,3}(-[A-Z][a-z]{3})?(-([A-Z]{2}|[0-9]{3}))?$", | ||
| "maxLength": 35, |
There was a problem hiding this comment.
This limit never applies, because the pattern already caps tags at 12 chars. Can we drop it, or note in the PR that it's there for later widening?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| assert not _only_min_length_paths(ontology_validator, document) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("language", ["en", "pt-BR", "zh-Hant-TW", "es-419", "fil"]) |
There was a problem hiding this comment.
Can we add en-Latn-US here so all three subtags are covered together? A matching abcde in the rejected list would pin the {2,3} length.
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
Summary
An ontology document is written in a natural language, but it cannot say which one. Descriptions
explain concepts in prose, and every relationship's required
verbalizesreadings are sentences.The root of
ontology.jsonis closed (additionalProperties: false), so producers cannot recordthe language themselves, and consumers that need it (OPC UA LocalizedText, RDF language-tagged
literals, AI tools, translation workflows) have to guess.
This PR adds one optional field:
Announced on dev@ossie.apache.org; thread link to follow.
What changes
ontology/ontology.jsonlanguage: a string matching a BCP 47 (RFC 5646) tag of language, optional script and optional region, in canonical case; at most 35 charactersontology/ontology.mdvalidation/tests/test_ontology.pypatternerror onlanguageThe tag pattern:
en,pt-BR,zh-Hant-TW,es-419,fil;pt-brandEN(not canonical case),en_US,en-,en-US-x-private(subtags outsidethe restricted shape),
english, and the tags that name no single language:und,mul,zxx,misandqst(private use).Design notes
language, notlocale. It states the language of content. A locale is a set of userpreferences (W3C, Language Tags and Locale Identifiers, §2–3). This matches RDF, JSON-LD
@language,xml:langand DCAT.stay possible later.
the language, so the field has no effect on resolution or validation beyond its own value.
that consumes these tags uses. Widening it later does not break any document.
Compatibility
Purely additive. Every document that validates today still validates, and an absent
languagemeans "not stated".
Testing
Follow-up
If the shape is accepted, a second PR adds the same field to semantic models (
core-spec).Tooling
Prepared with Claude Code; the commit carries a
Generated-by:token, per the ASF Generative Tooling Guidance. I have reviewed every line and am responsible for the change.