如何在JSON-LD中编写循环RDF图?

时间:2018-06-24 09:23:59

标签: rdf json-ld

我的图如下:

  [Natasha]--- knows--> [Bob]
  [Bob]--- brother of--> [Alice]
  [Alice]--- play with--> [Natasha]

如何将其嵌入JSON-LD?

我当前无法使用的解决方案:

{
"@context" : {
   "Natasha" : "http://names.example.org/resource/name/Natasha",
   "Bob" : "http://names.example.org/resource/name/Bob",
   "Alice" : "http://names.example.org/resource/name/Alice",
   "knows" : "http://example.com/knows",
   "brother-of" : "http://example.com/brother-of",
   "play-with" : "http://example.com/play-with"
},
 "@id" : "Natasha", 
  "knows" : 
        {  "@id" : "Bob", 
           "brother-of" : { 
                    "@id" : "Alice",
              "play-with" : "Natasha"
        }

        }
    }

1 个答案:

答案 0 :(得分:5)

此值被解释为纯文本,而不是URI:

"play-with" : "Natasha"

要将其解释为URI,可以在上下文中定义它:

"@context": {
  "play-with": {
    "@id": "http://example.com/play-with", 
    "@type": "@id"
  }
}

或者您可以在提供值时将其明确显示(例如您已经为brother-of做过):

"play-with" : {"@id": "Natasha"}