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

Add RDF support #427

Closed
mhrimaz opened this issue Jan 8, 2024 · 11 comments
Closed

Add RDF support #427

mhrimaz opened this issue Jan 8, 2024 · 11 comments

Comments

@mhrimaz
Copy link

mhrimaz commented Jan 8, 2024

RDF is also part of the specification. It would be great to add support to handle RDF representation of AAS.

@mristin
Copy link
Contributor

mristin commented Jan 8, 2024

@mhrimaz We already generate RDF+SHACL schemas. Could you please clarify?

@mhrimaz
Copy link
Author

mhrimaz commented Jan 8, 2024

I don't mean the ontology and SHACL. I mean handling the RDF serialization so you can also load a RDF file like:

@prefix aas: <https://admin-shell.io/aas/3/0/> .

<MySubmodel> a aas:Submodel ;
    <https://admin-shell.io/aas/3/0/Identifiable/id> "MySubmodel" .

and convert it to JSON or vice versa.

{
  "id": "MySubmodel",
  "modelType": "Submodel"
}

@wiresio
Copy link

wiresio commented Jan 8, 2024

We recently added generation of JSON-LD context. We it, you can do:

<urn:aas> aas:Environment\/submodels <urn:sub> ; a aas:Environment .
<urn:sub> aas:Referable\/idShort "MySubmodel" ; a aas:Submodel .

Convert to JSON-LD and then do a JSON-LD framing with:

{
  "@context": {GENERATEDCONTEXT},
  "Environment/submodels": {}
}

@mhrimaz
Copy link
Author

mhrimaz commented Jan 8, 2024

@wiresio that's great!

I couldn't find anything related to json-ld in the current python. Are you guys planning to add it?

And other than generation of JSON-LD (RDF Turtle), is that possible to read RDF Turtle (JSON-LD) data ?

@mhrimaz
Copy link
Author

mhrimaz commented Jan 8, 2024

We recently added generation of JSON-LD context. We it, you can do:

<urn:aas> aas:Environment\/submodels <urn:sub> ; a aas:Environment .
<urn:sub> aas:Referable\/idShort "MySubmodel" ; a aas:Submodel .

How can I generate the provided triple? are they now part of the generated SDKs? I would appreciate if you can provide an example.

The provided file that you sent is the definition of elements and the relations between them. similar to the rdf-ontology.

So my question is how to convert a Submodel to json-ld and read it?

Here a example Submodel in json-ld:

[
  {
    "@id":"https://admin-shell.io/aas/3/0/Submodel"
  },
  {
    "@id":"urn:sub",
    "https://admin-shell.io/aas/3/0/Identifiable/id":[
      {
        "@value":"MySubmodel"
      }
    ],
    "@type":[
      "https://admin-shell.io/aas/3/0/Submodel"
    ]
  }
]

or in RDF turtle:

@prefix aas: <https://admin-shell.io/aas/3/0/> .

<urn:sub> aas:Identifiable\/id "MySubmodel" ; 
a aas:Submodel .

or in JSON turtle:

{
  "id": "MySubmodel",
  "modelType": "Submodel"
}

@wiresio
Copy link

wiresio commented Jan 8, 2024

PREFIX aas: <https://admin-shell.io/aas/3/0/>
<urn:aas> aas:Environment\/submodels <urn:sub> ; a aas:Environment .
<urn:sub> aas:Referable\/idShort "MySubmodel" ; a aas:Submodel .

results in:

{
  "@graph": [
    {
      "@id": "urn:sub",
      "aas:Referable/idShort": "MySubmodel",
      "@type": "aas:Submodel"
    },
    {
      "@id": "urn:aas",
      "@type": "aas:Environment",
      "aas:Environment/submodels": {
        "@id": "urn:sub"
      }
    }
  ],
  "@context": {
    "aas": "https://admin-shell.io/aas/3/0/"
  }
}

When you frame it, you get:

...
  },
  "@id": "urn:aas",
  "modelType": "Environment",
  "submodels": [
    {
      "@id": "urn:sub",
      "modelType": "Submodel",
      "idShort": "MySubmodel"
    }
  ]
}

You can try it here: https://json-ld.org/playground/

@mristin
Copy link
Contributor

mristin commented Jan 8, 2024

@mhrimaz wrote:

I mean handling the RDF serialization so you can also load a RDF file [...]

There are no RDF modules in all of standard libraries, so this makes it a no-go for the current core SDKs which aim at zero or few dependencies.

I would be glad to mentor the pull request if somebody wants to write a generator for an RDF de/serializer and publish the generated code as a separate package.

@mhrimaz
Copy link
Author

mhrimaz commented Jan 8, 2024

@wiresio I think you are one step ahead. What is missing is the step before it. converting objects to rdf.

Key simpleKey = new DefaultKey.Builder()
                .value("simple")
                .type(KeyTypes.GLOBAL_REFERENCE)
                .build();
// This part is not in AAS4j, implemented by me. Model is a Apache Jena model.
RDFSerializationResult rdfSerializationResult = new DefaultKeyRDFHandler().toModel(simpleKey);
rdfSerializationResult.getModel().write(System.out, Lang.TTL.getName());

which produce the following RDF Turtle:

[ a       <https://admin-shell.io/aas/3/0/Key>;
  <https://admin-shell.io/aas/3/0/Key/type>
          "GLOBAL_REFERENCE";
  <https://admin-shell.io/aas/3/0/Key/value>
          "simple"
] .

Or with aas-core3.0-python:

import json
import aas_core3.types as aas_types
import aas_core3.verification as aas_verification
import aas_core3.jsonization as aas_jsonization
import aas_core3.xmlization as aas_xmlization

example = aas_types.Submodel(id="some-unique-global-identifier")
print(aas_jsonization.to_jsonable(example)) # as json
print(aas_xmlization.to_str(example))# as xml


aas_rdfization.to_turtle() # as rdf turtle or json-ld is missing!

@wiresio
Copy link

wiresio commented Jan 8, 2024

I think you are one step ahead. What is missing is the step before it. converting objects to rdf.

That's right. I thought it was your starting point.

@mristin
Copy link
Contributor

mristin commented Jun 7, 2024

I'm closing the issue due to inactivity -- I don't think we are going to work on this feature in the near or mid-term. The specification for RDF+SHACL is in progress of substantial improvement (e.g., see: admin-shell-io/aas-specs#421), so once the changes are fleshed out, we can re-consider and re-open this issue.

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

No branches or pull requests

3 participants