Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation issues #532

Closed
hongcui opened this issue Dec 21, 2021 · 5 comments
Closed

validation issues #532

hongcui opened this issue Dec 21, 2021 · 5 comments
Labels
bug Something that should work but isn't, with an example and a test case.

Comments

@hongcui
Copy link

hongcui commented Dec 21, 2021

Describe the bug
We expect the given json file (simp.json.txt) should be validated against the given yaml schema (simp.yaml.txt), but it did not. Not sure if this is a bug or something we did wrong.

To Reproduce
Steps to reproduce the behavior:

  1. run
    linkml-validate -s simp.yaml simp.json
  2. See error message output by linkml-validate.

Expected behavior

Expected no error.

Screenshots
error

Desktop (if applicable, please complete the following information):

  • Windows 10
  • LinkML version downloaded on Nov 30, 2021

Additional context
Changing "required" to false in yaml would validate the instance (relatedResource), but why?
slot_usage: relationship: required: false target: required: false

The order in which properties are listed under slot_usage actually affects the reported error, why?

@hongcui hongcui added the bug Something that should work but isn't, with an example and a test case. label Dec 21, 2021
@cmungall
Copy link
Member

Hi @hongcui

It looks like you are trying to validate JSON-LD instance data using LinkML. I think there are a couple of different things going on here

  1. I am not sure your jsonld is valid. When I run it through Apache jena/riot, it yields a blank file. Same with https://json-ld.org/playground/
  2. Even if it were valid, a json-schema based approach will not work for json-ld documents

I can advise on you paths forward but it may help to know more about your overall requirements and strategy. Do you have requirements to use jsonld specifically? If you do, that's fine, linkml is appropriate, but there are things to be aware of.

I fixed your JSON-LD by adding a context (in fact this context was generated by gen-jsonld-context:

{
   "@context": {
      "isam": "http://resource.isamples.org/schema/",
      "linkml": "https://w3id.org/linkml/",
      "@vocab": "http://resource.isamples.org/schema/",
      "relatedResource": {
         "@type": "@id"
      }
   },
   "@id": "metadata/21547/Car2PIRE_0334",

        "relatedResource":[ {
        "target": "ark:/21547/Cat2INDO106431.1",
        "relationship": "derived"
  }]
}

Riot/jsonld playground generates what I think is your intended Turtle:

@prefix isam: <http://resource.isamples.org/schema/> .
@prefix linkml: <https://w3id.org/linkml/> .

<file:///Users/cjm/repos/linkml/tests/test_issues/input/metadata/21547/Car2PIRE_0334>
        isam:relatedResource  _:b0 .

_:b0    isam:relationship  "derived" ;
        isam:target        "ark:/21547/Cat2INDO106431.1" .

(I expect that is not the URI you expect for the sample record, but that can be addressed separately)

Let me know if I am on the right track here...

One thing to be aware of if you are using jsonld is that there are many possible ways to serialize the same RDF structure as JSON. See the list of qualifiers here:

https://blogs.pjjk.net/phil/json-schema-for-json-ld/

@cmungall
Copy link
Member

Here is a quick fix for you just now

Use this as your jsonld:

{
   "@context": {
      "isam": "http://resource.isamples.org/schema/",
      "linkml": "https://w3id.org/linkml/",
      "@vocab": "http://resource.isamples.org/schema/",
      "relatedResource": {
         "@type": "@id"
      }
   },
   "@id": "metadata/21547/Car2PIRE_0334",
    "@type": "isam:PhysicalSampleRecord",
    "relatedResource":[ {   
        "target": "ark:/21547/Cat2INDO106431.1",
        "relationship": "derived"
    }]
}

Convert this to turtle using a tool like riot:

riot --output turtle linkml_issue_532_data.jsonld > linkml_issue_532_data.ttl

you can see what the equivalent direct json (note: not the same structure as json-ld for the aforementioned reasons):

linkml-convert --no-validate -s linkml_issue_532.yaml linkml_issue_532_data.ttl > linkml_issue_532_data.json
{
  "id": "file:///Users/cjm/repos/linkml/tests/test_issues/input/metadata/21547/Car2PIRE_0334",
  "relatedResource": [
    {
      "target": "ark:/21547/Cat2INDO106431.1",
      "relationship": "derived"
    }
  ]
}

This validates as expected:

$ linkml-validate  -s linkml_issue_532.yaml linkml_issue_532_data.json && echo success
success

Now I appreciate that splitting your workflow into these steps is annoying, it's necessary with the current release as we're lacking some convenience functions for recognizing jsonld in the command line wrapper. The next release will make this all easier and more intuitive.

One final thing, for reasons I'll go into later, you should declare your multivalued slot relatedResource to be inlined as list. You also need an identifier slot for the sample record (otherwise there is no place for the Car2PIRE_0334 ID to go).

So this schema should work:

id: http://resource.isamples.org/schema/0.3
name: physicalSample
description: Schema for documenting physical samples
license: https://creativecommons.org/publicdomain/zero/1.0/
version: 20211022
prefixes:
  linkml: https://w3id.org/linkml/
  isam: http://resource.isamples.org/schema/
default_prefix: isam
imports:
  - linkml:types
default_range: string


classes:
  PhysicalSampleRecord:
    description: This is a data object that is a digital representation of a physical
      sample. It provides descriptive properties for any iSamples physical sample.
    slots:
      - id
      - relatedResource

  SampleRelation:
    description: Object specifying relationships to other samples, (particularly between
            subsamples and parent samples), or beteen samples and other related 
            information, e.g. publications using data from the sample or providing 
            background information to understand the sample.
    slots:
      - target
      - relationship
    slot_usage:
      target:
        required: true
      relationship:
        required: true

 
slots:
  id:
    identifier: true
  relatedResource:
    range: SampleRelation
    description: link to related resource with relationship property to indicate
      nature of connection. Target should be identifier for a resource.
    multivalued: true
    inlined_as_list: true   ### necessary: see https://github.com/linkml/linkml/pull/488
  relationship:
    range: string
    description: term to identify realationship between host sample and the sample
      relation target. Should be controlled vocabulary (ScopedName). for now
      start with string, 'derivedFrom'.
  target:
    range: string
    description: identifier for the target resource in the relationship. Start
      with string, should be Identifier object.
   
  

cmungall added a commit that referenced this issue Dec 22, 2021
Made command line utils aware of json-ld as a format,
and pass it accordingly. This removes the necessity
to first convert from json-ld to rdf using an external tool,
see also #532
cmungall added a commit that referenced this issue Dec 22, 2021
Made command line utils aware of json-ld as a format,
and pass it accordingly. This removes the necessity
to first convert from json-ld to rdf using an external tool,
see also #532
cmungall added a commit that referenced this issue Dec 22, 2021
@hongcui
Copy link
Author

hongcui commented Dec 22, 2021

Thank you @cmungall
It is very helpful!

@cmungall
Copy link
Member

If you upgrade to 1.1.15, the command line wrappers now recognize json-ld, so you can do this:

linkml-validate  -s linkml_issue_532.yaml linkml_issue_532_data.jsonld

and this should validate correctly

(you will still need to add the inlined_as_list to the schema, and add the context to the jsonld though)

@cmungall
Copy link
Member

Hi @hongcui do you have further questions or shall we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should work but isn't, with an example and a test case.
Projects
None yet
Development

No branches or pull requests

2 participants