BioSchemas / specifications

Issue tracker, technical wiki, and example markup
https://bioschemas.org
54 stars 52 forks source link

additionalType not handling properties correctly #584

Closed ntwi closed 2 years ago

ntwi commented 2 years ago

I'm unable to get additionalType to correctly handle the additional properties of a MolecularEntity or Product when paired together. I know it has been advised to avoid using additionalType, but if anyone has a solution to this I'd really appreciate it.

Two minimal examples:

{
    "@context": "https://schema.org/",
    "@type": "MolecularEntity",
    "@id": "\/\/example.org\/products\/name\/#MolecularEntity",
    "additionalType": "Product",
    "name": "name",
    "url": "\/\/example.org\/products\/name\/",
    "description": "",
    "image": "",
    "sku": "TESTSKU",
    "offers": [
        {
            "@type": "Offer",
            "price": "$999.99",
            "priceSpecification": {
                "priceCurrency": "USD",
                "valueAddedTaxIncluded": "false"
            },
            "priceCurrency": "USD",
            "availability": "http://schema.org/InStock",
            "url": "\/\/example.org\/products\/name\/"

        }
    ],
    "monoisotopicMolecularWeight": "112.11404563"
}

The above will throw (The property sku is not recognized by the schema (e.g. schema.org) for an object of type MolecularEntity.) and The property offers is not recognized by the schema (e.g. schema.org) for an object of type MolecularEntity.

{
    "@context": "https://schema.org/",
    "@type": "Product",
    "@id": "\/\/example.org\/products\/name\/#Product",
    "additionalType": "MolecularEntity",
    "name": "name",
    "url": "\/\/example.org\/products\/name\/",
    "description": "",
    "image": "",
    "sku": "TESTSKU",
    "offers": [
        {
            "@type": "Offer",
            "price": "$999.99",
            "priceSpecification": {
                "priceCurrency": "USD",
                "valueAddedTaxIncluded": "false"
            },
            "priceCurrency": "USD",
            "availability": "http://schema.org/InStock",
            "url": "\/\/example.org\/products\/name\/"

        }
    ],
    "monoisotopicMolecularWeight": "112.11404563"
}

The above will throw (The property monoisotopicMolecularWeight is not recognized by the schema (e.g. schema.org) for an object of type Product.)

AlasdairGray commented 2 years ago

The additionalType property is not recognised as a type declaration; it is included in schema.org to support formats that microdata where you can only have one property declaration.

In JSON-LD, you can have multiple type declarations. The following code raises no warnings

{
    "@context": "https://schema.org/",
    "@type": ["MolecularEntity","Product"],
    "@id": "\/\/example.org\/products\/name\/#MolecularEntity",
    "name": "name",
    "url": "\/\/example.org\/products\/name\/",
    "description": "",
    "image": "",
    "sku": "TESTSKU",
    "offers": [
        {
            "@type": "Offer",
            "price": "$999.99",
            "priceSpecification": {
                "priceCurrency": "USD",
                "valueAddedTaxIncluded": "false"
            },
            "priceCurrency": "USD",
            "availability": "http://schema.org/InStock",
            "url": "\/\/example.org\/products\/name\/"

        }
    ],
    "monoisotopicMolecularWeight": "112.11404563"
}
ntwi commented 2 years ago

The additionalType page on schema.org is misleading. Thank you for this.

marco-brandizi commented 2 years ago

This is not coherent with the fact additionalProperty is declared as a subproperty of rdf:type. I've been discussing this here, the discussion mixed this and I'm still left with two problems:

In my projects, I'm using dc:type for the former case, plus a few conventions over PropertyValue for the second.

While these tricks have worked fairly well for me so far (example), the general problem is that they're no way common practice (letting a part, a standard). The whole schema.org community (or bioschema people only) might decide a different approach, but the bottom line is we probably have a need to agree common practice for these cases.