重用JSON-LD知识数据

时间:2016-12-05 01:24:13

标签: schema.org json-ld

我无法确定在定义后是否可以引用配对值。

例如,如果我创建一个地址对,我可以使用一种简写的方式重新使用该值吗?

"address": {
                        "@type": "PostalAddress",
                        "streetAddress": "14 Blue Street Road",
                        "addressLocality": "Nottingham",
                        "addressRegion": "Nottinghamshire
                        "postalCode": "NG73DT",
                        "addressCountry": "United Kingdom"
                    },
                    "foundingLocation": "@address",

1 个答案:

答案 0 :(得分:1)

是的,这是可能的。 JSON-LD使用属性链接节点。节点可以是值对象(例如,日期,时间,数字等)或节点对象,例如上面的PostalAddress。所有节点都具有使用 @id 属性指定的显式或实现标识符。除其他外,JSON-LD Flattening算法还有一个过程,它删除嵌入式节点定义,并用引用替换它们,根据需要创建空白节点。引用基本上只是一个只包含 @id 属性的节点。您可以通过向PostalAddress添加空白节点来重写上面的示例:

"address": {
                    "@id": "_:n1",
                    "@type": "PostalAddress",
                    "streetAddress": "14 Blue Street Road",
                    "addressLocality": "Nottingham",
                    "addressRegion": "Nottinghamshire
                    "postalCode": "NG73DT",
                    "addressCountry": "United Kingdom"
                },
                "foundingLocation": "@address",

然后您可以从 foundingLocation 中引用它,如下所示:

"address": {
                    "@id": "_:n1",
                    "@type": "PostalAddress",
                    "streetAddress": "14 Blue Street Road",
                    "addressLocality": "Nottingham",
                    "addressRegion": "Nottinghamshire
                    "postalCode": "NG73DT",
                    "addressCountry": "United Kingdom"
                },
                "foundingLocation": {"@id": "_:n1"}