Multiple contexts in JSON-LD

♀尐吖头ヾ 提交于 2019-12-06 11:58:48

问题


How can I access two seperate vocabs in JSON-LD, can I use 2 @contexts? e.g.

{
"@context": {
  "@vocab": "http://schema.org/",
  "first_name": "givenName",
  "last_name": "familyName
  }
"@context": {
  "@vocab": "http://our_own_schema.org/",
  "Time": "inputTime"
 }
}

回答1:


You can provide multiple @context. If they contain duplicated terms, the most recently defined term gets used. See examples 27 and 28. But if you want to mix vocabularies within the same object, this doesn’t work.

To allow mixing vocabularies within the same object, you could define all vocabularies in the @context at the top of the document. Each vocabulary can have a prefix, which allows you to use compact IRIs. One vocabulary can be the default one (without prefix).

  • With default vocabulary:

    "@context": 
    [
      "http://schema.org/",
      {"oos": "http://our_own_schema.org/"}
    ],
    

    The key name expands to http://schema.org/name,
    the key oos:name expands to http://our_own_schema.org/name.

  • Without default vocabulary:

    "@context": 
    {
      "schema": "http://schema.org/",
      "oos": "http://our_own_schema.org/"
    },
    

    The key name would be ignored,
    the key schema:name expands to http://schema.org/name,
    the key oos:name expands to http://our_own_schema.org/name.

Note: It’s always possible to use absolute IRIs as keys. You don’t have to define these in a context.



来源:https://stackoverflow.com/questions/47227586/multiple-contexts-in-json-ld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!