Home » Eclipse Projects » Eclipse Titan » RDF-related encodings in Titan
RDF-related encodings in Titan [message #1824397] |
Tue, 14 April 2020 13:49  |
Eclipse User |
|
|
|
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 #1824447 is a reply to message #1824442] |
Wed, 15 April 2020 08:29   |
Eclipse User |
|
|
|
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 #1824506 is a reply to message #1824451] |
Thu, 16 April 2020 10:47  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Wed Jul 23 18:35:37 EDT 2025
Powered by FUDForum. Page generated in 0.05790 seconds
|