monarch-initiative / koza

Data transformation framework for LinkML data models
https://koza.monarchinitiative.org/
BSD 3-Clause "New" or "Revised" License
48 stars 4 forks source link

Add linkml-validator support #77

Closed kevinschaper closed 2 years ago

kevinschaper commented 2 years ago

We should add linkml-validator support directly into Koza.

Command line usage should be something like an optional extra argument specifying a schema that will trigger validation

koza transform --source ingest.yaml --schema biolink-model.yaml

or directly as a module with:

transform_source(
            source="...",
            output_dir="...",
            output_format=OutputFormat.tsv,
            local_table=None,
            global_table=None,
            schema="./biolink-model.yaml"            
        )

Here is the linkml-validator module example

from linkml_validator.validator import Validator

data_obj = {
    "id": "obj1",
    "name": "Object 1",
    "type": "X"
}
validator = Validator(schema="examples/example_schema.yaml")
validator.validate(obj=data_obj, target_class="NamedThing")

We'll likely want to make the schema an argument to set_koza_app and have the validator be defined in the KozaApp init, where a validator can be instantiated.

Then the write method should run validation if a validator exists.