-
Notifications
You must be signed in to change notification settings - Fork 18
feat: strongly typed vocabularies #848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This is a proposal for Lyo Designer to generate better vocabulary helpers. It consists of two changes: 1. Generate a constant for every single class and prop. 2. Provide helpers for QNames of every prop for easy use in extended props. These changes together will ensure that users do not need to do any concatenation of strings or call "new QName" for well-known RDF props. The QName initialization is done lazily and only once per prop, which will improve adaptor performance. Finally, I would suggest shorter names: - `Dcterms.NS` instead of `DctermsVocabularyConstants.DUBLIN_CORE_NAMSPACE` - `Dcterms.PREFIX` instead of `DctermsVocabularyConstants.DUBLIN_CORE_NAMSPACE_PREFIX` - maybe even `Dcterms.Q.title()` instead of `Dcterms.QNames.title()` Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
|
Would be also good to introduce a helper request.getExtendedProperties().put(new QName("http://purl.org/dc/terms/", "identifier"), "test-id-123");
// to
request.getExtendedProperties().put(DctermsVocabularyConstants.QNames.identifier(), "test-id-123");
// to
request.getExtendedProperties().put(Dcterms.QNames.identifier(), "test-id-123");
// to
request.getExtendedProperties().put(Dcterms.Q.identifier(), "test-id-123");
// to
request.getExtendedProperties().put(Dcterms.identifier(), "test-id-123");
// to
request.setProp(DctermsVocabulary.identifier(), "test-id-123"); // or
request.setExtended(DctermsVocabulary.identifier(), "test-id-123"); |
|
@oslc-bot /test-all |
|
@oslc-bot /test-all |
| } | ||
|
|
||
| // Start of user code toString_finalize | ||
| result = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
| * The class resource, everything. | ||
| * @deprecated Use {@link Rdfs#RDFSCLASS_CLASS} instead. | ||
| */ | ||
| @Deprecated public static String RDFSCLASS_CLASS = "RdfsClass"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong, the suffix should not be added to the old class
| * The class resource, everything. | ||
| * @deprecated Use {@link Rdfs#RDFSCLASS_CLASS} instead. | ||
| */ | ||
| @Deprecated public static String TYPE_RDFSCLASS = Rdfs.RDFSCLASS_CLASS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jad-el-khoury this fixes a bug where this constant previously was http://www.w3.org/2000/01/rdf-schema#RdfsClass but should be http://www.w3.org/2000/01/rdf-schema#Class.
| <version>7.0.0-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
| <name>Lyo :: Domains</name> | ||
| <name>oslc-domains</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotta revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces strongly typed vocabulary helpers for OSLC domains to improve developer experience and performance. The changes eliminate the need for manual string concatenation or new QName() calls by providing:
- Static class constants for every RDF class and property
- QName helper methods with lazy initialization and caching
- Shorter, more ergonomic naming patterns
Key changes include:
- Adding new vocabulary helper classes (Dcterms, Foaf, Rdf, Rdfs, Prov, Oslc, Oslc_cm, Oslc_qm, Oslc_rm, Oslc_config) with constants and QName factory methods
- Deprecating old constant names in VocabularyConstants interfaces with migration paths
- Fixing typo: "Oscl" → "Oslc" throughout codebase
- Reformatting DomainConstants files for better readability
- Adding
setExtended()helper method to AbstractResource - Updating license headers to EPL-2.0 OR BSD-3-Clause format
Reviewed changes
Copilot reviewed 146 out of 146 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Dcterms.java, Foaf.java, Rdf.java, Rdfs.java, Prov.java, Oslc.java, Oslc_cm.java, Oslc_qm.java, Oslc_rm.java, Oslc_config.java | New vocabulary helper classes with constants and QName factory methods |
| *VocabularyConstants.java | Updated with _CLASS suffix, deprecation annotations, and javadocs |
| *DomainConstants.java | Reformatted for readability with improved comment placement |
| OslcVocabularyConstants.java | Fixed typo from OsclVocabularyConstants |
| OsclVocabularyConstants.java | Removed (typo file) |
| Nsp10DomainConstants.java | Removed unused Matlab domain |
| AbstractResource.java | Added setExtended() helper method |
| OslcClientTest.java | Added test demonstrating new QName helper usage |
| oslc-client/pom.xml | Added oslc-domains dependency |
| Various resource files | Updated license headers and generation timestamps |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Discussion.class); | ||
| } | ||
|
|
||
| public String toString() { |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method overrides Object.toString; it is advisable to add an Override annotation.
|
@oslc-bot /test-all |
This is a proposal for Lyo Designer to generate better vocabulary helpers. It consists of two changes:
These changes together will ensure that users do not need to do any concatenation of strings or call "new QName" for well-known RDF props. The QName initialization is done lazily and only once per prop, which will improve adaptor performance.
Finally, I would suggest shorter names:
Dcterms.NSinstead ofDctermsVocabularyConstants.DUBLIN_CORE_NAMSPACEDcterms.PREFIXinstead ofDctermsVocabularyConstants.DUBLIN_CORE_NAMSPACE_PREFIXDcterms.Q.title()instead ofDcterms.QNames.title()OslcRm.Shapes.NSand so on. Those are used less frequently.Printing prop description in the javadoc for both constants and helpers would be even better!
There is also a bunch of vocabs we could consider adding, see https://github.com/berezovskyi/ldsw-scraper/tree/main/data and https://github.com/OSLC/oslc4net/blob/main/OSLC4Net_SDK/OSLC4Net.Core/Model/OslcConstants.LDP.cs
Closes #0; Closes #00 (use exactly this syntax to link to issues, one issue per statement only!)
Checklist
@oslc-bot /test-allif not sure) or adds unit/integration tests.mvn package org.openrewrite.maven:rewrite-maven-plugin:run spotless:apply -DskipTests -P'!enforcer'if not, commit & push)