{"id":1790,"date":"2021-01-28T21:04:21","date_gmt":"2021-01-28T21:04:21","guid":{"rendered":"https:\/\/jan.schnasse.org\/blog\/?p=1790"},"modified":"2026-09-28T11:38:03","modified_gmt":"2026-09-28T09:38:03","slug":"datamodelling-with-a-json-to-rdf-approach","status":"publish","type":"post","link":"https:\/\/jan.schnasse.org\/blog\/2021\/01\/28\/datamodelling-with-a-json-to-rdf-approach\/","title":{"rendered":"Datamodelling with a &#8222;Json to Rdf&#8220; Approach."},"content":{"rendered":"<div class=\"s-prose js-post-body\">\n<div class=\"s-prose js-post-body\">\n<p>At the example of this stackoverflow question:<\/p>\n<p>&#8222;Supposing we have the following triple in Turtle syntax:<\/p>\n<pre class=\"lang-none s-code-block\"><code>&lt;http:\/example.com\/Paul&gt; &lt;http:\/example.com\/running&gt; &lt;http:\/example.com\/10miles&gt; .\n<\/code><\/pre>\n<p>How do I add a start and end time? For example if I want to say he started at 10 am and finished his 10miles run at 12 am. I want to use <code>xsd:dateTime<\/code>.&#8220;<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/49726990\">https:\/\/stackoverflow.com\/questions\/49726990<\/a><\/p>\n<\/div>\n<\/div>\n<hr \/>\n<p>Sometimes it can be hard to create good, well fitting models. In my own experience it is crucial to identify a well defined set of entities and relations to create a vocabulary from.\u00a0 Some people prefer to use visual strategies to develop their models. I prefer to write models in structured text.\u00a0 This has the advantage that the process of modeling directly leads into actual coding.<\/p>\n<p>Here is an example on <a href=\"https:\/\/stackoverflow.com\/a\/49741094\/1485527\">how I would tackle the question<\/a> .<\/p>\n<div class=\"s-prose js-post-body\">\n<p><strong>1. The modelling part (not much RDF involved)<\/strong><\/p>\n<pre class=\"default s-code-block hljs json\"><code>{\n    <span class=\"hljs-attr\">\"runs\"<\/span>: [\n        {\n            <span class=\"hljs-attr\">\"id\"<\/span>: <span class=\"hljs-string\">\"runs:0000001\"<\/span>,\n            <span class=\"hljs-attr\">\"distance\"<\/span>: {\n                <span class=\"hljs-attr\">\"length\"<\/span>: <span class=\"hljs-number\">10.0<\/span>,\n                <span class=\"hljs-attr\">\"unit\"<\/span>: <span class=\"hljs-string\">\"mile\"<\/span>\n            },\n            <span class=\"hljs-attr\">\"time\"<\/span>: {\n                <span class=\"hljs-attr\">\"start\"<\/span>: <span class=\"hljs-string\">\"2018-04-09T10:00:00\"<\/span>,\n                <span class=\"hljs-attr\">\"end\"<\/span>: <span class=\"hljs-string\">\"2018-04-09T12:00:00\"<\/span>\n            },\n            <span class=\"hljs-attr\">\"runner\"<\/span>: {\n                <span class=\"hljs-attr\">\"id\"<\/span>: <span class=\"hljs-string\">\"runner:0000002\"<\/span>,\n                <span class=\"hljs-attr\">\"name\"<\/span>: <span class=\"hljs-string\">\"Paul\"<\/span>\n            }\n        }\n    ]\n}\n<\/code><\/pre>\n<p>We store the json document in a file <strong>run.json<\/strong>. From here we can use the<a href=\"https:\/\/github.com\/jschnasse\/oi\"> &#8218;oi&#8216; command line tool<\/a> , to create an adhoc context.<\/p>\n<pre class=\"default s-code-block hljs json\"><code>oi run.json -t context<\/code><\/pre>\n<p>The resulting context is just a stub. But with a few additions we can easily create a context document to define id&#8217;s and types for each vocable\/entity\/relation.<\/p>\n<p><strong>2. The RDF part: define a proper context for your document.<\/strong><\/p>\n<pre class=\"default s-code-block hljs perl\"><code>   {\n    <span class=\"hljs-string\">\"@context\"<\/span>: {\n        <span class=\"hljs-string\">\"ical\"<\/span>: <span class=\"hljs-string\">\"http:\/\/www.w3.org\/2002\/12\/cal\/ical#\"<\/span>,\n        <span class=\"hljs-string\">\"xsd\"<\/span>: <span class=\"hljs-string\">\"http:\/\/www.w3.org\/2001\/XMLSchema#\"<\/span>,\n        <span class=\"hljs-string\">\"runs\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/runs\/\"<\/span>,\n            <span class=\"hljs-string\">\"@container\"<\/span>: <span class=\"hljs-string\">\"@list\"<\/span>\n        },\n        <span class=\"hljs-string\">\"distance\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/distance\"<\/span>\n        },\n        <span class=\"hljs-string\">\"length\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/length\"<\/span>,\n            <span class=\"hljs-string\">\"@type\"<\/span>: <span class=\"hljs-string\">\"xsd:double\"<\/span>\n        },\n        <span class=\"hljs-string\">\"unit\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/unit\"<\/span>\n        },\n        <span class=\"hljs-string\">\"runner\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/runner\/\"<\/span>\n        },\n        <span class=\"hljs-string\">\"name\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/name\"<\/span>\n        },\n        <span class=\"hljs-string\">\"time\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>: <span class=\"hljs-string\">\"info:stack\/49726990\/time\"<\/span>\n        },\n        <span class=\"hljs-string\">\"start\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>:<span class=\"hljs-string\">\"ical:dtstart\"<\/span>,\n            <span class=\"hljs-string\">\"@type\"<\/span>: <span class=\"hljs-string\">\"xsd:dateTime\"<\/span>\n        },\n        <span class=\"hljs-string\">\"end\"<\/span>: {\n            <span class=\"hljs-string\">\"@id\"<\/span>:<span class=\"hljs-string\">\"ical:dtend\"<\/span>,\n            <span class=\"hljs-string\">\"@type\"<\/span>: <span class=\"hljs-string\">\"xsd:dateTime\"<\/span>\n        },\n        <span class=\"hljs-string\">\"id\"<\/span>: <span class=\"hljs-string\">\"@id\"<\/span>\n    }\n}<\/code><\/pre>\n<p><strong>3. The fun part: Throw it to an RDF converter of your choice<\/strong><\/p>\n<p>This is <a href=\"https:\/\/json-ld.org\/playground\/#startTab=tab-nquads&amp;json-ld=%7B%22%40context%22%3A%7B%22ical%22%3A%22http%3A%2F%2Fwww.w3.org%2F2002%2F12%2Fcal%2Fical%23%22%2C%22xsd%22%3A%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%22%2C%22runs%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Fruns%2F%22%2C%22%40container%22%3A%22%40list%22%7D%2C%22distance%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Fdistance%22%7D%2C%22length%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Flength%22%2C%22%40type%22%3A%22xsd%3Adouble%22%7D%2C%22unit%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Funit%22%7D%2C%22runner%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Frunner%2F%22%7D%2C%22name%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Fname%22%7D%2C%22time%22%3A%7B%22%40id%22%3A%22info%3Astack%2F49726990%2Ftime%22%7D%2C%22start%22%3A%7B%22%40id%22%3A%22ical%3Adtstart%22%2C%22%40type%22%3A%22xsd%3AdateTime%22%7D%2C%22end%22%3A%7B%22%40id%22%3A%22ical%3Adtend%22%2C%22%40type%22%3A%22xsd%3AdateTime%22%7D%2C%22id%22%3A%22%40id%22%7D%2C%22runs%22%3A%5B%7B%22id%22%3A%22runs%3A0000001%22%2C%22distance%22%3A%7B%22length%22%3A10%2C%22unit%22%3A%22mile%22%7D%2C%22time%22%3A%7B%22start%22%3A%222018-04-09T10%3A00%3A00%22%2C%22end%22%3A%222018-04-09T12%3A00%3A00%22%7D%2C%22runner%22%3A%7B%22id%22%3A%22runner%3A0000002%22%2C%22name%22%3A%22Paul%22%7D%7D%5D%7D&amp;frame=%7B%7D&amp;context=%7B%22%40context%22%3A%7B%22ical%22%3A%22http%3A%2F%2Fwww.w3.org%2F2002%2F12%2Fcal%2Fical%23%22%2C%22xsd%22%3A%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%22%2C%22ical%3Adtstart%22%3A%7B%22%40type%22%3A%22xsd%3AdateTime%22%7D%7D%7D\" rel=\"nofollow noreferrer\">how it looks in JSON-Playground<\/a><\/p>\n<p>Or simply use &#8218;oi&#8216;:<\/p>\n<pre class=\"default s-code-block hljs perl\"><code> \noi run.json -f run.context -t ntriples\n<\/code><\/pre>\n<p>Prints:<\/p>\n<pre class=\"default s-code-block hljs\"><code> \n_:b0 &lt;info:stack\/49726990\/runs\/&gt; _:b3 .\n_:b3 &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#first&gt; &lt;info:stack\/49726990\/runs\/0000001&gt; .\n_:b3 &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#rest&gt; &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#nil&gt; .\n&lt;info:stack\/49726990\/runs\/0000001&gt; &lt;info:stack\/49726990\/distance&gt; _:b1 .\n&lt;info:stack\/49726990\/runs\/0000001&gt; &lt;info:stack\/49726990\/runner\/&gt; &lt;info:stack\/49726990\/runner\/0000002&gt; .\n&lt;info:stack\/49726990\/runs\/0000001&gt; &lt;info:stack\/49726990\/time&gt; _:b2 .\n_:b1 &lt;info:stack\/49726990\/length&gt; \"1.0E1\"^^&lt;http:\/\/www.w3.org\/2001\/XMLSchema#double&gt; .\n_:b1 &lt;info:stack\/49726990\/unit&gt; \"mile\" .\n&lt;info:stack\/49726990\/runner\/0000002&gt; &lt;info:stack\/49726990\/name&gt; \"Paul\" .\n_:b2 &lt;http:\/\/www.w3.org\/2002\/12\/cal\/ical#dtend&gt; \"2018-04-09T12:00:00\"^^&lt;http:\/\/www.w3.org\/2001\/XMLSchema#dateTime&gt; .\n_:b2 &lt;http:\/\/www.w3.org\/2002\/12\/cal\/ical#dtstart&gt; \"2018-04-09T10:00:00\"^^&lt;http:\/\/www.w3.org\/2001\/XMLSchema#dateTime&gt; .\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>At the example of this stackoverflow question: &#8222;Supposing we have the following triple in Turtle syntax: &lt;http:\/example.com\/Paul&gt; &lt;http:\/example.com\/running&gt; &lt;http:\/example.com\/10miles&gt; . How do I add a start and end time? For example if I want to say he started at 10 am and finished his 10miles run at 12 am. I want to use xsd:dateTime.&#8220; https:\/\/stackoverflow.com\/questions\/49726990 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9],"tags":[],"class_list":["post-1790","post","type-post","status-publish","format-standard","hentry","category-development","category-java"],"_links":{"self":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/comments?post=1790"}],"version-history":[{"count":1,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1790\/revisions"}],"predecessor-version":[{"id":4009,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1790\/revisions\/4009"}],"wp:attachment":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/media?parent=1790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/categories?post=1790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/tags?post=1790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}