7. Interact with KTypes through the SDK#

7.1. Setting up#

Before you run this tutorial: make sure to have access to a DSMS-instance of your interest, alongwith with installation of this package and have establised access to the DSMS through DSMS-SDK (refer to Connecting to DSMS)

Import the needed classes and functions.

[1]:
from dsms import DSMS, KType

Now source the environmental variables from an .env file and start the DSMS-session.

[2]:
dsms = DSMS(env=".env")

7.2. Create KTypes#

New KTypes can be created by a simple class inititation.

[3]:
ktype = KType(
        id='batch',
        name='Batch'
)

ktype
[3]:
ktype:
  id: batch
  name: Batch
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: null
  updated_at: null

The commit method should be executed to synchronize the changes with the DSMS SDK.

[4]:
dsms.commit()

The type object will automatically get updated with after the commit.

[5]:
ktype
[5]:
ktype:
  id: batch
  name: Batch
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2025-01-17T11:54:17.493125'
  updated_at: '2025-01-17T11:54:17.493125'

7.3. Update KTypes#

The ktype object can be fetched using its id.

[6]:
ktype = dsms.ktypes.Batch
ktype
[6]:
ktype:
  id: batch
  name: Batch
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2025-01-17T11:54:17.493125'
  updated_at: '2025-01-17T11:54:17.493125'

We can change e.g. the name of the ktype

[7]:
ktype.name = 'Batches'
dsms.commit()

After the committing, we can see the changes of the ktype

[8]:
ktype
[8]:
ktype:
  id: batch
  name: Batches
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2025-01-17T11:54:17.493125'
  updated_at: '2025-01-17T11:54:18.373264'

7.5. Fetching KTypes#

The existing KTypes can be fetched as follows.

[9]:
for ktype in dsms.ktypes:
    print(ktype)
ktype:
  id: organization
  name: null
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2024-12-09T15:48:24.918527'
  updated_at: '2024-12-09T15:48:24.918527'

ktype:
  id: expert
  name: null
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2024-12-09T15:48:24.918527'
  updated_at: '2024-12-09T15:48:24.918527'

ktype:
  id: app
  name: null
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2024-12-09T15:48:24.918527'
  updated_at: '2024-12-09T15:48:24.918527'

ktype:
  id: dataset
  name: dataset
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2024-12-09T15:48:24.918527'
  updated_at: '2024-12-09T15:48:24.918527'

ktype:
  id: dataset-catalog
  name: dataset catalog
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2024-12-09T15:48:24.918527'
  updated_at: '2024-12-09T15:48:24.918527'

ktype:
  id: material
  name: Material
  context: false
  context_schema: []
  webform:
    semantics_enabled: true
    sections_enabled: true
    class_mapping:
    - https://w3id.org/emmo#EMMO_4207e895_8b83_4318_996a_72cfb32acd94
    sections:
    - id: id37bef167f3118
      name: Material spec
      inputs:
      - id: idd4eca7fb62c54
        label: Material type
        widget: Select
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options:
        - key: option1
          label: Crystal
          disabled: false
        - key: option2
          label: Liquid
          disabled: false
        - key: option3
          label: Gas
          disabled: false
        measurement_unit: null
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasMaterialClass_Object
          type: object_property
          class_iri: https://w3id.org/emmo#EMMO_39348191_08fd_4bb6_9b1e_012d5b2f1ff6
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: null
        range_options: null
        placeholder: null
      - id: id0ff68b6b11bf4
        label: Supplier
        widget: Multi-select
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options:
        - key: option1
          label: Company 1
          disabled: false
        - key: option2
          label: Company 2
          disabled: false
        measurement_unit: null
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasSupplier_Object
          type: object_property
          class_iri: https://w3id.org/steel/ProcessOntology/Supplier
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: null
        range_options: null
        placeholder: null
      - id: id8cc24aecb9282
        label: Product form
        widget: Radio
        required: false
        value: Sheet
        hint: null
        hidden: false
        ignore: false
        select_options:
        - key: option1
          label: Sheet
          disabled: false
        - key: option2
          label: Block
          disabled: false
        measurement_unit: null
        relation_mapping:
          iri: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
          type: object_property
          class_iri: https://w3id.org/emmo#EMMO_dd4b7d81_28a9_4801_8831_4cbab217e362
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: null
        range_options: null
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/emmo#EMMO_4207e895_8b83_4318_996a_72cfb32acd94
    suffix: slug
    source: material[*]
    suffix_from_location: true
    custom_relations:
    - object_location: material-type
      relation: https://w3id.org/steel/ProcessOntology/hasMaterialClass_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/emmo#EMMO_39348191_08fd_4bb6_9b1e_012d5b2f1ff6
    - object_location: supplier
      relation: https://w3id.org/steel/ProcessOntology/hasSupplier_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/steel/ProcessOntology/Supplier
    - object_location: product-form
      relation: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
      relation_type: object_property
      object_type:
        iri: https://w3id.org/emmo#EMMO_dd4b7d81_28a9_4801_8831_4cbab217e362
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2024-12-09T23:14:18.843010'
  updated_at: '2025-01-17T09:57:57.584798'

ktype:
  id: testingmachine
  name: Testing machine
  context: false
  context_schema: []
  webform:
    semantics_enabled: true
    sections_enabled: false
    class_mapping:
    - https://w3id.org/pmd/co/Specimen
    sections:
    - id: id18d888a9c9fa48
      name: Untitled Section
      inputs:
      - id: ida450e96a27a6e8
        label: Machine
        widget: Knowledge item
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options: []
        measurement_unit: null
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasMachine_Object
          type: object_property
          class_iri: https://w3id.org/steel/ProcessOntology/Machine
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: testingmachine
        range_options: null
        placeholder: null
      - id: idba8e853b2fdbe
        label: Specimen
        widget: Knowledge item
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options: []
        measurement_unit: null
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasTestPiece_Object
          type: object_property
          class_iri: https://w3id.org/pmd/co/Specimen
        relation_mapping_extra: null
        multiple_selection: true
        knowledge_type: specimen
        range_options: null
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/pmd/co/Specimen
    suffix: slug
    source: testingmachine[*]
    suffix_from_location: true
    custom_relations:
    - object_location: machine
      relation: https://w3id.org/steel/ProcessOntology/hasMachine_Object
      relation_type: object_property
      object_type: anyURI
    - object_location: specimen
      relation: https://w3id.org/steel/ProcessOntology/hasTestPiece_Object
      relation_type: object_property
      object_type: anyURI
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2024-12-12T17:56:45.095403'
  updated_at: '2025-01-16T15:19:06.989779'

ktype:
  id: specimen
  name: Specimen
  context: false
  context_schema: []
  webform:
    semantics_enabled: true
    sections_enabled: false
    class_mapping:
    - https://w3id.org/pmd/co/Specimen
    sections:
    - id: ida3c5c42685526
      name: Untitled Section
      inputs:
      - id: id175f885f8dda58
        label: Width
        widget: Slider
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options: []
        measurement_unit:
          label: Millimetre
          iri: http://qudt.org/vocab/unit/MilliM
          symbol: null
          namespace: http://qudt.org/vocab/unit
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasWidth_Object
          type: object_property
          class_iri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: null
        range_options:
          min: 0
          max: 1
          step: 0.1
          range: false
        placeholder: null
      - id: idef5a37328789f
        label: Length
        widget: Slider
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options: []
        measurement_unit:
          label: Millimetre
          iri: http://qudt.org/vocab/unit/MilliM
          symbol: null
          namespace: http://qudt.org/vocab/unit
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
          type: object_property
          class_iri: https://w3id.org/steel/ProcessOntology/TotalLength
        relation_mapping_extra:
          iri: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
          type: object_property
          class_iri: https://w3id.org/steel/ProcessOntology/TotalLength
        multiple_selection: false
        knowledge_type: null
        range_options:
          min: 0
          max: 1
          step: 0.1
          range: true
        placeholder: null
      - id: id54decb9641f9a
        label: Radius
        widget: Number
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        select_options: []
        measurement_unit:
          label: Millimetre
          iri: http://qudt.org/vocab/unit/MilliM
          symbol: null
          namespace: http://qudt.org/vocab/unit
        relation_mapping:
          iri: https://w3id.org/steel/ProcessOntology/hasRadius_Object
          type: object_property
          class_iri: https://w3id.org/emmo#EMMO_32dcd601_47c7_4028_b7fa_5e972ae57f12
        relation_mapping_extra: null
        multiple_selection: false
        knowledge_type: null
        range_options:
          min: 0
          max: 1
          step: 0.1
          range: false
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/pmd/co/Specimen
    suffix: slug
    source: specimen[*]
    suffix_from_location: true
    custom_relations:
    - object_location: width
      relation: https://w3id.org/steel/ProcessOntology/hasWidth_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: length[0]
      relation: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/steel/ProcessOntology/TotalLength
        unit: http://qudt.org/vocab/unit/MilliM
        suffix: min
    - object_location: length[1]
      relation: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
      relation_type: object_property
      object_type:
        suffix: max
        iri: https://w3id.org/steel/ProcessOntology/TotalLength
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: radius
      relation: https://w3id.org/steel/ProcessOntology/hasRadius_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/emmo#EMMO_32dcd601_47c7_4028_b7fa_5e972ae57f12
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2024-12-17T11:00:34.924035'
  updated_at: '2025-01-16T18:25:33.054442'

ktype:
  id: batch
  name: Batches
  context: false
  context_schema: []
  webform: null
  json_schema: null
  created_at: '2025-01-17T11:54:17.493125'
  updated_at: '2025-01-17T11:54:18.373264'

7.4. Delete KTypes#

The fetched ktype can be deleted by applying the del-operator to the dsms object with the individual KType object.

[10]:
del dsms[ktype]

As always, commit the changes.

[11]:
dsms.commit()

The available KTypes in the SDK can be fetched from an enum list.