Skip to content
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

Auto-generate SPDX3 model to RDF graph converters for RDF serialization #726

Closed
wants to merge 16 commits into from

Conversation

fholger
Copy link
Collaborator

@fholger fholger commented Jul 11, 2023

This PR implements a draft for RDF serialization output. The RDF writer/converter is mostly auto-generated from the spec-parser's json dump of the spdx3 model.

Note: there are currently some issues in the spec where minCount/maxCount are not properly set for some properties, which leads to issues in the code generator as it incorrectly assumes these fields should be lists. Thes issues will need to be addressed in the spec or the spec-parser. In the meantime, you may have to manually set the maxCount for these fields in the json dump to '1'.
Known affected fields: CreationInfo::[specVersion, created, dataLicense]

Also: some classes in the licensing namespace currently use properties from ExpandedLicense, but are not referencing the namespace correctly. These are subjectLicense and subjectAddition. These have to be prefixed with ExpandedLicense/ in the json dump manually until this issue is resolved in the spec.

Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Thanks, looks very good to me, just a few remarks.

return "Build"
if module.startswith("spdx_tools.spdx3.model.software"):
return "Software"
return "Core"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Core doesn't make sense to me as a default value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With the current manually written model classes, the core classes do not have their own subpackages within the spdx3.model package. So if they do not match any of the other namespace packages above, then "Core" is actually what remains.

dev/gen_model_to_rdf.py Outdated Show resolved Hide resolved
dev/gen_model_to_rdf.py Outdated Show resolved Hide resolved
dev/gen_model_to_rdf.py Show resolved Hide resolved
dev/gen_model_to_rdf.py Outdated Show resolved Hide resolved
dev/gen_model_to_rdf.py Outdated Show resolved Hide resolved
dev/gen_model_to_rdf.py Outdated Show resolved Hide resolved
if not clazz:
return True
if "SubclassOf" not in clazz["metadata"] or clazz["metadata"]["SubclassOf"] == "none" or clazz["metadata"]["SubclassOf"].startswith("xsd:"):
return not clazz["properties"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This assumes that we'll not have a non-literal base class without properties, doesn't it? Which will probably stay true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps it would be sufficient to check for subclasses of xsd types without properties. A class without any parent and without any properties probably doesn't make sense in the spdx spec, anyway.



def module_to_namespace(module: str) -> Optional[str]:
if not module.startswith("spdx_tools.spdx3.model"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

When is this the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For Python built-in types like str and datetime. Although it's possible that in the latest iteration of the generated code these cases no longer reach that function, I'd have to check.

@fholger fholger force-pushed the rdf_model branch 2 times, most recently from a08c3dc to e82cb96 Compare July 26, 2023 06:58
@fholger fholger marked this pull request as ready for review July 26, 2023 07:00
Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Runs without error using the changes from spdx/spdx-3-model#399.
Thanks for the great work! :)

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
…eral properties are treated as URIRefs; fixes shacl validation errors

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
…should be objects

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
… writer test

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
@maxhbr
Copy link
Member

maxhbr commented Mar 22, 2024

This is stale, and https://github.com/JPEWdev/shacl2code is expected to replace it

@maxhbr maxhbr closed this Mar 22, 2024
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.

None yet

3 participants