Skip to content

The algorithm for processing a reverse term returns too early #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
niklasl opened this issue May 1, 2023 · 1 comment · Fixed by #566
Closed

The algorithm for processing a reverse term returns too early #565

niklasl opened this issue May 1, 2023 · 1 comment · Fixed by #566

Comments

@niklasl
Copy link
Contributor

niklasl commented May 1, 2023

In section 4.2 Create Term Definition of the Context Processing Algorithms, step 13, processing a reverse term ends with:

Set the term definition of term in active context to definition and the value associated with defined's entry term to true and return.

But with that early return, the algorithm stops processing a reverse term definition here, and thus reverse terms will not use any compaction features captured in the subsequent steps (step 19 and onward); e.g. indexed containers).

Thus this example:

{
  "@context": {
    "@base": "https://example.org/",
    "@vocab": "https://example.net/ns#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "statement": {"@reverse": "rdf:subject", "@container": "@index", "@index": "predicate"},
    "predicate": {"@id": "rdf:predicate", "@type": "@vocab"},
    "term": {"@id": "rdf:object", "@type": "@vocab"},
    "addedIn": {"@type": "@id"}
  },
  "@id": "/item/1",
  "statement": {
    "rdf:type": {"term": "A", "addedIn": "v1"}
  }
}

which should expand to:

[
  {
    "@id": "https://example.org/item/1",
    "@reverse": {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject": [
        {
          "https://example.net/ns#addedIn": [
            {
              "@id": "https://example.org/v1"
            }
          ],
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#object": [
            {
              "@id": "https://example.net/ns#A"
            }
          ],
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate": [
            {
              "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
            }
          ]
        }
      ]
    }
  }
]

instead results in:

[
  {
    "@id": "https://example.org/item/1",
    "@reverse": {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject": [
        {
          "https://example.net/ns#addedIn": [
            {
              "@id": "https://example.org/v1"
            }
          ],
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#object": [
            {
              "@id": "https://example.net/ns#A"
            }
          ],
          "@index": "rdf:type"
        }
      ]
    }
  }
]

since the term definition of statement is missing what term to use when interpreting the @index value.

The fix is simple: remove "and return" from the end of step 13, and revise step 14 to begin with "Otherwise".

This is consistent with playground and distiller behaviour, and by looking at implementation, e.g. the ruby implementation does not return early.

I have a fix for TRLD to reflect the above (applying that, example output changed accordingly to the expected behaviour).

@pchampin
Copy link
Contributor

FTR PyLD 2.0.3 also provides the expected result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants