Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » RDF-related encodings in Titan
RDF-related encodings in Titan [message #1824397] Tue, 14 April 2020 17:49 Go to next message
Sascha Hackel is currently offline Sascha HackelFriend
Messages: 6
Registered: October 2017
Location: Berlin
Junior Member
Hello,

I'd like to receive JSON-LD encoded messages as I work with linked data (RDF) at the moment.

Unfortunately, I couldn't find any RDF-related encodings (e.g. turtle or JSON-LD).

So my first simple try was to use the JSON encoding built into Titan, but of course, due to the invalid token "@" that is used in JSON-LD for certain keywords, the decoding failed.

Is there any straightforward way to make Titan handle Turtle or JSON-LD encodings?

Thank you in advance.

Best regards
Sascha
Re: RDF-related encodings in Titan [message #1824439 is a reply to message #1824397] Wed, 15 April 2020 10:16 Go to previous messageGo to next message
Gábor Szalai is currently offline Gábor SzalaiFriend
Messages: 46
Registered: December 2015
Member
The JSON encoder of the TITAN can deal with the special "@..." names of the JSON-LD

Either you can use the generic JSON structure defined in:
https://github.com/eclipse/titan.ProtocolModules.JSON_v07_2006

Or you can specify the exact type definitions and use the "name as " attribute the define the attribute names with @

Example:

{
"@id" : "http://manu.sporny.org/about#manu"
}

type set r1 {
charstring id
} with {
variant (id) "name as '@id'"
}

Result:
{
id := "http://manu.sporny.org/about#manu"
}
Re: RDF-related encodings in Titan [message #1824442 is a reply to message #1824439] Wed, 15 April 2020 11:31 Go to previous messageGo to next message
Sascha Hackel is currently offline Sascha HackelFriend
Messages: 6
Registered: October 2017
Location: Berlin
Junior Member
Thanks for your reply, Gábor.

Actually, that's what I tried. For that, I reused the example from here: https://www.eclipse.org/forums/index.php/t/1068704/

Here the excerpt of my custom type:
type set ConnectorSelfDescription {
  charstring connector_type optional,
  ... some more fields ...
 } with {
  variant (connector_type) "name as '@type'"
}


The result is the following:

index.php/fa/37834/0/

As you can see, the
"@type" : "ids:BaseConnector"
is the first field.

But the result is an error with the following error message:
index.php/fa/37835/0/

Is there anything else I need to consider?

[Updated on: Wed, 15 April 2020 11:33]

Report message to a moderator

Re: RDF-related encodings in Titan [message #1824447 is a reply to message #1824442] Wed, 15 April 2020 12:29 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1080
Registered: January 2015
Senior Member
Hi Sascha,

indeed, the @ character is no accepted in JSON encoding variants; we will look into the possibility to relax this restriction.

As a quick and dirty hack I can propose you the following:

-when encoding, use a token different from @, but easy to detect
- post encoding , replace the token with @

-when receiving the JSON instance, replace @ with token and then decode

(see attached code)

The downside of this-besides being a hack- is that the token will become a restricted expression, i.e. cannot be used in other parts of the JSON; this is of little practical impact, if the token is carefully chosen ("atsupercalifragistic" in my example, to be replaced with "@" back and forth).
For replacement of substrings, functions from TCCConversion_Functions library can be used.

The other option mentioned by Gabor is also valid, I have attached an example as well. JSON will be decoded into a generic TTCN-3 structure that
unfortunately is quite ugly; nonetheless this requires the least initial investment as there is no need of any further TTCN-3 types.


As an example , this JSON-LD
{
      "@context": {
        "name": "http://xmlns.com/foaf/0.1/name",
        "knows": "http://xmlns.com/foaf/0.1/knows"
      },
      "@id": "http://me.markus-lanthaler.com/",
      "name": "Markus Lanthaler",
      "knows": [
        {
          "name": "Dave Longley"
        }
      ]
    }


is decoded as below:
 JSON_object := {
        {
            key := "@context",
            val := {
                JSON_object := {
                    {
                        key := "name",
                        val := {
                            JSON_string := "http://xmlns.com/foaf/0.1/name"
                        }
                    },
                    {
                        key := "knows",
                        val := {
                            JSON_string := "http://xmlns.com/foaf/0.1/knows"
                        }
                    }
                }
            }
        },
        {
            key := "@id",
            val := {
                JSON_string := "http://me.markus-lanthaler.com/"
            }
        },
        {
            key := "name",
            val := {
                JSON_string := "Markus Lanthaler"
            }
        },
        {
            key := "knows",
            val := {
                JSON_array := {
                    {
                        JSON_object := {
                            {
                                key := "name",
                                val := {
                                    JSON_string := "Dave Longley"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


Best regards
Elemer
Re: RDF-related encodings in Titan [message #1824449 is a reply to message #1824442] Wed, 15 April 2020 12:36 Go to previous messageGo to next message
Gábor Szalai is currently offline Gábor SzalaiFriend
Messages: 46
Registered: December 2015
Member
Maybe something is wrong with the type definition. The error message indicates that JSON_PDU doesn't have any field named as "@type"

Is it possible to share the whole type definition and the value to be decoded?

Try to decode the ConnectorSelfDescription directly.
Re: RDF-related encodings in Titan [message #1824451 is a reply to message #1824449] Wed, 15 April 2020 12:53 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1080
Registered: January 2015
Senior Member
Hi Sascha, Gabor ,

please disregard my previous observation about the @ being restricted; it's not , and it should work as Gabor described, see new attachment. Hence no need to rename it.

I agree with Gabor, likely the structure does not tally.


BR

Elemer
Re: RDF-related encodings in Titan [message #1824506 is a reply to message #1824451] Thu, 16 April 2020 14:47 Go to previous message
Sascha Hackel is currently offline Sascha HackelFriend
Messages: 6
Registered: October 2017
Location: Berlin
Junior Member
Hi Elemer, hi Gábor,

thank you for your help. I managed to decode the JSON-LD.

In fact, the issue was a connection between using the variant extension wrongly and a false defined JSON structrure. But thanks to you I knew it should work with JSON-LD messages.

Best regards,
Sascha
Previous Topic:xsd2ttcn on RFC5874
Next Topic:Alternative to GTP_Tunnel_Daemon: osmo-uecups
Goto Forum:
  


Current Time: Mon Aug 10 16:48:44 GMT 2020

Powered by FUDForum. Page generated in 0.02844 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top