繁体   English   中英

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

[英]How to encode datatype IRIs for RDF values in 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建模中,通常对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中指定它?

您可以通过指定值对象来提供类型化值

例:

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

您还可以将@context嵌套到specialize / override属性。 举个例子:

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

您可以在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"
  }
}

在JSON-LD操场上查看此示例

最简单的方法是引入单独的属性。 类似的东西(我也将@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM