Ruby JSON-LD中使用相同谓词消除资源歧义

Ruby JSON-LD中使用相同谓词消除资源歧义,ruby,rdf,json-ld,Ruby,Rdf,Json Ld,我很难弄清楚如何消除预先使用相同谓词的资源的歧义。我是RDF新手,所以请原谅我的术语:我将尝试用示例解释我的意思 我有一个采访资源/模型,其(简化)背景如下: { "id": { "@id": "http://purl.org/dc/terms/identifier" }, "interviewers": { "@id": "http://purl.org/dc/terms/contributor", "@type": "@id", "@contain

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

我有一个
采访
资源/模型,其(简化)背景如下:

{
  "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"
  }
}
{
  "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"
  ]
}
我的
采访者
采访者
资源的上下文如下:

{
  "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"
  }
}
{
  "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"
  ]
}
然后,我创建一个如下所示的资源:

{
  "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"
  }
}
{
  "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代码)

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

当然,这是非常有意义的,因为
采访者
采访者
都与
采访
资源相关,并带有
dc:contributor
谓词(它们只根据各自的类型进行区分)

我需要让
dump
过程了解相关的资源类型,但我不知道如何将这些信息添加到面试的上下文中

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

我可以对
面试者
面试者
使用不同的谓词,但似乎我不应该这样做。有什么建议吗

注:我在上一节也问了这个问题

其他信息

我以这种方式模拟了我的
贡献者
关系(其中
采访者
贡献者
,类型为
http://id.loc.gov/vocabulary/relators/ivr
)基于鉴定DC属性的推荐方法之一。例如,可以在资源上表示网格主题,如:

<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>

D08.586.682.075.400
甲酸脱氢酶
假设我有:

<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>

D08.586.682.075.400
甲酸脱氢酶
甲酸脱氢酶

我希望能够引用
lcsh\u subjects
“属性”,其中
lcsh\u subjects
表示与资源相关且具有类型
dcterms:lcsh
的节点。然而,我意识到我可能对JSON-LD模型的想法是错误的。

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

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

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

例如,您可以考虑在其中创建和定义属性(当然可以使用您自己的可撤销的IRI):

然后,您可以将其用于对象的上下文,如下所示:

{
  "@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"
  ]
}
(另外,请在

如果您将其转换为类似于海龟(try)的内容,您将得到以下结果:

@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" .
@前缀dc:。
@前缀rdf:。
@前缀xsd:。
A.
dc:标题为“采访某某”;
;
;
dc:标识符“06bad25f-83c1-4ee5-b055-0cb87d4c06be”。
A.
dc:标识符“b0c262ce-7eb3-47f2-b212-a0e71cca0c92”。
A.
dc:标识符“bd6bb9ec-f417-4f81-af69-e3d191e3f73b”。

谢谢您的回答。我非常感谢您的输入。您可能是对的,使用不同的谓词是最好的解决方案,但我在上面添加了更多的细节。对于转义的URI,我深表歉意:转义是由我使用的JSON漂亮打印机添加的。“rdfs:subpertyof”:{“@id”:“dc:contributor”}这是在JSON-LD中定义某事物的子属性的方法吗?还有其他方法吗?子属性是在词汇表/本体上定义的,而不是在上下文上定义的。当然,JSON-LD上下文可能包括词汇表定义,但我经常看到它们是在Turtle或RDF/XML中定义的。您可以使用
rdfs:subpertyof
谓词,因此您可以通过添加您指定的关系来定义,比如“采访者”。这使其可用于推断引擎,例如SPARQL蕴涵机制。linter在验证时也会使用此信息。请确认
“@type”:“@id”
意味着在您的上下文中,属性具有字符串类型,其值应解释为IRI。
http://purl.org/dc/terms/contributor
似乎是类型(对象),而不是属性名(谓词)。因此,我认为您的上下文有缺陷。但我对JSON-LD也是新手…我猜
@type
相当于
rdf:type
谓词,
@id
至少在属性定义上相当于实际的主语,但很难找到关于这一点的任何信息…:S