semantic-web - 在 JSON-LD 中,是否可以扩展上下文?

标签 semantic-web linked-data json-ld

我有一个 JSON-LD 文档。

{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}

现在,此文档的部分上下文是在运行时生成的(Marty P 对象),但 foaf前缀定义是静态的,并为每个文档重复。

如果我有 10 个前缀定义,将它们放在每个文档中会感觉很浪费。所以我想做类似的事情
generated document :
{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "@extends": "http://example.com/base_context.jsonld",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}
base_context.jsonld :
  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows"
  }

这可能吗?

最佳答案

每个@context实际上可以是多个对象(或 URL),然后按照它们出现的顺序组合(这样可以改变术语的含义 - 注意这里 )。

为此,您可以使用一个数组,您可以在其中混合本地和外部上下文。这是你的例子

{
  "@context": 
  [
    "http://example.com/base_context.jsonld",
    {
      "@vocab": "http://example.com/"
    }
  ]
}

它在 section 6.7 中有描述JSON-LD 规范。

关于semantic-web - 在 JSON-LD 中,是否可以扩展上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232346/

相关文章:

html - 元素 h1 不得作为地址元素的后代出现

sparql - DBpedia 聚焦 : get related content

graph - 如何使用 Neo4j 图数据库获取语句源?

rdf - schema.org 的使用如何符合关联数据原则?

reactjs - 使用 Gatsby 或 SPA 的 SEO 结构化数据

c# - 使用属性或扩展 json.net 库寻找 Hydra/Json-ld 序列化程序

html - 处理 RDFa 中 "rel"的非语义使用

python - 使用 RDFLib 时处理缺少 <> 封闭 URL

schema.org - 如何为我的组织指定父组织?