2016-02-14 46 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" 
    } 
} 
相關問題