namespaces - JSON-LD 上下文中的不同值前缀

标签 namespaces json-ld

所以我有一个预定义的本体和一个现有的 JSON 服务(两次都读为“无法更改那里的现有内容”),返回类似于以下 JSON 的内容:

{
  "propA": "someResource",
  "propB": "otherResource"
}

我想通过添加(我无法更改现有属性,但可以添加新属性)上下文定义来将该输出转换为 JSON-LD。在第一步中,我添加了一个默认上下文,如下所示:

  "@context": {
    "@vocab": "https://example.org/",

    "propA": { "@type": "@vocab" },
    "propB": { "@type": "@vocab" }
  },
  "@id": "https://example.org/blub",

这会将两个资源映射到 @vocab ( playground ) 指定的命名空间。

<https://example.org/blub> <https://example.org/propA> <https://example.org/someResource> .
<https://example.org/blub> <https://example.org/propB> <https://example.org/otherResource> .

但是,两个引用的资源属于两个不同的命名空间。所以我需要的是一些上下文,映射到以下内容:

<https://example.org/blub> <https://example.org/propA> <https://foo.com/someResource> .
<https://example.org/blub> <https://example.org/propB> <https://bar.com/otherResource> .

我在某个地方发现了一个hack using @base ,但这仅作为一种解决方法,如果您需要一个额外的命名空间而不是多个命名空间。

那么,当我需要两个以上的属性时,如何为不同的属性定义单独的命名空间前缀?

最佳答案

这是一种方法:

{
  "@context": {
    "dcat": "http://www.w3.org/ns/dcat#",
    "org": "http://www.w3.org/ns/org#",
    "vcard": "http://www.w3.org/2006/vcard/ns#",
    "foaf": "https://project-open-data.cio.gov/v1.1/schema#",
    "dc": "http://purl.org/dc/terms/",
    "pod": "https://project-open-data.cio.gov/v1.1/schema#",
    "skos": "http://www.w3.org/2004/02/skos/core#",
  }
}

然后您将使用 CURIE 格式 ( https://en.wikipedia.org/wiki/CURIE ) 来指定 key:value 对,其中 keyvocab 并且是公理/语句中使用的词汇术语

关于namespaces - JSON-LD 上下文中的不同值前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52126765/

相关文章:

json-ld - 从 JSON-LD 中的前缀和数据构建 IRI

JSON-LD无法在@context中定义多个节点类型

.net - CLSCompliant(true) 拖入未使用的引用

c++ - 使用 namespace 别名优于预处理器的好处

c# - 是什么导致对象浏览器中 DLL 中的属性命名空间?

clojure:如何将命名空间作为宏参数传递?

PHP : 'use' inside of the class definition

schema.org - 为什么 schema.org JSON-LD 表示如此小?

node.js - 使用node.js从HTML解析JSON-LD微格式?

seo - 通过 JSON+LD 实现的来自 Schema.org 的 Rich Snippets 但未被爬虫抓取