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

Validate ro-crate-metadata.json is flattened #27

Open
dnlbauer opened this issue Nov 5, 2024 · 2 comments
Open

Validate ro-crate-metadata.json is flattened #27

dnlbauer opened this issue Nov 5, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@dnlbauer
Copy link

dnlbauer commented Nov 5, 2024

Hi,

The RO-Crate documentation mentions that the JSON-LD in a valid ro-crate-metadata.json file is flattened:

https://www.researchobject.org/ro-crate/specification/1.1/structure.html

The RO-Crate Metadata File MUST contain RO-Crate JSON-LD; a valid JSON-LD 1.0 document in flattened and compacted form

From my tests, the validator does not validate against it. I.e. here is an unflattend JSON-LD that is recognized as a valid RO-Crate:

{
    "@context": "https://w3id.org/ro/crate/1.1/context",
    "@graph": [
        {
            "@type": "CreativeWork",
            "@id": "ro-crate-metadata.json",
            "conformsTo": {
                "@id": "https://w3id.org/ro/crate/1.1"
            },
            "about": {
                "@type": "Dataset",
                "@id": "./",
                "hasPart": [
                    {
                        "@type": "File",
                        "@id": "test.csv",
                        "encodingFormat": "text/csv",
                        "name": "This is a test file",
                        "description": "This is a test dataset"
                    }
                ],
                "name": "This is a test dataset",
                "description": "This is a test dataset",
                "license": {
                    "@id": "https://creativecommons.org/licenses/by/4.0/"
                },
                "datePublished": "2024-11-05"
            }
        }
    ]
}
@simleo
Copy link
Member

simleo commented Nov 12, 2024

I've found an example of unflattened RO-Crate that is still recognized as valid:

{
    "@context": "https://w3id.org/ro/crate/1.1/context",
    "@graph": [
        {
            "@id": "ro-crate-metadata.json",
            "@type": "CreativeWork",
            "about": {"@id": "./"},
            "conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"}
        },
        {
            "@id": "./",
            "@type": "Dataset",
            "name": "not_flattened",
            "description": "not_flattened",
            "license": "Apache-2.0",
            "datePublished": "2024-11-12",
            "hasPart": [{"@id": "somedir/"}]
        },
        {
            "@id": "somedir/",
            "@type": "Dataset",
            "name": "dataset",
            "description": "dataset",
            "variableMeasured": [
                {
                    "@type": "PropertyValue",
                    "propertyID": "https://example.org/terms/ru#realTime",
                    "name": "realTime",
                    "value": "42"
                }
            ]
        }
    ]
}

I ran

rocrate-validator -y validate -v -w 79 -nff -p ro-crate -o err.txt -l REQUIRED <crate>

@simleo simleo reopened this Nov 12, 2024
@dnlbauer
Copy link
Author

@simleo good catch!

So the reason for this is, that I (faulty) assumed that nested blocks always have an @id at this line:

Basically, it says "if there is a nested dict, and the dict has an @id, it must not have any other properties". Your nested entity does not have an id and is therefore falling through my net.

One option would be to assume that a dictionary that is not on @graph level always has to follow the format {"@id": "..."}. The check would then be:

if "@id" not in entity or len(entity) > 1: 
    return False

dnlbauer pushed a commit to dnlbauer/rocrate-validator that referenced this issue Nov 12, 2024
dnlbauer pushed a commit to dnlbauer/rocrate-validator that referenced this issue Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants