[英]How to encode datatype IRIs for RDF values in JSON-LD?
A JSON-LD context can be used to specify the range of a property. JSON-LD上下文可用于指定属性的范围。 Eg, the following stats that the range of
rdf:value
consists of integers: 例如,以下统计信息表明
rdf:value
的范围由整数组成:
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"rdf:value": { "@type": "xsd:integer" }
},
"rdf:value": "1"
}
In RDF modeling it is common to use different ranges for different uses of rdf:value
. 在RDF建模中,通常对
rdf:value
不同用途使用不同的范围。 Eg, the following expresses that an object costs €2,50 and has temperature 28.2 ℃ (using Turtle notation): 例如,以下表示物体成本为2.50欧元,温度为28.2℃(使用海龟表示法):
_:1 ex:price [ rdf:value "2.50"^^xsd:decimal ; ex:unit ex:euros ] ;
ex:temperature [ rdf:value "28.2"^^xsd:float ; ex:unit ex:degreesCelsius ] .
How do I describe this in terms of a JSON-LD context? 如何根据JSON-LD上下文对此进行描述? It seems to me that I need property paths (borrowing a concept from SPARQL) as keys, specifically the following for the current example:
在我看来,我需要属性路径(从SPARQL中借用一个概念)作为键,特别是当前示例的以下内容:
"ex:price/rdf:value": "xsd:decimal"
"ex:temperature/rdf:value": "xsd:float"
Is there a way to specify this in JSON-LD? 有没有办法在JSON-LD中指定它?
You can provide a typed value by specifying a value object . 您可以通过指定值对象来提供类型化值 。
Example: 例:
{
"@context":
{
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"rdf:value":
{
"@value": "1",
"@type": "xsd:integer"
}
}
You can also nest @context
to specialize/override properties. 您还可以将
@context
嵌套到specialize / override属性。 To take your example: 举个例子:
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"rdf:value": { "@type": "xsd:integexr" }
},
"rdf:value": "1",
"ex:price": {
"@context": {
"rdf:value": { "@type": "xsd:float"}
},
"rdf:value": "35.3"
},
"ex:temperature": {
"@context": {
"rdf:value": { "@type": "xsd:decimal"}
},
"rdf:value": "2.50"
}
}
You can experiment with this in the JSON-LD Playground . 您可以在JSON-LD Playground中进行此实验 。
Another approach is to use custom properties that all map to one @id
( rdf:value
) but with different datatypes: 另一种方法是使用所有映射到一个
@id
( rdf:value
)但具有不同数据类型的自定义属性:
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"value_integer": {
"@id": "rdf:value",
"@type": "xsd:integer"
},
"value_float": {
"@id": "rdf:value",
"@type": "xsd:float"
},
"value_decimal": {
"@id": "rdf:value",
"@type": "xsd:decimal"
}
},
"value_integer": "1",
"ex:price": {
"value_decimal": "35.3"
},
"ex:temperature": {
"value_float": "2.50"
}
}
See this example on the JSON-LD playground . 在JSON-LD操场上查看此示例 。
The easiest way is to introduce separate properties. 最简单的方法是引入单独的属性。 Something like (I also set
@vocab
to ex
here): 类似的东西(我也将
@vocab
设置为ex
):
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"price_value": { "@id": "rdf:value", "@type": "xsd:decimal" },
"temperature_value": { "@id": "rdf:value", "@type": "xsd:float" },
"@vocab": "http://ex.org/",
"unit": { "@type": "@vocab" }
},
"price": {
"price_value": "2.50",
"unit": "euros"
},
"temperature": {
"temperature_value": "28.2",
"unit": "degreesCelsius"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.