我无法预先确定如何消除使用相同谓词的资源的歧义.我是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"
}
}
Run Code Online (Sandbox Code Playgroud)
我Interviewer
和Interviewee
资源有这样的情境:
{
"id": {
"@id": "http://purl.org/dc/terms/identifier"
},
"name": {
"@id": "info:repository/ive/name"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建一个如下所示的资源:
{
"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"
]
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,我可以将这个"对象"存储到我的存储库(我正在使用RDF.rb库).但是,当我尝试提取对象并"重新序列化"它时,会出现问题.例如(借用Ruby代码),
query = repository.query(:subject => RDF::URI(uri))
JSON.parse(query.dump(:jsonld, :context => Interview.context))
Run Code Online (Sandbox Code Playgroud)
这些行从存储库中提取相关语句,然后将它们混合到具有适当上下文的JSON-LD"资源"中.但是,受访者和访调员都被移入了interviewees
属性中.
当然,这是非常合情合理的,因为两者interviewers
并interviewees
都涉及到interview
与资源dc:contributor
谓词(他们只是通过他们各自的类型来区分).
我需要让dump
流程知道相关的资源类型,但我不知道如何将这些信息添加到访谈的上下文中.
根据目前的JSON-LS规范,我不知道这是否可行.这个问题看起来可能是相关的,但我对RDF/JSON-LD的了解还不够.
我可以用不同的谓词interviewers
和interviewees
,但它似乎并不像我应该这样做.有什么建议?
注意:我也在answers.semanticweb.com上提出了这个问题.
附加信息
我已经基于推荐的限定DC属性的方法之一contributor
以这种方式(其中a interviewer
是contributor
一个类型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>
Run Code Online (Sandbox Code Playgroud)
假设我有:
<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>
Run Code Online (Sandbox Code Playgroud)
我希望能够引用lcsh_subjects
"属性",其中lcsh_subjects
表示dc:subject
与具有类型的AND 的资源相关的那些节点dcterms:LCSH
.但是,我意识到我可能正在以错误的方式思考JSON-LD模型.
您可能会对@id用于面试官和受访者感到困惑.您已使用相同的@id定义它们,这意味着它们是相同的谓词.它们被定义为资源的贡献者,但没有什么可以使它们彼此区分开来.您可能会认为"访问者"的含义是一个谓词,它是dc:贡献者的子属性,对于"受访者"也是如此.选择一个已经具有访调员和受访者概念的现有词汇可能会更好.或者,创建自己的词汇表,定义您需要的术语,并使用它来创建上下文类型.
您还要转义对象中使用的URI(例如,"http://purl.org/dc/terms/identifier"),这可能不会产生您想要的内容,只需使用常规URI,例如" http:// purl.org/dc/terms/identifier ".
(另外,使用"info"前缀,这是未定义的.并且,没有必要在每个级别声明@context).
例如,您可以考虑创建http://example.foo/my-vocab#并在其中定义属性(当然,使用您自己的dereferencable 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"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以将此与对象的上下文一起使用,如下所示:
{
"@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"
]
}
Run Code Online (Sandbox Code Playgroud)
(另外,请在JSON-LD操场上查看
如果你把它变成像龟一样的东西(试试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" .
Run Code Online (Sandbox Code Playgroud)