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

JSON-LD context (and frame) #386

Open
Tracked by #384
VladimirAlexiev opened this issue Mar 14, 2024 · 23 comments
Open
Tracked by #384

JSON-LD context (and frame) #386

VladimirAlexiev opened this issue Mar 14, 2024 · 23 comments
Labels
RDF impact to RDF

Comments

@VladimirAlexiev
Copy link

VladimirAlexiev commented Mar 14, 2024

To ensure that the JSON and RDF representation match perfectly, and to convert between them in the easiest possible way, it is best to use the JSON-LD standard:

  • For JSON->RDF (parsing) it's enough to define a JSON-LD context
  • For RDF->JSON (serialization) the same JSON-LD context is reused, and a Frame needs to be added to describe which nodes to insert as JSON sub-objects.

I searched in this project and despite my expectation, didn't find anything about JSON-LD.

I have done this in several projects/communities and have enough experience to do this correctly for AAS:

@mristin
Copy link
Collaborator

mristin commented Mar 14, 2024

@VladimirAlexiev
Copy link
Author

@mristin I haven't, thanks!
Have you tried it for JSON->RDF, and perhaps RDF->JSON?

@mristin
Copy link
Collaborator

mristin commented Mar 14, 2024

@mristin I haven't, thanks! Have you tried it for JSON->RDF, and perhaps RDF->JSON?

I don't use RDF so I haven't -- @wiresio can you please provide more info?

@wiresio
Copy link

wiresio commented Mar 14, 2024

@VladimirAlexiev - Within the context of W3C WoT standardisation, we implemented a triplestore based Thing Description (TD) Directory API according to: https://www.w3.org/TR/wot-discovery/

For this we needed a proper JSONLD context to realize the roundtripping TD-JSONLD -> RDF -> TD-JSONLD. From the code - which will be soon put to open source - you will see that we had to correct the W3C WoT JSONLD context a bit, to really retrieve the semantically exact JSONLD back from the roundtrip. So, yes we did it for W3C TDs.

We also realized the idea of doing another roundtrip, actually realizing a data format conversion by doing TD-JSONLD -> RDF -> (SPARQL construct query) -> AAS-JSON. For the last step after the SPARQL query, we carried out JSONLD framing with the AAS context mentioned above. So yes, roundtripping should also work for AAS using this context.

@wiresio
Copy link

wiresio commented Mar 15, 2024

@VladimirAlexiev - Thanks for the extensive list in #384.

What do you expect from this issue? JSON-LD context for AAS v3 is there (and can be auto-generated for future versions thanks to the integration in aas-core-codegen).

@VladimirAlexiev
Copy link
Author

Hi @wiresio and @mristin (and @mhrimaz)!
Please see https://github.com/VladimirAlexiev/aas-core-codegen/tree/main/test_data/jsonld_context/trials#readme.
The context almost works but needs 2 fixes (and sample data needs 1 fix).

Then see https://github.com/VladimirAlexiev/aas-core-codegen/tree/main/test_data/jsonld_context/trials#next-steps, in particular

I'll also make a PR but please give me some feedback about file location and naming:

  • Is it ok to replace context with context-fixed?
  • Is the trials folder ok where it is?

Cheers!

@mristin
Copy link
Collaborator

mristin commented Mar 17, 2024

@sebbader-sap @BirgitBoss should we move the JSON-LD here?

@mristin
Copy link
Collaborator

mristin commented Mar 17, 2024

@wiresio can you please patch the json-ld context generator? I know too little about RDF and JSON-LD to know what to fix.

@mristin
Copy link
Collaborator

mristin commented Mar 17, 2024

@VladimirAlexiev I think it would be best if you schedule a call to decide in a live discussion how we should go about RDF specification. I am irrelevant for the initial talks and decisions, but please insert me in the loop once you want to make changes to aas-core-codegen.

@wiresio
Copy link

wiresio commented Mar 17, 2024

@VladimirAlexiev - thanks for pointing this out!

@ethieblin - can you please have a look?

@sebbader-sap
Copy link
Contributor

@sebbader-sap @BirgitBoss should we move the JSON-LD here?

Generally, it does make sense to put the context file also into the RDF schema folder. I can also create a proper redirect to have a nice looking URL for it. E.g. "@context": "https://admins-shell.io/3/0/context.json".

My main problem is that the whole RDF (in particular JSON-LD) needs more "love" (aka. "time"), which is currently the limiting factor. I know that the "WG Ontologies" also has a bunch of improvement proposals in their pipeline, which all together would create a sound picture.

If we can combine all these different activities, maybe in late April or so, I can certainly help too.

@VladimirAlexiev
Copy link
Author

Hi @sebbader-sap, thanks for the response!

I should be able to give some "love" as part of Manufacturing Data Space project that just started.
If IDTA is willing to change the RDF representation to make it better, then Ontotext will be happy to help.
I have a call with @wiresio and @egekorkan on Mar 28 and maybe we'll discuss this (and eClass semantic representation).

Where is the "WG Ontologies" and their improvement proposals?
#384 should go in there.

Cheers!

@sebbader-sap
Copy link
Contributor

Where is the "WG Ontologies" and their improvement proposals?

It's an IDTA-internal group, I don't think that there is a public space. Is Ontotext an IDTA member? If so, you can join them.

@ethieblin
Copy link

ethieblin commented Mar 19, 2024

Hello,

Thanks for your feedback on the JSON-LD Context.

I definitely agree that the ontology part of AAS needs more "love" :) And I agree with the " tickets you have created: xs:string, langStrings and the URI formation of the properties.

Regarding the JSON-LD Context:

  • I agree that it should be served on the spec and made accessible via a dedicated URL
  • I created a PR to add the wrapping "@context" tag in aas-code-gen.
  • regarding the "modelType" to transform into "rdf:type" or "@type", we are currently using the jsonld.js to perform roundtripping. Note that it exports the RDF version in ntriples and not turtle. The framing based on the context in this actual form functions correctly. We do AAS/JSON + JSON-LD Context => N-triples that we store in a triplestore, then N-triples (queries from the triplestore) => AAS/JSON by using a frame based on the JSON-LD Context and the URI of the root node.

@VladimirAlexiev
Copy link
Author

VladimirAlexiev commented Mar 19, 2024

@ethieblin I use jsonld-cli (npm install -g jsonld-cli) which is also by digital-bazaar and (supposed to be) the same code that powers the playground. jsonld compact produces this, which is bad style

    "globalAssetId": {
      "modelType": "xs:string", // should be "@type"
      "@value": "something_eea66fa1"
    }

it exports the RDF version in ntriples and not turtle.

Yes (ntriples or nquads), that's why I use extra tools to make turtle so I can compare to the Turtle examples.

framing based on the context in this actual form functions correctly.

That's great! But we need more holistic examples to make sure

Please see https://github.com/VladimirAlexiev/aas-core-codegen/tree/main/test_data/jsonld_context/trials#next-steps and comment (here).

Can you please answer:

I'll also make a PR but please give me some feedback about file location and naming:
Is it ok to replace context with context-fixed?
Is the trials folder ok where it is?

After these trials are merged, we can more easily extend/correct them.

@VladimirAlexiev
Copy link
Author

jsonld-cli (v2.0.0) has just been upgraded to jsonld.js v8.3.2+: digitalbazaar/jsonld-cli#18

ethieblin added a commit to logilab/aas-core-codegen that referenced this issue Mar 20, 2024
This issue is related to admin-shell-io/aas-specs#386
It is needed so that the context can be served directly at a given URL
and digested in a JSON-LD document
@ethieblin
Copy link

ethieblin commented Mar 20, 2024

Ah yes you are right on the "modelType" vs "@type". The issue is more general.
From my experience with JSON-LD framing, a context that overrides the JSON-LD keywords may often result in errors.

Having one of either of the following solutions should in theory give the same result. In practice, it may fall into an undefined behaviour of the JSON-LD framing libraries.

  "modelType": {"@type": "@id", "@id": "rdf:type"},

or

  "modelType": "@type"

For your comments

I'll also make a PR but please give me some feedback about file location and naming
Is the trials folder ok where it is?

I am not a maintainer of aas-core-codegen repository, so I have little impact here. The file locations and naming are fine with me, or perhaps they could be placed in tests/jsonld_context as a report ? cc @mristin

Is it ok to replace context with context-fixed?

In this PR I added the wrapping "@context" tag. Please have a look. To me if modifications are to be made, they should be in the code that generates the context and not in the context itself (that may be overwritten by launching the code again).

@ethieblin
Copy link

Regarding the next steps you propose:

Produce a holistic Turtle example that includes as many submodels as possible, including numbers (decimal/float) and langStrings with real lang tags

We can also rely on the different JSON examples and RDF examples on the specs repository

Load some realistic AAS data in a semantic repository, and work on a Frame to produce several JSON messages according to JSON schemas

Not sure what you mean by "several JSON messages" you mean validation messages, error messages?

The context should live in https://github.com/admin-shell-io/aas-specs/, not in https://github.com/aas-core-works/aas-core-codegen/blob/main/test_data/jsonld_context/aas_core_meta.v3/output/

Agreed

The context needs to be served from some permanent URL, with Content Type application/ld+json

Agreed

Enrich the context to cover langStrings (#382) by mapping language, text to @language, @value.

That would require a change in the ontology and the specs examples as well

mristin pushed a commit to aas-core-works/aas-core-codegen that referenced this issue Mar 20, 2024
This patch is related to the [issue 386 of aas-specs]. We fix 
the JSON-LD generation so that the context can be served
directly at a given URL and digested in a JSON-LD document.

[issue 386 of aas-specs]: admin-shell-io/aas-specs#386
@mristin
Copy link
Collaborator

mristin commented Mar 20, 2024

I'll also make a PR but please give me some feedback about file location and naming
Is the trials folder ok where it is?

I am not a maintainer of aas-core-codegen repository, so I have little impact here. The file locations and naming are fine with me, or perhaps they could be placed in tests/jsonld_context as a report ? cc @mristin

Let me please clarify a confusion. The JSON-LD does not "live" at aas-core-codegen. It's were the generator lives. We simply recorded the output for V3.0 and used it as a golden data for tests. When the V3.1 comes (and future versions), we will probably not keep the outputs as test data.

The parties interested in the usage of JSON-LD definitely need to clarify whether you want to stick to aas-core-codegen (and patch the generator accordingly), take a hybrid approach (generate a base JSON-LD with aas-core-codegen, but then additionally write a script to patch it automatically or manually make changes), or go back to the manual specification.

It is probably best if you schedule a conference call, and make a decision. I fear that the discussions through GitHub issues are too scattered to come to a viable and thought-through solution.

@VladimirAlexiev
Copy link
Author

@ethieblin

rely on the different JSON examples and RDF examples on the specs repository

Can you point me to examples with langStrings and datatyped values?
I don't fully grasp the minimal/maximal philosophy, but I still think it'd be nicer to have a big realistic example so you can check all mapping features in one place, rather than having to check multiple files.

work on a Frame to produce several JSON messages according to JSON schemas
Not sure what you mean by "several JSON messages"

When I wrote this, I didn't know that your Context also serves as a Frame.
My point is this:

  • imagine you have a semantic repo with a gazillion triples about a thousand AAS models
  • before you Frame some response, you have to write a Query to get the data you need
  • That data may be about multiple AAS, one complete AAS, only a submodel of an AAS, etc etc
  • Are you sure your "Context as Frame" works for all these different cases? Won't you need to at least specify different "root points"?
  • Do you have tests for such different cases?

This goes into future work on realistic use cases, so it may be too early to discuss...

I think most people think of AAS as documents: there are different file/message formats, hopefully with round-trip between them, there's AASX zip format, etc.
But to work efficiently with this data, you need to store it somewhere. RDF repositories are databases that can accommodate such flexible data directly, no need for schemas or mapping into tables. Then to get out the documents you need, may require some tweaking of frames, or make

it may fall into an undefined behaviour of the JSON-LD framing libraries.

Please say more. I think mapping a prop to rdf:type shouldn't run this risk, but if it does we need to look at it very carefully.
You do use "scoped contexts" but I don't remember whether they are local to type or property?

cover langStrings (#382)
That would require a change in the ontology and the specs examples as well

Yep.

Same re Datatyped literals (#284): instead of

<https://admin-shell.io/aas/3/0/Property/valueType> <https://admin-shell.io/aas/3/0/DataTypeDefXsd/AnyUri>

we want to map to

"@type": "xs:anyURI"

@mristin

whether you want to stick to aas-core-codegen (and patch the generator accordingly),

This is definitely the best approach, if it is feasible. As we use more tricks in the context, it may become less feasible. You're best qualified to say whether it is feasible!

@mristin
Copy link
Collaborator

mristin commented Mar 21, 2024

@mristin

whether you want to stick to aas-core-codegen (and patch the generator accordingly),

This is definitely the best approach, if it is feasible. As we use more tricks in the context, it may become less feasible. You're best qualified to say whether it is feasible!

I think it has to be a hybrid approach (generaee RDF+SHACL), then patch with a script.

Otherwise, the expressivity of RDF would need to be captured by aas-core-codegen, which is a huge effort.

@mristin
Copy link
Collaborator

mristin commented Mar 21, 2024

@VladimirAlexiev

I don't fully grasp the minimal/maximal philosophy, but I still think it'd be nicer to have a big realistic example so you can check all mapping features in one place, rather than having to check multiple files.

Please see:
https://www.researchgate.net/publication/374055610_Maturity_Evaluation_of_SDKs_for_I40_Digital_Twins
about how we generated the examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RDF impact to RDF
Projects
None yet
Development

No branches or pull requests

6 participants