RDFLib / rdflib-jsonld

JSON-LD parser and serializer plugins for RDFLib
Other
280 stars 71 forks source link

v0.4.0 fails to parse what 0.5.0.dev0 can #81

Closed James-Hudson3010 closed 4 years ago

James-Hudson3010 commented 4 years ago

I have the following json-ld file:

{
    "@context": {        
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "hr": "http://learningsparql.com/ns/humanResources#",
        "d": "http://learningsparql.com/ns/data#",
        "sh": "http://www.w3.org/ns/shacl#",
        "sch": "http://schema.org/"
    },
    "@graph": [
        {
            "@id": "hr:Employee",
            "@type": "rdfs:Class",
            "rdfs:comment": "a good employee",
            "rdfs:label": "model"
        },
        {
            "@id": "hr:Another",
            "@type": "rdfs:Class"
        },
        {
            "@id": "hr:name",
            "@type": "rdf:Property",
            "sch:domainIncludes":  [
                {
                    "@id": "hr:Employee"
                }
            ]
        },
        {
            "@id": "hr:freestanding",
            "@type": "rdf:Property",
            "sch:rangeIncludes": [
                {
                    "@id": "sch:Text"
                }
            ]            
        },        
        {
            "@id": "hr:nosuper",
            "@type": "rdf:Property",
            "sch:rangeIncludes": [
                {
                    "@id": "sch:Text"
                }
            ],
            "sch:domainIncludes":  [
                {
                    "@id": "hr:Uncreated"
                }
            ]                        
        },             
        {
            "@id": "hr:randomtype",
            "@type": "hr:invalidtype",
            "rdfs:comment": "some comment about randomtype",
            "rdfs:label": "some label about randomtype"
        },        
        {
            "@id": "hr:typo",
            "@type": "rdfs:Classs",
            "rdfs:comment": "some comment about typo",
            "rdfs:label": "some label about typo"
        },        
        {
            "@id": "hr:missing",
            "rdfs:comment": "some comment about missing"           
        }
    ]
}

If I use json-ld 0.4.0 (the last released version) with the following code:

import toml
import json
import os
import glob
import rdflib

from pprint import pprint

PATH = "/Users/jamesh/depot/sparql_work/data_graph.jsonld"

datagraph = open( PATH, "r" ).read()
g = rdflib.Graph().parse( data = datagraph, format = 'json-ld' )

print( g.serialize( format = 'ttl' ).decode( 'utf8' ) ) 

the what is printed is:

@prefix d: <http://learningsparql.com/ns/data#&gt; .
@prefix hr: <http://learningsparql.com/ns/humanResources#&gt; .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix sch: <http://schema.org/&gt; .
@prefix sh: <http://www.w3.org/ns/shacl#&gt; .
@prefix xml: <http://www.w3.org/XML/1998/namespace&gt; .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#&gt; .

However, if I clone the project and pip install from the master branch (0.5.0.dev0), I get the expected result:

@prefix d: <http://learningsparql.com/ns/data#&gt; .
@prefix hr: <http://learningsparql.com/ns/humanResources#&gt; .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix sch: <http://schema.org/&gt; .
@prefix sh: <http://www.w3.org/ns/shacl#&gt; .
@prefix xml: <http://www.w3.org/XML/1998/namespace&gt; .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#&gt; .

hr:Another a rdfs:Class .

hr:Employee a rdfs:Class ;
    rdfs:label "model" ;
    rdfs:comment "a good employee" .

hr:freestanding a rdf:Property ;
    sch:rangeIncludes sch:Text .

hr:missing rdfs:comment "some comment about missing" .

hr:name a rdf:Property ;
    sch:domainIncludes hr:Employee .

hr:nosuper a rdf:Property ;
    sch:domainIncludes hr:Uncreated ;
    sch:rangeIncludes sch:Text .

hr:randomtype a hr:invalidtype ;
    rdfs:label "some label about randomtype" ;
    rdfs:comment "some comment about randomtype" .

hr:typo a rdfs:Classs ;
    rdfs:label "some label about typo" ;
    rdfs:comment "some comment about typo" .

Needless to say, I am eager for another release as soon as possible.

niklasl commented 4 years ago

I just released rdflib-jsonld 0.5.0 from current master. I hope this makes things better!

James-Hudson3010 commented 4 years ago

Awesome. Thank you.