代码之家  ›  专栏  ›  技术社区  ›  Anjan Kaur

如何在JSON-LD中表示备选方案集合

  •  3
  • Anjan Kaur  · 技术社区  · 9 年前

    早些时候,我使用RDF/XML通过RDF:Alt实现了这一点。请参见以下示例

    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://ns.example.com/example/">
    <rdf:Description>
        <ex:prop1>
            <rdf:Alt>
                <rdf:li>100</rdf:li>
                <rdf:li>120</rdf:li>
                <rdf:li>130</rdf:li>
            </rdf:Alt>
        </ex:prop1>
    </rdf:Description>
    </rdf:RDF>
    

    但现在我想在JSON-LD中做同样的事情。我尝试通过在线转换器将上述代码段转换为JSON-LD,结果如下

    {
      "@context": {
        "ex": "http://ns.example.com/example/",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      },
      "@graph": [
        {
          "@id": "_:g70327238021300",
          "ex:prop1": {
            "@id": "_:g70327280101680"
          }
        },
        {
          "@id": "_:g70327280101680",
          "@type": "rdf:Alt",
          "rdf:_1": "100",
          "rdf:_2": "120",
          "rdf:_3": "130"
        }
      ]
    }
    

    archaic w3c。在JSON-LD中,有序数组和无序数组分别有@list和@set。那么,在JSON-LD中有没有其他方法可以不使用“rdf:Alt”作为@type来实现这一点呢?

    2 回复  |  直到 9 年前
        1
  •  1
  •   Community Mohan Dere    6 年前

    RDF

    在RDF中,存在 RDF Containers ( RDF:Container RDF Collections ( rdf:List 打开 关闭 ,另请参见 this question .

    rdf:Container : rdf:Bag , rdf:Seq rdf:Alt

    语义的 )这类容器之间的不同之处在于 this question .

    严格来说,RDF集合和RDF容器都不是RDF数据模型的一部分,而是特定RDF词汇表的元素(尽管这个词汇表非常常见)。

    JSON-LD

    JSON-LD数据模型与RDF没有很好地对齐,请参见 this article 主要创造者之一。

    • JSON-LD忽略了 .
    • JSON-LD忽略了上述内容
    • JSON-LD保留了 无序
    • 不明确 不同的 ,

    映射

    根据RDFS 1.1:

    The same resource may appear in a container more than once

    The first member of the container, i.e. the value of the rdf:_1 property, is the default choice .

    rdf:Alt 不是唯一的,而是有序的。 因此,应该使用 @list .但是,如果 你的 @set .

    在其他情况下,请注意,在没有任何订单的情况下,维护订单不会有任何伤害。

    另请参见 ISSUE-24 用于讨论和激励。

    是的,这是不可能表达的 实用的 (即与语言语用学相关)JSON-LD数据模型中的差异。例如,无法表达 rdf:Alt

    RDFS就是这样一种词汇。使用JSON-LD作为RDF抽象语法和写入的序列化格式 "@type": "rdf:Alt" 等等,就像你之前做的那样。

    @id 在JSON-LD中。只是不要在RDF中使用空白节点,那么JSON-LD将如下所示:

    {
      "@context": {
        "ex": "http://example.com/example/",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      },
      "@graph": [
        {
          "@id": "ex:object1",
          "ex:availableOptions": {
            "@id": "ex:optionsFor1"
          }
        },
        {
          "@id": "ex:optionsFor1",
          "@type": "rdf:Alt",
          "rdf:_1": "100",
          "rdf:_2": "120",
          "rdf:_3": "130"
        }
      ]
    }
    

    schema.org .我不确定这个例子是否正确:

    {
      "@context": {"schema": "http://schema.org/",
                   "adobe" : "http://ns.adobe.com/xap/1.0/smp/"},
      "@type": "schema:ChooseAction",             
      "@id": "adobe:price",
      "schema:option": ["100", "120", "130"]
    }
    
        2
  •  1
  •   Gregg Kellogg    9 年前

    rdf:li 扩展到 rdf:_n rdf:Alt/Bag/Seq

    对于除RDF集合之外的其他收集信息的方法,RDF集合在RDF概念中具有语义支持,并且由大多数RDF序列化直接支持,请查看本体,例如 Ordered List Ontology rdf:Alt 使用语义而不是语法的语义。

    Choose Action ,这似乎与您想要做的事情相似。相关投票行动也类似。