如何在JSON-LD中为类型化的@sets或@lists建模

时间:2016-05-18 13:56:37

标签: json-ld

使用schema.org对Person的定义我可以创建以下架构:

{
    "@context": "http://www.schema.org/",
    "@type": "Person",
    "@id": "#AndyWarhol",
    "givenName": "Andy",
    "familyName": "Warhol",
    "birthDate": "1928-08-06",
    "deathDate": "1987-02-22",
    "knows": [
        {
            "@type": "Person",
            "@id": "#JeanMichelBasquiat"
        },
        {
            "@type": "Person",
            "@id": "#FrancescoClemente"
        }
    ]
}

如果我要将@type #JeanMichelBasquiat更改为PlaceGoogle Schema Validator实际上会抱怨knows Place不是预期的价值。只有Person。 这很棒!

现在解决实际问题:

说我想发表关于所有Place #AndyWarhol生活已超过一年的陈述。所以从本质上讲,我正在寻找PersonPlace之间的一对多关系。

由于我无法在schema.org上找到它,我试图自己创建并且悲惨地失败。

所以我的问题是:

如何自行为knows这样的结构建模? 我可以做的一件事就是说hasLivedIn只是一组@id,但是再一次,解析器无法验证已写入的数据是否真正有效。

{
    "@context": {
        "givenName": "http://schema.org/givenName",
        "hasLivedIn": {
            "@id": "http://schema.org/Place",
            "@type": "@id"
        }
    },
    "@type": "Person",
    "@id": "AndyWarhol",
    "givenName": "Andy",
    "hasLivedIn": [
        "http://newyorkcity.com",
        "http://losangeles.com"
    ]
}

这没有任何意义我猜

我还尝试使用@container@set@list来实现这些结果:

{
    "@context": {
        "givenName": "schema:givenName",
        "hasLivedIn": {
            "@id": "schema:Place",
            "@container": "@set"
        },
        "knows": {
            "@id": "schema:knows",
            "@type": "@id"
        },
        "schema": "http://www.schema.org/"
    },
    "@type": "schema:Person",
    "@id": "AndyWarhol",
    "givenName": "Andy",
    "hasLivedIn": [
        {
            "@type": "schema:Place",
            "@id": "places/nyc"
        },
        {
            "@type": "schema:Place",
            "@id": "places/la"
        }
    ],
    "knows": [
        {
            "@type": "schema:Person",
            "@id": "person/JeanMichelBasquiat"
        },
        {
            "@type": "schema:Person",
            "@id": "person/FrancescoClemente"
        }
    ]
}

但是,当我在@typehasLivedIn中更改其中一个knows时,验证程序现在正在抱怨。

简而言之:

我想要一个名为hasLivedIn的新属性,它会在Place级别上获取Person个列表。理想情况下,我可以自己定义这个新属性的属性。

修改

这是我能够工作的一个:

{
    "@context": {
        "@vocab": "http://www.schema.org/",
        "hasLivedIn": "hasPos"
    },
    "@type": "Person",
    "@id": "AndyWarhol",
    "givenName": "Andy",
    "hasLivedIn": [
        {
            "@type": "Place",
            "@id": "places/nyc"
        },
        {
            "@type": "Place",
            "@id": "places/la"
        }
    ]
}

我使用hasPOS并将其别名为hasLivedIn,这可能不是正确的做事方式......

0 个答案:

没有答案
相关问题