do type = @ id值必须在JSON-LD中显式输入吗?

时间:2015-12-11 15:01:49

标签: schema.org json-ld

我正在研究JSON-LD,特别是与schema.org结合使用。

schema.org/Person的一个Json-LD示例让我觉得错误:

        {
          "@context": "http://schema.org",
          "@type": "Person",
          "address": {
            "@type": "PostalAddress",
            "addressLocality": "Seattle",
            "addressRegion": "WA",
            "postalCode": "98052",
            "streetAddress": "20341 Whitworth Institute 405 N. Whitworth"
          },
          "colleague": [
            "http://www.xyz.edu/students/alicejones.html",
            "http://www.xyz.edu/students/bobsmith.html"
          ],
          "email": "mailto:jane-doe@xyz.edu",
          "image": "janedoe.jpg",
          "jobTitle": "Professor",
          "name": "Jane Doe",
          "telephone": "(425) 123-4567",
          "url": "http://www.janedoe.com"
        }

我觉得错误的是colleague被定义为type = Person(参见上面的链接),而是提供了实体引用(url / text)。

格式化的正确方法似乎是在@context中提供额外信息,如下所示:

        {
          "@context": {
                "@vocab": "http://schema.org/",
                "colleague": { "@type": "@id" }
            },
          "@type": "Person",
          "address": {
            "@type": "PostalAddress",
            "addressLocality": "Seattle",
            "addressRegion": "WA",
            "postalCode": "98052",
            "streetAddress": "20341 Whitworth Institute 405 N. Whitworth"
          },
          "colleague": [
            "http://www.xyz.edu/students/alicejones.html",
            "http://www.xyz.edu/students/bobsmith.html"
          ],
          "email": "mailto:jane-doe@xyz.edu",
          "image": "janedoe.jpg",
          "jobTitle": "Professor",
          "name": "Jane Doe",
          "telephone": "(425) 123-4567",
          "url": "http://www.janedoe.com"
        }

schema.org(代码示例1)上的示例是否确实不正确/不完整,代码示例2是否正确?

或者一般来说:当引用而不是嵌入实体时,是否需要将其显式化(使用@type: @id),或者,在规范中是否存在一些隐含的概念,即当值是URL时它被认为是是@id的参考?

1 个答案:

答案 0 :(得分:0)

你是对的,这个例子不是100%正确。缺少对@id的类型强制。我提交了一个错误来解决这个问题:https://github.com/schemaorg/schemaorg/issues/929