ttl2jsonld icon indicating copy to clipboard operation
ttl2jsonld copied to clipboard

edge prefix is making bug the ttl2jsonld

Open darreal44 opened this issue 1 year ago • 1 comments

If you have the following prefix: @prefix : https://schema.mekanoid.io/mekanoid.owl# .

:defender_machine_321ddbxxxxxxxxxxxxxx1776bbd3918b7a8 rdf:type d3f:Host ; :comment "Agent version 10.8210.17763.3650", "Risk Score None", "Status Inactive" ;

it creates keys in json-ld like "0:defender_machine__321ddbxxxxxxxxxxxxxx1776bbd3918b7a8" or "0:comment" and not ":defender_machine__321ddbxxxxxxxxxxxxxx1776bbd3918b7a8" or ":comment" like it should.

darreal44 avatar Mar 29 '23 13:03 darreal44

This behaviour is based on difference between Turtle and JSON-LD.

Below is valid Turtle with empty prefix definition.

@prefix : <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a :Person;
  :name "Manu Sporny";
  :homepage <http://manu.sporny.org/> .

It is simple if this turtle can be converted to JSON-LD below. But below is invalid JSON-LD.

{
  "@context": {
    "": "http://xmlns.com/foaf/0.1/"
  },
  "@id": "http://manu.sporny.org/about#manu",
  "@type": ":Person",
  ":name": "Manu Sporny",
  ":homepage": {
    "@id": "http://manu.sporny.org/"
  }
}

JSON-LD 1.0 spec says:

Furthermore, the use of empty terms ("") is not allowed as not all programming languages are able to handle empty JSON keys.

To solve this problem, I considered three options. Finally option3 was choosed.

option1: expand URI

{
  "@id": "http://manu.sporny.org/about#manu",
  "@type": "http://xmlns.com/foaf/0.1/Person",
  "http://xmlns.com/foaf/0.1/name": "Manu Sporny",
  "http://xmlns.com/foaf/0.1/homepage": {
    "@id": "http://manu.sporny.org/"
  }
}
  • Pros: simple
  • Cons: prefix definition in Turtle is lost

option2: use @vocab

{
  "@context": {
    "@vocab": "http://xmlns.com/foaf/0.1/"
  },
  "@id": "http://manu.sporny.org/about#manu",
  "@type": "Person",
  "name": "Manu Sporny",
  "homepage": {
    "@id": "http://manu.sporny.org/"
  }
}
  • Pros: compact, use of empty prefix can be guessed.
  • Cons: I was not sure about @vocab 's side effect.

option3: use "0" for empty prefix

{
  "@context": {
    "0": "http://xmlns.com/foaf/0.1/"
  },
  "@id": "http://manu.sporny.org/about#manu",
  "@type": "0:Person",
  "0:name": "Manu Sporny",
  "0:homepage": {
    "@id": "http://manu.sporny.org/"
  }
}
  • Pros: use of empty prefix can be guessed (Note: prefix 0 is not allowed in Turtle spec)

frogcat avatar Apr 14 '23 06:04 frogcat