Re: Learning JSON-LD - some questions

Prefixes (task, tt) are only recognized when the expansion algorithm knows
that it's a resource. Otherwise, it's treated as a string.

`{"@id": "tt:taskEnum"}` explicitly declares it to be a resource, and hence
the URI is expanded.

You could do that in the context, and thus allow "tt:taskEnum" in the data,
like this:

{
  "@context": {
    "tt": "http://company/tasking#",
    "task": "http://company/taskont#",
    "task:enumerated": {"@type": "@id"}
  },
  "task:enumerated": "tt:taskEnum"
}

Or, better, use `@vocab` and also put taskEnum into the context:

{
  "@context": {
    "tt": "http://company/tasking#",
    "task": "http://company/taskont#",
    "enumerated": {"@type": "@vocab", "@id": "task:enumerated},
    "Enum": {"@id": "tt:taskEnum"}
  },
  "enumerated": "Enum"
}

(Assuming that there are a limited, enumerable set of values for
task:enumerated)

Hope that helps!

Rob


On Mon, Mar 9, 2020 at 8:56 AM James Hudson <jameshudson3010@gmail.com>
wrote:

> Hello Ivan,
>
> Thank you for your quick reply. It was useful.
>
> Your point regarding
>
>      "task:taskDescription": {
>                 "@value": "The description of the task"
>         },
>
> vs
>
>      "task:taskDescription": "The description of the task",
>
> is well taken.
>
> It does bring up another question.
>
> Let's say that I had:
>
> {
>     "@context": {
>         "tt": "http://my-company-name/Tasking#",
>         "task": "http://my-company-name/data/TaskingOntology#"
>     },
>     "@graph": [
>         {
>             "@id": "tt:taskparta_TaskSubject",
>             "task:enumerated": {
>                 "@id": "tt:taskEnum"
>             }
>         }
>     ]
> }
>
> In this case, tt:taskEnum can be correctly expanded to
> http://my-company-name/Tasking#
>
> However, if I did "task:enumerated": "tt:taskEnum", then it would not be
> expanded.
>
> I am just trying to understand the expansion rules a bit better. Is there
> anything you would be able to say to help me understand the expansion rules?
>
> But, this may be a case of needing to read the spec (RTFM). It may help if
> there was a particular part of the spec that speaks directly to this issue.
>
> Regards,
> James
>
> On Sat, Mar 7, 2020 at 3:02 AM Ivan Herman <ivan@w3.org> wrote:
>
>> 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#",
>>             "task": "http://my-company-name/data/TaskingOntology#",
>>             "rdfs": "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#",
>>             "task": "http://my-company-name/data/TaskingOntology#",
>>             "rdfs": "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#",
>>             "task": "http://my-company-name/data/TaskingOntology#",
>>             "rdfs": "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, it will produce the
>> following RDF:
>>
>> @prefix ns1: <http://my-company-name/data/TaskingOntology#> .
>>
>> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
>>
>> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
>>
>> @prefix xml: <http://www.w3.org/XML/1998/namespace> .
>>
>> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
>>
>>
>> <http://my-company-name/Tasking#Task_3> a ns1:Task ;
>>
>>     rdfs:label "Task 3" ;
>>
>>     ns1:itemToTeardown <http://my-company-name/Tasking#TaskSubject> ;
>>
>>     ns1:taskDescription "The description of the task" .
>>
>>
>> <http://my-company-name/Tasking#taskparta_TaskSubject> rdfs:label "Label A" ;
>>
>>     ns1:isComponentOf ns1: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> *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
>>
>>

-- 
Rob Sanderson
Semantic Architect
The Getty Trust
Los Angeles, CA 90049

Received on Monday, 9 March 2020 16:05:48 UTC