Re: Learning JSON-LD - some questions

Dear James,

First of all, to your second and third question: the JSON-LD you have is absolutely correct and, without knowing the details of the vocabulary you use, does not 'smell':-). As for the 'a' in the turtle output, that is a widely used Turtle idiom (does not have anything to do with JSON-LD: it is a shorthand for rdf:type.

I have made a few changes on your example, mostly to address your first question. The "@graph" construct makes it possible to gather nodes on the 'top level' as you wanted but also to share contexts. Ie, you do not have to repeat the context. The other change I have made is when you have properties whose values are simply strings, it is possible to make the JSON-LD data more compact by just using that string as a value. Though your construction of using an object with "@value" is absolutely correct, it is too complicated for that simple case.

Here is the new version:

{
    "@context": {
        "tt": "http://my-company-name/Tasking#",
        "task": "http://my-company-name/data/TaskingOntology#",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
    },    
    "@graph": [
        {
            "@id": "tt:Task_3",
            "@type": "task:Task",
            "task:itemToTeardown": {
                    "@id": "tt:TaskSubject"
            },
            "task:taskDescription": "The description of the task",
            "rdfs:label": "Task 3"
        },
        {
            "@id": "tt:taskparta_TaskSubject",
            "task:isComponentOf": {
                    "@id": "task:TaskSubject"
            },
            "rdfs:label": "Label A"
        },
        {
            "@id": "tt:taskpartb_TaskSubject",
            "task:isComponentOf": {
                    "@id": "task:TaskSubject"
            },        
            "rdfs:label": "Label B"       
        }   
    ]
}

I hope this helps

Sincerely

Ivan Herman





> On 6 Mar 2020, at 19:22, James Hudson <jameshudson3010@gmail.com> wrote:
> 
> I have the following JSON-LD document:
> 
> [
>     {
>         "@context": {
>             "tt": "http://my-company-name/Tasking# <http://my-company-name/Tasking#>",
>             "task": "http://my-company-name/data/TaskingOntology# <http://my-company-name/data/TaskingOntology#>",
>             "rdfs": "http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>"
>         },    
>         "@id": "tt:Task_3",
>         "@type": "task:Task",
>         "task:itemToTeardown": {
>                 "@id": "tt:TaskSubject"
>         },
>         "task:taskDescription": {
>                 "@value": "The description of the task"
>         },
>         "rdfs:label": {
>                 "@value": "Task 3"
>         }
>     },
>     {
>         "@context": {
>             "tt": "http://my-company-name/Tasking# <http://my-company-name/Tasking#>",
>             "task": "http://my-company-name/data/TaskingOntology# <http://my-company-name/data/TaskingOntology#>",
>             "rdfs": "http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>"
>         }, 
>         "@id": "tt:taskparta_TaskSubject",
>         "task:isComponentOf": {
>                 "@id": "task:TaskSubject"
>         },
>         "rdfs:label": {
>                 "@value": "Label A"
>         }
>     },
>     {
>         "@context": {
>             "tt": "http://my-company-name/Tasking# <http://my-company-name/Tasking#>",
>             "task": "http://my-company-name/data/TaskingOntology# <http://my-company-name/data/TaskingOntology#>",
>             "rdfs": "http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>"
>         },     
>         "@id": "tt:taskpartb_TaskSubject",
>         "task:isComponentOf": {
>                 "@id": "task:TaskSubject"
>         },        
>         "rdfs:label": {
>                 "@value": "Label B"
>         }        
>     }   
> ]
> 
> using https://github.com/RDFLib/rdflib-jsonld <https://github.com/RDFLib/rdflib-jsonld>, it will produce the following RDF:
> 
> @prefix ns1: <http://my-company-name/data/TaskingOntology# <http://my-company-name/data/TaskingOntology#>> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>> .
> @prefix xml: <http://www.w3.org/XML/1998/namespace <http://www.w3.org/XML/1998/namespace>> .
> @prefix xsd: <http://www.w3.org/2001/XMLSchema# <http://www.w3.org/2001/XMLSchema#>> .
> 
> <http://my-company-name/Tasking#Task_3 <http://my-company-name/Tasking#Task_3>> a ns1:Task ;
>     rdfs:label "Task 3" ;
>     ns1:itemToTeardown <http://my-company-name/Tasking#TaskSubject <http://my-company-name/Tasking#TaskSubject>> ;
>     ns1:taskDescription "The description of the task" .
> 
> <http://my-company-name/Tasking#taskparta_TaskSubject <http://my-company-name/Tasking#taskparta_TaskSubject>> rdfs:label "Label A" ;
>     ns1:isComponentOf ns1:TaskSubject .
> 
> <http://my-company-name/Tasking#taskpartb_TaskSubject <http://my-company-name/Tasking#taskpartb_TaskSubject>> rdfs:label "Label B" ;
>     ns1:isComponentOf ns1:TaskSubject .
> 
> I have the following questions:
> 
> (1) I need to duplicate the @context across several entries. Is there some way to avoid that? I note that in the RDF, the common prefixes can be shared.
> 
> (2) Does the JSON-LD stuff look "right"? Does anything smell? It is hard for me to judge having only starting looking at such things. 
> 
> (3) In the RDF, I see <http://my-company-name/Tasking#Task_3 <http://my-company-name/Tasking#Task_3>> a ns1:Task ; ... what is the 'a'? Where did it come from?
> 
> Thank you.
> 
> 
> 
> 
> 
> 
> 
> 


----
Ivan Herman, W3C 
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
ORCID ID: https://orcid.org/0000-0003-0782-2704

Received on Saturday, 7 March 2020 08:02:12 UTC