3

JSON-LD 圧縮と、それを使用して値の IRI を圧縮できるかどうかについて、少し混乱しています。

次の JSON-LD オブジェクトがあります

{
    "@context": {
        "@base": "file:///", 
        "x": "https://example.org/pub/x#", 
        "x-attribute": "https://example.org/pub/x-attribute#",
        "x:purpose": { 
            "@type": "@id"
        }
    },
    "https://example.org/pub/x#purpose": "https://example.org/pub/x-attribute#on"
}

および次の新しいコンテキスト

{
    "x": "https://example.org/pub/x#",
    "x-attribute": "https://example.org/pub/x-attribute#"
}

私は期待している...そして欲しい...を手に入れたい

{
  "@context": {
    "x": "https://example.org/pub/x#",
    "x-attribute": "https://example.org/pub/x-attribute#"
  },
  "x:purpose": "x-attribute:on"
}

しかし、私が最終的に得るのは

{
  "@context": {
    "x": "https://example.org/pub/x#",
    "x-attribute": "https://example.org/pub/x-attribute#"
  },
  "x:purpose": "https://example.org/pub/x-attribute#on"
}

これを試してみたい場合は、これをJSON-LD Playgroundにプラグインできます。

自分がやろうとしていることをどのように達成できますか? つまり、基本的に値の位置でコンパクト IRI を使用します。

4

1 に答える 1

3

最初に簡単なメモ: 入力オブジェクトのコンテキストで定義した用語を使用していません。完全な URI を使用しているため、 @type 定義は適用されていません。代わりに、(x:purpose) という用語を使用する必要があります。

{
    "@context": {
        "@base": "file:///", 
        "x": "https://example.org/pub/x#", 
        "x-attribute": "https://example.org/pub/x-attribute#",
        "x:purpose": { 
            "@type": "@id"
        }
    },
    "x:purpose": "https://example.org/pub/x-attribute#on"
}

データで用語を使用しない場合は、次のように値が @id であることを指定する必要があります。

{
    "@context": {
        "@base": "file:///", 
        "x": "https://example.org/pub/x#", 
        "x-attribute": "https://example.org/pub/x-attribute#",
        "x:purpose": { 
            "@type": "@id"
        }
    },
    "https://example.org/pub/x#purpose": {
        "@id": "https://example.org/pub/x-attribute#on"
    }
}

ここで、値が CURIE に圧縮された場合に必要な効果を得るには、値が実際に語彙の一部であることを示す必要があります (必要に応じて「列挙型」)。これを行うには、新しいコンテキストを次のように変更します。

{
    "x": "https://example.org/pub/x#",
    "x-attribute": "https://example.org/pub/x-attribute#",
    "x:purpose": {
        "@type": "@vocab"
    }
}

それはあなたが望む結果を与えるはずです。

于 2014-01-17T15:47:01.487 に答える