2016-02-14 49 views
3

JSON-LD上下文可用于指定属性的范围。例如,下面的统计信息的rdf:value范围包括整数:如何在JSON-LD中为RDF值编码数据类型IRI?

{ 
    "@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" 
} 

在RDF建模中,通常使用不同的范围为rdf:value不同的用途。例如,下面的表现,一个对象收费€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 ] . 

如何描述这种以JSON-LD方面的条款?在我看来,我需要财产路径(借用SPARQL一个概念)作为键,专为当前的例子如下:

"ex:price/rdf:value": "xsd:decimal" 
"ex:temperature/rdf:value": "xsd:float" 

是否有JSON-LD来指定这个办法?

回答

1

您也可以nest @context专门/替代属性。以你为例:

{ 
    "@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" 
    } 
} 

你可以experiment with this in the JSON-LD Playground

另一种方法是使用自定义属性都映射到一个@idrdf: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" 
    } 
} 

this example on the JSON-LD playground

+0

这需要我为每个这样的属性包含嵌套的上下文。是否没有更通用的方式来表达这一点,即一次说明“p/q”:{“@type”:“xsd:float”}'而不是陈述'“q”:{“@type”: “xsd:float”}'每次出现'“q”''? –

+1

您可以使用自定义属性,[这是一个示例](http://tinyurl.com/h5z5pfx) – kba

1

您可以通过指定value object来提供typed value

例子:

{ 
    "@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" 
    } 
} 
+0

我想表达的情境数据类型IRI,所以我可以指定一次,不需要重复。 –

+2

@WouterBeek:啊。那么在'@ context'中定义不同的属性,每个属性都有相同的'@ id',但不同的'@type'? – unor

1

最简单的方法是引入单独的属性。喜欢的东西(我还设置@vocabex这里):

{ 
    "@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" 
    } 
} 
相关问题