biothings / discovery-app

The Data Discovery Engine project by the CD2H Data working-group
http://discovery.biothings.io
Apache License 2.0
4 stars 9 forks source link

discussion/suggestion: enable viewing of marginality options from validation #102

Closed gtsueng closed 2 years ago

gtsueng commented 2 years ago

We can use the validation rules to define the cardinality of a property in DDE (one vs many). Similarly, we can use the validation rules to apply a binary definition of the marginality of a property in DDE (required vs not required). However, the validation rules can't be used to distinguish between optional vs recommended.

We got around this issue with the NIAID Dataset schema by re-defining existing properties to include cardinality and marginality:

    {
      "@id": "niaid:name",
      "@type": "rdf:Property",
      "rdfs:comment": "Descriptive name of the dataset",
      "rdfs:label": "name",
      "schema:domainIncludes": [{
        "@id": "niaid:NiaidDataset"
      }],
      "schema:rangeIncludes": [{
        "@id": "schema:Text"
      }],
      "schema:sameAs": {
        "@id": "schema:name"
      },
      "owl:cardinality": "one",
      "marginality": "required"
    }

Including marginality in this manner means that the property is not being re-used from schema.org but being redefined for each class within a schema. We could easily include something like "marginality": "recommended" in the validation for a property which will allow us to define the marginality of a property without redefining the property (especially since two classes within a schema may share a property, but have different marginality definitions for that property.

If we include marginality for properties in the validation, could it be exposed in the schema viewer?

gtsueng commented 2 years ago

We will test the inclusion of marginality in the validation. Specifically, it will be included in the following fashion:

"$validation": {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "type": "object",
        "properties": {
          "url": {
            "description": "URL of the item.",
            "type": "string",
            "format": "uri"
          },
          "name": {
            "description": "The name of the item.",
            "type": "string"
          },
          "identifier": {
            "description": "The identifier property represents any kind of identifier for any kind of <a class=\"localLink\" href=\"http://schema.org/Thing\">Thing</a>, such as ISBNs, GTIN codes, UUIDs etc. Schema.org provides dedicated properties for representing many of these, either as textual strings or as URL (URI) links. See <a href=\"/docs/datamodel.html#identifierBg\">background notes</a> for more details.",
            "type": "string"
          }
        },
        "required": ["name"],
        "recommended":["identifier"],
        "optional":["url"]
      }

This format has not caused any issues with https://www.jsonschemavalidator.net/ ; however, the site can be more generous that the python json schema validation library, so more testing should be done before adopting this format.

Once a format is determined, @marcodarko can include it in the UI

gtsueng commented 2 years ago

The above format seems to work as expected in python using the schema validation methods from the jsonschema python library. This library has caught errors that were missed by https://jsonschemavalidator.net previously.

marcodarko commented 2 years ago

@gtsueng great! I guess let me know when you have a working version of the updated schema so I have something to test and update the UI

gtsueng commented 2 years ago

@marcodarko, the Bioschemas classes here: https://discovery.biothings.io/view/bioschemas/ should all have "required","recommended' and "optional" properties (all the classes EXCEPT for BioChemEntity). You should be able to use that schema for testing and updating the UI.

marcodarko commented 2 years ago

Will be addressed in https://github.com/biothings/discovery-app/pull/104

gtsueng commented 2 years ago

It's beautiful!!!