Problem/Motivation

In order to parse a JSON object as JSON-LD, a context is required. The context provides the full URIs for the aliases used in the JSON-LD and other information.

For example:

  "@context":
  {
    "schema": { "@id": "http://schema.org/" },
    "field_address": { "@id": "schema:address" },
  },

fago made clear at DrupalCon Munich that we want to provide this context at a URI rather than embedding it. This has the advantage of providing a concise JSON response. It also will allow us to respond with JSON-LD to JSON responses if we choose (as the context can be added in an HTTP Link Header).

Proposed resolution

Create a context document for each bundle in a Drupal instance. This will map Drupal's internal field/property names to their corresponding full URIs in the site generated vocabulary. These full URIs will follow the guidelines decided in #1784198: Decide on a URI structure for site generated RDF vocabulary.

CommentFileSizeAuthor
#2 1794958-2-context.txt2.72 KBlinclark
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Component: rdf.module » base system
Issue tags: +WSCCI, +json-ld

Tagging

Anonymous’s picture

FileSize
2.72 KB

Posting a patch which depends on #1811510: Enable JSON-LD entity serialization.

This creates a JsonldContext class, which will eventually be used when adding the context route and creating the full output for the context.

webchick’s picture

Status: Active » Needs review

Marking needs review.

yurtboy’s picture

Tried to test this patch.
I went to the link in #2 to get the other path. I found patch on comment #29 and that applied fine.
Then I came back to this patch and received these errors.

error: patch failed: core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizer.php:32
error: core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizer.php: patch does not apply

I looked in the patch and noted that the 2 items do not even exists in the file
1. line 82

-    $attributes = array('@id' => $entity_wrapper->getId()) + $attributes;
+    $attributes = array('@context' => $entity_wrapper->getContext(), '@id' => $entity_wrapper->getId()) + $attributes;
     return $attributes;

2. And

public function __construct($entity) {

Which right after it is suppose to have this inserted

   * Get the @context URI for this bundle type.
+   */
+  public function getContext() {
+    $entity_type = $this->entity->entityType();
+    $bundle = $this->entity->bundle();
+    $context = new JsonldContext($entity_type, $bundle);
+
+    return $context->getUri();
+  }

Maybe this patch is no longer needed?

I will try again if I missed something?

Also prior to getting the other patch above I received these errors.

error: core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php: No such file or directory
error: core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizer.php: No such file or directory

Thanks

Anonymous’s picture

Status: Needs review » Postponed

No, you're not doing anything wrong. This issue is part of a series of issues which need more architectural review than patch testing.

Crell’s picture

Issue summary: View changes
Status: Postponed » Closed (won't fix)