@embed: @never is ignored inside an @reverse frame

オープン 初心者向け
#378 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
90/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

lib/pyld/jsonld.py#L4663 の reverse-framing ブランチから始めてください。ここでは状態キーが embeded と綴られています。L4484-L4485 付近の @never チェックおよび L4597 と L4611 の forward 呼び出し箇所と比較してください。issue の reproducer を実行して employee ノードが埋め込まれていることを確認し、その後 1 文字の修正を適用してください。完了とは、既存の frame テストが変わらないまま、reverse frame が "employees": {"@id": "ex:p1"} を返すことです。

索引モデルが issue の本文から書いたものです。

説明

Framing a reverse property with {"@embed": "@never"} embeds the matched node in full. The same flag on a forward property is honoured.

from pyld import jsonld

ctx = {"schema": "http://schema.org/", "name": "schema:name",
       "works_for": {"@id": "schema:worksFor", "@type": "@id"},
       "employees": {"@reverse": "schema:worksFor"}}
doc = {"@context": ctx, "@graph": [
    {"@id": "ex:org1", "@type": "schema:Organization", "name": "Acme"},
    {"@id": "ex:p1", "@type": "schema:Person", "name": "Ada", "works_for": "ex:org1"}]}
back = jsonld.from_rdf(jsonld.to_rdf(doc, {"format": "application/n-quads"}),
                       {"format": "application/n-quads"})

print(jsonld.frame(back, {"@context": ctx, "@embed": "@once", "@type": "schema:Organization",
                          "@reverse": {"schema:worksFor": {"@embed": "@never"}}}))

3.3.0 returns the employee embedded:

"employees": {"@id": "ex:p1", "@type": "schema:Person", "name": "Ada", "works_for": "ex:org1"}

The reverse branch recurses with a misspelled state key, jsonld.py#L4663:

{**state, 'embeded': True},

while the @never test reads state['embedded'] (L4484-L4485). The key written is never read, so a reverse-framed node is treated as if it were at the top level, where @never does not apply. The two forward call sites, L4597 and L4611, spell it 'embedded'.

Changing that one character in an installed 3.3.0 gives "employees": {"@id": "ex:p1"}, with the other frames unchanged.

jsonld.js is correct at frame.js#L309, so this is specific to the Python port.

主要言語
Python
スター
689
フォーク
140
平均マージ
2日 16時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

digitalbazaar/pyld のほかの issue

digitalbazaar/pyld の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。