From 70f555b0501a3d5333da893914f26e277d8c50b9 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Mon, 14 Aug 2023 20:19:03 +0200 Subject: [PATCH] Updated readme and main script --- examples/datamodel_as_rdf/README.md | 11 +++++++++-- examples/datamodel_as_rdf/main.py | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/datamodel_as_rdf/README.md b/examples/datamodel_as_rdf/README.md index 5e72589d9..ce77a6233 100644 --- a/examples/datamodel_as_rdf/README.md +++ b/examples/datamodel_as_rdf/README.md @@ -1,5 +1,12 @@ Datamodels as RDF ================= -This example will show how DLite and Pydantic data models can be serialised to RDF. +This example will show how DLite and Pydantic data models can be +serialised to RDF. -The example requires that you have Pydantic v1.x installed. +Two examples are included: +- **pydantic_nested**: Shows serialisation of nested pydantic models into RDF. + Works for both Pydantic v1 and v2. +- **dataresource**: Shows serialisation of a Pydantic model of a OTEAPI + dataresource to RDF. This example has two versions, one for Pydantic v1 + ([dataresource.py](dataresource.py)) and one for Pydantic v2 + ([dataresource_pydantic2.py](dataresource_pydantic2.py)). diff --git a/examples/datamodel_as_rdf/main.py b/examples/datamodel_as_rdf/main.py index 4377b73bb..21f4d276b 100644 --- a/examples/datamodel_as_rdf/main.py +++ b/examples/datamodel_as_rdf/main.py @@ -1,3 +1,15 @@ """Main script running all tests in this repo.""" -import pydantic_nested -import dataresource +import pydantic + + +pydantic_major = int(pydantic.__version__.split(".")[0]) + +# Run examples +import pydantic_nested # works for both Pydantic v1 and v2 + +if pydantic_major == 1: + # Only Pydantic v1 + import dataresource +elif pydantic_major == 2: + # Only Pydantic v2 + import dataresource_pydantic2