Skip to content

Label language preferences + diff-pretty label-language prefs support#1287

Open
jclerman wants to merge 6 commits into
ontodev:masterfrom
jclerman:label-language-prefs+diff-pretty-usage
Open

Label language preferences + diff-pretty label-language prefs support#1287
jclerman wants to merge 6 commits into
ontodev:masterfrom
jclerman:label-language-prefs+diff-pretty-usage

Conversation

@jclerman

@jclerman jclerman commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This PR does not resolve a filed issue (I can file one if that's preferred).

I posted a question about this capability in the OBO Slack last week; this PR stems from the ensuing conversation.

  • docs/ have been added/updated
  • tests have been added/updated
  • mvn verify says all tests pass
  • mvn site says all JavaDocs correct
  • CHANGELOG.md has been updated

Summary

Add initial support for specifying a language-preference when showing entity-labels. Use that support for the diff command's pretty format. Solution is designed to be extensible for use with the other diff formats, and for other ROBOT commands that show entity-labels.

Background

robot did not previously have support for preferring a particular language when showing entity labels. For ontologies with max-1 label per entity, that doesn't matter - but some ontologies designed to support multi-language use may have multiple labels (one per each of several languages). Although multiple labels per entity violates an OBO principle, it may be worth revisiting that decision. Meantime, non-OBO ontologies can also use this tool and would benefit from the extension immediately.

Details

Context/Plan: First of several PRs

With this PR, the first step in a 3 (or 4) step plan for adding language-preference support to ROBOT is delivered.

Steps:

  1. This PR; ROBOT: diff (pretty): Add a reusable LanguagePreference helper and PreferredLanguageShortFormProvider, and wire a new --label-langs-priority option into diff so the pretty format can select entity labels by an ordered language list (with en→en-GB cascade, deterministic tie-breaking, a none token for untagged literals). NO CHANGE to behavior when the option is omitted.
  2. In owl-diff: Provider injection: Add backward-compatible renderWriter overloads to MarkdownGroupedDiffRenderer and HTMLDiffRenderer that accept a caller-supplied ShortFormProvider for labels instead of building their own, so consumers can control label rendering (no ROBOT dependency added).
  3. ROBOT: diff (markdown/html): Once the owl-diff change is released, pass ROBOT's PreferredLanguageShortFormProvider into the markdown and html renderers so --label-langs-priority works for all diff formats consistently.
  4. ROBOT: Other commands: Reuse the same LanguagePreference/provider to add --label-langs-priority (or equivalent) to the other label-displaying commands — export, explain, and report.

Ordering: PR3 depends on PR2 being merged and released (new owl-diff version bump in ROBOT); PRs 1, 2, and 4 are independent.

Note about language-preference cascade

As part of this implementation, label-language preferences follow a "specificity cascade": More-general tags (e.g. "en") can match to more-specific ones (e.g. "en-GB"). However, label-values match to the most-specific-possible position in the preference-list, and are prioritized with that in mind. So:

  • Binding (within a label): each label binds to the most specific preferred entry its tag matches (longest matching tag; exact beats cascade at equal length).
  • Winner (across labels): the label bound to the earliest entry wins. Ties are broken by exact-over-cascade, then alphanumerically.
  • Consequence: listing a specific tag after a general one (en,en-GB) deprioritizes it.

Future work

Remaining 3 steps (steps 2-4 as enumerated above). Note that the next step would be an update to owl-diff - not this repo.

@jclerman jclerman marked this pull request as ready for review July 6, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant