Skip to content

Updated test results for JSON-LD-star #61

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Updated test results for JSON-LD-star #61

wants to merge 5 commits into from

Conversation

gkellogg
Copy link
Member

(other than annotation folding).

This diverges from the existing spec behavior.

Fixes #49.

…. This diverges from the existing spec behavior.
@gkellogg
Copy link
Member Author

I wanted to get this out there even though it's not finished, and there are no corresponding spec changes. I haven't done the optional @annotation re-construction in some flatten tests, and the fromRdf tests will need to invoke that solution as well.

There may be some differences in opinion on what the results should look like, particularly for reifications of multiple triples. Also, the use of explicit reifiers is limited. right now..

Copy link
Collaborator

@pchampin pchampin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only reviewed 'compact' and 'expand' so far. Generally LGTM, with a few questions though.

@gkellogg gkellogg marked this pull request as ready for review May 19, 2025 16:33
@gkellogg
Copy link
Member Author

Synopsis of algorithm updates:

Expansion Algorithm

  • If output object is a triple term (an object containing an @triple key) verify that the only keys in that object are @triple and @annotation.
  • When processing each key/value in the input:
    • If expanded property is @annotation, the expanded value is the result of expanding that value, using @annotation as the active property.
    • If expanded property is @reifies:
      • expand value as an array called rei nodes, using null as active property.
      • for each rei node in rei nodes, count the triples generated by calling the Object to RDF Algorithm on that node to verify the no more than one statement is generated.
      • The result is the expanded value as an array using @reifies as the active property.
    • If expanded property is @triple:
      • expand value to tt node, using null as active property.
      • count the statements generated by calling the Object to RDF Algorithm on that node to verify the no more than one triple is generated.
      • tt node must not include the @reverse or @triple keys.
      • The result tt node.
  • Before processing nests, if the output object includes @triple, ensure that it includes no keys other than @triple and @annotation.

Compaction Algorithm

  • If expanded property is @id, its value can no longer be an object, so text reverts to base JSON-LD 1.1
  • Adds entry for expanded property being @triple, which compacts the triple object and returns it.

Flattening Algorithm

  • If element is a value object, see if it includes an @annotation key. If so:
    • Remove the @annotation key using the value as annotation
    • construct reification as a new object with @id set to active subject, and active property set to an array containing element.
    • For each annotation:
      • set reifier to the @id key from that annotation, or a new blank node, if there is no such entry.
      • Add key entries for @id and @reifier taken from reifier and reification, respectively.
      • Create an entry in graph map using active graph, and reifier for active subject
  • If element is a triple term, see if it includes an @annotation key. If so:
  • Remove the @annotation key using the value as annotation
  • construct reification as a new object with @id set to active subject, and active property set to an array containing element.
  • For each annotation:
    • set reifier to the @id key from that annotation, or a new blank node, if there is no such entry.
    • Add key entries for @id and @reifier taken from reifier and reification, respectively.
    • Create an entry in graph map using active graph, and reifier for active subject
  • Use add value to add element as an active property to subject node. (element will only contain @triple).
  • Otherwise, element is a node object:
    • Process annotations as above, creating a @reifies entry in node, using element without the @reifies key.

Create Annotations

  • Foreach entry in node map having a @reifies key, and for each such value node:
    • set reif id do the value of @id in node.
    • set reifs to the value of @reifies in node. (It must be an array).
    • Set annotation to the a copy of node excluding @id and @reifies.
    • For each reif in reifs:
      • set target id to the value of @id in _reif`.
      • set target node to the entry in node map for target id.
      • If there is no such node, continue to the next reif.
      • set reif prop to the only key in reif other than @id (error if not found)
      • set reif values to the value of reif key in reif, which must be an array with a single entry.
      • set reif value to the only entry in reif values.
      • set target values to the value of reif prop in target node, continuing to the next reif if there are no such values.
      • It is an error if target values is not an array.
      • For each target value in target values
        • Continue to the next target value unless target value exclusive of @annotation is equal to reif value
        • Use add value to add a copy of annotation with @id set to reif id as an @annotation to target value.
        • remove reif from @reifies in node.
    • If the value of @reifies in node is empty, remove that entry from node.

Serialize RDF as JSON-LD Algorithm

  • if predicate is rdf:reifies and object is a triple term:
    • set reifiecation to the JSON-LD representation of the triple term and merge the resulting value of @triple into node using the @reifies key.

Object to RDF Algorithm

  • If item is a triple term, return the result of using this algorithm on the value of @triple
  • When processing each property and _value) in item:
    • If proeprty is @reifies, call this algorithm recursively on each such value, where each resulting triple is treated as a triple term resource.

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

Successfully merging this pull request may close these issues.

Adapting to Triple Terms and Reifiers
2 participants