为了更清晰地说明JSON-LD上下文是如何将属性映射到RDF IRIs,我们可以基于提供的上下文规范,举一个完整的JSON-LD数据实例,并展示它是如何转换为RDF三元组的。
示例上下文
{
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/",
"Person": "foaf:Person",
"interest": "foaf:topic_interest",
"knows": {
"@id": "foaf:knows",
"@type": "@id"
},
"birthdate": {
"@id": "http://schema.org/birthDate",
"@type": "http://www.w3.org/2001/XMLSchema#date"
},
"dcterms": "http://purl.org/dc/terms/",
"title": "dcterms:title",
"creator": {
"@id": "dcterms:creator",
"@type": "@id"
},
"subject_of": {
"@reverse": "dcterms:subject",
"@type": "@id"
}
}
}
示例JSON-LD数据
{
"@type": "Person",
"@id": "http://example.org/people/john",
"title": "Developer",
"creator": "http://example.org/people/jane",
"subject_of": "http://example.org/articles/article1",
"knows": "http://example.org/people/joe",
"birthdate": "1980-01-01"
}
映射为RDF三元组
根据上下文规范,这个JSON-LD数据可以映射为以下RDF三元组:
-
@type
映射http://example.org/people/john rdf:type foaf:Person
-
title
映射http://example.org/people/john dcterms:title "Developer"
-
creator
映射http://example.org/people/john dcterms:creator http://example.org/people/jane
-
subject_of
映射(使用@reverse
)http://example.org/articles/article1 dcterms:subject http://example.org/people/john
-
knows
映射http://example.org/people/john foaf:knows http://example.org/people/joe
-
birthdate
映射http://example.org/people/john http://schema.org/birthDate "1980-01-01"^^http://www.w3.org/2001/XMLSchema#date
详细解释
-
@type
映射到rdf:type
并使用foaf:Person
:<http://example.org/people/john> rdf:type foaf:Person .
-
title
映射到dcterms:title
:<http://example.org/people/john> dcterms:title "Developer" .
-
creator
映射到dcterms:creator
并指定类型为@id
:<http://example.org/people/john> dcterms:creator <http://example.org/people/jane> .
-
subject_of
使用@reverse
映射到dcterms:subject
:<http://example.org/articles/article1> dcterms:subject <http://example.org/people/john> .
-
knows
映射到foaf:knows
并指定类型为@id
:<http://example.org/people/john> foaf:knows <http://example.org/people/joe> .
-
birthdate
映射到http://schema.org/birthDate
并指定类型为http://www.w3.org/2001/XMLSchema#date
:<http://example.org/people/john> <http://schema.org/birthDate> "1980-01-01"^^<http://www.w3.org/2001/XMLSchema#date> .
通过这些映射,可以将JSON-LD文档转换为RDF三元组,从而使数据在语义网环境中具有互操作性和可查询性。