Skip to content

feat(ontology): add an optional document-level language tag - #689

Open
rodrigo-fagundes wants to merge 1 commit into
apache:mainfrom
rodrigo-fagundes:feat/ontology-document-language
Open

rodrigo-fagundes wants to merge 1 commit into
apache:mainfrom
rodrigo-fagundes:feat/ontology-document-language

Conversation

@rodrigo-fagundes

Copy link
Copy Markdown

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 verbalizes readings are sentences.
The root of ontology.json is closed (additionalProperties: false), so producers cannot record
the 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:

version: 0.2.0.dev0
name: OrganizationOntology
language: en
ontology: [ … ]

Announced on dev@ossie.apache.org; thread link to follow.

What changes

File Change
ontology/ontology.json Optional root language: a string matching a BCP 47 (RFC 5646) tag of language, optional script and optional region, in canonical case; at most 35 characters
ontology/ontology.md Root table row, a new Language section under Ontologies (what it covers, what it does not, what absence means) and a Version History line
validation/tests/test_ontology.py 5 accepted tags and 12 rejected ones; each rejection must be exactly one pattern error on language

The tag 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}))?$
  • accepted: en, pt-BR, zh-Hant-TW, es-419, fil;
  • rejected: pt-br and EN (not canonical case), en_US, en-, en-US-x-private (subtags outside
    the restricted shape), english, and the tags that name no single language: und, mul, zxx,
    mis and qst (private use).

Design notes

  • language, not locale. It states the language of content. A locale is a set of user
    preferences (W3C, Language Tags and Locale Identifiers, §2–3). This matches RDF, JSON-LD
    @language, xml:lang and DCAT.
  • One tag per document. No text field changes type, so the change is additive. Per-string tags
    stay possible later.
  • Identifiers are excluded. Names, prefixes, IRIs and expressions do not change meaning with
    the language, so the field has no effect on resolution or validation beyond its own value.
  • Narrow pattern. It covers language, script and region, which is what every format I know of
    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 language
means "not stated".

Testing

uv run --with pytest --with pyyaml --with jsonschema --with sqlglot -m pytest validation/tests/   # 544 passed, 1 skipped
uv run validation/test_validate.py                                                                 # 59 tests OK
uv run scripts/generate-spec-types.py --check                                                      # in sync

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.

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)
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thank you for your first contribution to Apache Ossie (incubating)!

A committer will review your PR. In the meantime, please ensure:

  • All CI checks pass
  • ASF license headers are present on new source files
  • Tests cover new functionality

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 orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ontology/ontology.md
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ontology/ontology.json
"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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants