如何在JSON-LD中为RDF值编码数据类型IRIs?

如何在JSON-LD中为RDF值编码数据类型IRIs?,rdf,json-ld,Rdf,Json Ld,JSON-LD上下文可用于指定属性的范围。例如,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" } ​在RDF

JSON-LD上下文可用于指定属性的范围。例如,
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"
}
​在RDF建模中,对于
RDF:value
的不同用途,通常使用不同的范围。例如,下面表示一个物体的价格为2.50欧元,温度为28.2℃(使用海龟符号):

我如何用JSON-LD上下文来描述这一点?在我看来,我需要属性路径(借用SPARQL的一个概念)作为键,对于当前示例,具体如下所示:

"ex:price/rdf:value": "xsd:decimal"
"ex:temperature/rdf:value": "xsd:float"
有没有办法在JSON-LD中指定这一点?

您可以通过指定来提供

例如:

{
“@context”:
{
“rdf”:http://www.w3.org/1999/02/22-rdf-syntax-ns#",
“xsd”:http://www.w3.org/2001/XMLSchema#"
},
“rdf:值”:
{
“@value”:“1”,
@type:“xsd:integer”
}
}
您还可以指定/覆盖属性。以你为例:

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

另一种方法是使用所有映射到一个
@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"
  }
}

请参阅。

最简单的方法是引入单独的属性。类似于(我还在这里将
@vocab
设置为
ex
):


这要求我为每个这样的属性包含嵌套上下文。有没有一种更通用的方式来表达这一点,即,对于
“p/q”:{“@type”:“xsd:float”}
,而不是每次出现
“q”{“@type”:“xsd:float”}
,我想在上下文中表示数据类型IRI,这样我就可以指定它一次,而不需要重复它。@WouterBeek:Ah。那么在
@context
中定义不同的属性如何,每个属性都具有相同的
@id
,但不同的
@type
{
  "@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"
  }
}
{
  "@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"
  }
}