【问题标题】:Disambiguating resources with same predicate in JSON-LD在 JSON-LD 中消除具有相同谓词的资源的歧义
【发布时间】:2014-01-17 19:19:13
【问题描述】:

我无法弄清楚如何预先消除使用相同谓词的资源的歧义。我是 RDF 新手,所以请原谅我的术语:我将尝试通过示例来解释我的意思。

我有一个Interview 资源/模型,其(简化)上下文如下:

{
  "id": {
    "@id": "http://purl.org/dc/terms/identifier"
  },
  "interviewers": {
    "@id": "http://purl.org/dc/terms/contributor",
    "@type": "@id",
    "@container": "@set"
  },
  "title": {
    "@id": "http://purl.org/dc/terms/title"
  },
  "interviewees": {
    "@id": "http://purl.org/dc/terms/contributor",
    "@type": "@id",
    "@container": "@set"
  }
}

我的InterviewerInterviewee 资源具有这样的上下文:

{
  "id": {
    "@id": "http://purl.org/dc/terms/identifier"
  },
  "name": {
    "@id": "info:repository/ive/name"
  }
}

然后我创建一个如下所示的资源:

{
  "id": "06bad25f-83c1-4ee5-b055-0cb87d4c06be",
  "interviewers": [
    {
      "id": "b0c262ce-7eb3-47f2-b212-a0e71cca0c92",
      "name": "Somebody",
      "@context": {
        ...
      },
      "@id": "urn:uuid:b0c262ce-7eb3-47f2-b212-a0e71cca0c92",
      "@type": [
        "http://id.loc.gov/vocabulary/relators/ivr"
      ]
    }
  ],
  "title": "Interview with So and So",
  "interviewees": [
    {
      "id": "bd6bb9ec-f417-4f81-af69-e3d191e3f73b",
      "name": "A third person",
      "gender": "male",
      "@context": {
        ...
      },
      "@id": "urn:uuid:bd6bb9ec-f417-4f81-af69-e3d191e3f73b",
      "@type": [
        "http://id.loc.gov/vocabulary/relators/ive"
      ]
    }
  ],
  "@context": {
    ...
  },
  "@id": "urn:uuid:06bad25f-83c1-4ee5-b055-0cb87d4c06be",
  "@type": [
    "info:repository/interview"
  ]
}

一切都很好,我可以将这个“对象”存储到我的存储库中(我正在使用 RDF.rb 库)。但是,当我尝试提取对象并“重新序列化”它时,就会出现问题。例如(请原谅 Ruby 代码),

query = repository.query(:subject => RDF::URI(uri))
JSON.parse(query.dump(:jsonld, :context => Interview.context))

这些行从存储库中提取相关语句,然后将它们混合到具有适当上下文的 JSON-LD“资源”中。但是,被采访者和采访者都被移到了interviewees 属性中。

当然,这是完全合理的,因为 interviewersinterviewees 都通过 interview 谓词与 interview 资源相关联(它们仅通过各自的类型进行区分)。

我需要让dump 进程知道相关的资源类型,但我不知道有什么方法可以将该信息添加到采访的上下文中。

根据当前的 JSON-LS 规范,我什至不知道这是否可能。 This issue 看起来可能是相关的,但我对 RDF/JSON-LD 的了解还不够,无法确定。

我可以对interviewersinterviewees 使用不同的谓词,但我似乎不必这样做。有什么建议吗?

注意:我也在 answers.semanticweb.com 上问过这个问题。

其他信息

我已经根据推荐的用于限定 DC 属性的方法之一以这种方式建模了我的 contributor 关系(其中 interviewercontributor 类型为 http://id.loc.gov/vocabulary/relators/ivr)。例如,可以在如下资源上表达 MESH 主题:

<rdf:Description>
  <dc:subject>
    <dcterms:MESH>
      <rdf:value>D08.586.682.075.400</rdf:value>
      <rdfs:label>Formate Dehydrogenase</rdfs:label>
    </dcterms:MESH>
  </dc:subject>
</rdf:Description>

假设我有:

<rdf:Description>
  <dc:subject>
    <dcterms:MESH>
      <rdf:value>D08.586.682.075.400</rdf:value>
      <rdfs:label>Formate Dehydrogenase</rdfs:label>
    </dcterms:MESH>
  </dc:subject>
  <dc:subject>
    <dcterms:LCSH>
      <rdf:value>Formate Dehydrogenase</rdf:value>
    </dcterms:LCSH>
  </dc:subject>
</rdf:Description>

我希望能够引用lcsh_subjects“属性”,其中lcsh_subjects 表示与dc:subject 和类型为dcterms:LCSH 的资源相关的那些节点。但是,我意识到我可能以错误的方式考虑 JSON-LD 模型。

【问题讨论】:

  • AFAIK "@type": "@id" 在您的上下文中意味着该属性具有字符串类型,其值应被解释为 IRI。 http://purl.org/dc/terms/contributor 似乎是一种类型(对象)而不是属性名称(谓词)。所以我认为你的上下文有缺陷。但我也是 JSON-LD 的新手......
  • 我猜@type 相当于rdf:type 谓词,而@id 至少在属性定义上相当于实际主语,但很难找到任何关于此的信息。 .. :S

标签: ruby rdf json-ld


【解决方案1】:

您可能对同时用于面试官和受访者的@id 感到困惑。您已经使用相同的@id 定义了它们,这意味着它们是相同的谓词。它们被定义为资源的贡献者,但没有什么可以使它们彼此区分开来。您可能会认为您所说的“interviewers”是一个谓词,它是 dc:contributor 的子属性,对于“interviewees”也是如此。选择一个已有的已经有采访者和被采访者概念的词汇可能会更好。或者,创建您自己的词汇表来定义您需要的术语,并使用它来创建上下文类型。

您还转义了对象中使用的 URI(例如,“http://purl.org/dc/terms/identifier”),这可能不会产生您想要的结果,只需使用常规 URI,例如“@ 987654321@".

(此外,您使用未定义的“info”前缀。而且,没有必要在每个级别都声明@context)。

例如,您可能会考虑创建 http://example.foo/my-vocab# 并在其中定义属性(当然,使用您自己的可取消引用的 IRI):

{
  "@context": {
    "dc": "dc:identifier",
    "rdf": "URI:http:/www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@graph": [
    {
      "@id": "http://example.foo/interviewees",
      "@type": "rdf:Property",
      "rdfs:comment": "Interviewee",
      "rdfs:subPropertyOf": {
        "@id": "dc:contributor"
      }
    },
    {
      "@id": "http://example.foo/interviewers",
      "@type": "rdf:Property",
      "rdfs:comment": "Interviewer",
      "rdfs:subPropertyOf": {
        "@id": "dc:contributor"
      }
    }
  ]
}

然后您可以将其与对象的上下文一起使用,如下所示:

{
  "@context": {
    "id": "http://purl.org/dc/terms/identifier",
    "myvocab": "http://example.foo/myvocab#",
    "info": "http://example.foo/info#",
    "interviewers": {
      "@id": "myvocab:interviewers",
      "@type": "@id",
      "@container": "@set"
    },
    "title": "http://purl.org/dc/terms/title",
    "interviewees": {
      "@id": "myvocab:interviewees",
      "@type": "@id",
      "@container": "@set"
    }
  },
  "id": "06bad25f-83c1-4ee5-b055-0cb87d4c06be",
  "interviewers": [
    {
      "id": "b0c262ce-7eb3-47f2-b212-a0e71cca0c92",
      "name": "Somebody",
      "@id": "urn:uuid:b0c262ce-7eb3-47f2-b212-a0e71cca0c92",
      "@type": [
        "http://id.loc.gov/vocabulary/relators/ivr"
      ]
    }
  ],
  "title": "Interview with So and So",
  "interviewees": [
    {
      "id": "bd6bb9ec-f417-4f81-af69-e3d191e3f73b",
      "name": "A third person",
      "gender": "male",
      "@id": "urn:uuid:bd6bb9ec-f417-4f81-af69-e3d191e3f73b",
      "@type": [
        "http://id.loc.gov/vocabulary/relators/ive"
      ]
    }
  ],
  "@id": "urn:uuid:06bad25f-83c1-4ee5-b055-0cb87d4c06be",
  "@type": [
    "info:repository/interview"
  ]
}

(另外,请查看JSON-LD playground

如果你把它变成 Turtle 之类的东西(试试 http://rdf.greggkellogg.net/),你会得到以下结果:

@prefix dc: <http://purl.org/dc/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<urn:uuid:06bad25f-83c1-4ee5-b055-0cb87d4c06be> a <http://example.foo/info#repository/interview>;
   dc:title "Interview with So and So";
   <http://example.foo/myvocab#interviewees> <urn:uuid:bd6bb9ec-f417-4f81-af69-e3d191e3f73b>;
   <http://example.foo/myvocab#interviewers> <urn:uuid:b0c262ce-7eb3-47f2-b212-a0e71cca0c92>;
   dc:identifier "06bad25f-83c1-4ee5-b055-0cb87d4c06be" .

<urn:uuid:b0c262ce-7eb3-47f2-b212-a0e71cca0c92> a <http://id.loc.gov/vocabulary/relators/ivr>;
   dc:identifier "b0c262ce-7eb3-47f2-b212-a0e71cca0c92" .

<urn:uuid:bd6bb9ec-f417-4f81-af69-e3d191e3f73b> a <http://id.loc.gov/vocabulary/relators/ive>;
   dc:identifier "bd6bb9ec-f417-4f81-af69-e3d191e3f73b" .

【讨论】:

  • 感谢您的回答。我非常感谢您的意见。你可能是对的,使用不同的谓词是最好的解决方案,但我在上面添加了更多细节。对于转义的 URI,我深表歉意:转义只是由我使用的 JSON 漂亮打印机添加的。
  • "rdfs:subPropertyOf": { "@id": "dc:contributor" } 这是在 JSON-LD 中定义某事物的子属性的方式吗?还有其他方法吗?
  • 子属性是在词汇/本体上定义的,而不是上下文。当然,JSON-LD 上下文可能包含词汇定义,但我经常看到它们是在 Turtle 或 RDF/XML 中定义的。您使用rdfs:subPropertyOf 谓词将 subPropertyRelationship 定义到另一个属性,因此您可以通过添加您指定的关系来定义“采访者”。这使其可用于推理引擎,例如 SPARQL Entailment Regimes。 linter 在验证时也会使用此信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-20
  • 2014-08-11
  • 2012-11-22
  • 2014-06-27
  • 2011-04-11
  • 2013-04-03
相关资源
最近更新 更多