Skip to content

Commit

Permalink
Add pydantic model gen; improve schema
Browse files Browse the repository at this point in the history
Schema
- add slot: pid_schema_version
- fix: Make ResourceInfo single-valued
- style: Gave enums singular name
  • Loading branch information
dalito committed Feb 25, 2024
1 parent 4ccb4af commit 984ae55
Show file tree
Hide file tree
Showing 20 changed files with 1,193 additions and 571 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ gen-examples:

gen-project: $(PYMODEL)
$(RUN) gen-project ${GEN_PARGS} -d $(DEST) $(SOURCE_SCHEMA_PATH) && mv $(DEST)/*.py $(PYMODEL)

# addition vs. template
$(RUN) gen-pydantic --pydantic_version 2 $(SOURCE_SCHEMA_PATH) > $(PYMODEL)/pid4cat_model_pydantic.py

test: test-schema test-python test-examples

Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ generator_args:
mergeimports: true
python:
mergeimports: true
pydantic:
mergeimports: true
pydantic-version: 2
prefixmap:
mergeimports: true
proto:
Expand Down
48 changes: 48 additions & 0 deletions explore_pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from linkml_runtime.dumpers import json_dumper, yaml_dumper
from pid4cat_model.datamodel import pid4cat_model_pydantic as p4c

p1_Agent = p4c.Agent(
name="Data Fuzzi",
contact_information=None,
person_orcid="0000-0000-0000-0000",
affiliation_ror=None,
role=p4c.PID4CatAgentRole.TRUSTEE,
)

p1_log = p4c.LogRecord(
datetime_log="2024-02-19T00:00:00Z",
has_agent=p1_Agent,
changed_field=p4c.ChangeLogField.STATUS,
description="as requested in issue #123",
)

p1_ressource_info = p4c.ResourceInfo(
label="Resource label",
description="Resource description",
resource_category=p4c.ResourceCategory.SAMPLE,
rdf_url="https://example.org/resource",
rdf_type="TURTLE",
schema_url="https://example.org/schema",
schema_type="XSD",
)

p1 = p4c.PID4CatRecord(
id="lik-123",
change_log=[p1_log],
landing_page_url="https://pid4cat.example.org/lik-123",
status=p4c.PID4CatStatus.REGISTERED,
pid_schema_version="0.1.0",
record_version="20240219v-0",
resource_info=p1_ressource_info,
related_identifiers=None,
dc_rights="CC0-1.0",
curation_contact="[email protected]",
)

c = p4c.Container(contains_pids=[p1])

print(p1)

print(json_dumper.dumps(p1))

print(yaml_dumper.dumps(c))
34 changes: 34 additions & 0 deletions explore_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from linkml_runtime.dumpers import json_dumper
from pid4cat_model.datamodel import pid4cat_model as p4c


p1_Agent = p4c.Agent(
person_orcid="0000-0000-0000-0000",
name="Data Fuzzi",
role="TRUSTEE",
)

p1_log = p4c.LogRecord(
datetime_log="2024-02-19T00:00:00Z",
has_agent=p1_Agent,
changed_field=p4c.ChangeLogField.STATUS, # "STATUS",
description="as requested in issue #123",
)

p1 = p4c.PID4CatRecord(
id="lik-1",
change_log=p1_log,
landing_page_url="https://pid4cat.example.org/lik-1",
status=p4c.PID4CatStatus.REGISTERED, # "REGISTERED",
record_version="20240219v-0",
resource_info={},
related_identifiers=None,
dc_rights="CC0-1.0",
curation_contact="[email protected]",
)

print(p1)

print(json_dumper.dumps(p1))

c = p4c.Container(contains_pids=[p1])
Binary file modified project/excel/pid4cat_model.xlsx
Binary file not shown.
23 changes: 15 additions & 8 deletions project/graphql/pid4cat_model.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ type Agent
contactInformation: String
personOrcid: String
affiliationRor: String
role: PID4CatAgentRoles
role: PID4CatAgentRole
}

type Container
{
containsPids: [PID4CatRecord]
}

type LogRecord
{
datetimeLog: String
agent: Agent
changedField: ChangeLogFields
hasAgent: Agent
changedField: ChangeLogField
description: String
}

Expand All @@ -20,26 +25,28 @@ type PID4CatRecord
id: Uriorcurie!
landingPageUrl: String
status: PID4CatStatus
resourceInfo: [ResourceInfo]
relatedIdentifiers: [Uriorcurie]
recordVersion: String
pidSchemaVersion: String
dcRights: String
curationContact: String
resourceInfo: ResourceInfo
relatedIdentifiers: [Uriorcurie]
changeLog: [LogRecord]!
}

type PID4CatRelation
{
relationType: [RelationTypes]
relationType: [RelationType]
relatedIdentifier: String
datetimeLog: String
agent: Agent
hasAgent: Agent
}

type ResourceInfo
{
label: String
description: String
resourceCategory: ResourceCategories
resourceCategory: ResourceCategory
rdfUrl: String
rdfType: String
schemaUrl: String
Expand Down
19 changes: 14 additions & 5 deletions project/jsonld/pid4cat_model.context.jsonld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"comments": {
"description": "Auto generated by LinkML jsonld context generator",
"generation_date": "2023-12-07T18:08:50",
"generation_date": "2024-02-25T23:40:28",
"source": "pid4cat_model.yaml"
},
"@context": {
Expand All @@ -16,10 +16,6 @@
"affiliation_ror": {
"@id": "schema:identifier"
},
"agent": {
"@type": "@id",
"@id": "schema:Agent"
},
"change_log": {
"@type": "@id",
"@id": "schema:identifier"
Expand All @@ -36,6 +32,9 @@
"contact_information": {
"@id": "schema:email"
},
"contains_pids": {
"@type": "@id"
},
"curation_contact": {
"@id": "schema:email"
},
Expand All @@ -48,6 +47,10 @@
"description": {
"@id": "schema:description"
},
"has_agent": {
"@type": "@id",
"@id": "schema:Agent"
},
"id": "@id",
"label": {
"@id": "schema:name"
Expand All @@ -61,12 +64,18 @@
"person_orcid": {
"@id": "schema:identifier"
},
"pid_schema_version": {
"@id": "schema:identifier"
},
"rdf_type": {
"@id": "schema:additionalType"
},
"rdf_url": {
"@id": "schema:additionalType"
},
"record_version": {
"@id": "schema:identifier"
},
"related_identifier": {
"@id": "schema:identifier"
},
Expand Down
Loading

0 comments on commit 984ae55

Please sign in to comment.