Skip to content
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

Enrich JSONLD representations with additional predicate for Drupal URI #768

Closed
dannylamb opened this issue Jan 8, 2018 · 19 comments
Closed
Assignees

Comments

@dannylamb
Copy link
Contributor

From https://groups.google.com/forum/#!topic/islandora-dev/WqgmbkLlUUY:

Allow the user to configure a predicate for the Drupal URI in serialized JSONLD. Firing an alter in the jsonld module and implementing the alter in core islandora would be a clean way to achieve this. You'll need to add the predicate to islandora's existing configuration form to expose it to the end user so it can be looked up in islandora's alter implementation.

@whikloj whikloj self-assigned this Jan 16, 2018
@whikloj
Copy link
Member

whikloj commented Feb 13, 2018

I was going to try this as an API-X service (to help understand that framework), does that sound okay?

That means it would conceivably only occur if you requested the modified version of the document, though I guess if that worked off the Gemini DB then you could request the translation before you PUT the json-ld into Fedora.

🤦‍♂️ wrong ticket

@whikloj
Copy link
Member

whikloj commented Feb 13, 2018

Ok, now I'm on the right ticket. I have two directions on this one.

  1. One would require two hooks. One to alter the rdf_mapping and one to alter the returned fields from the entity.
  2. One would only require one hook, but would be more static and just cram the predicate and value below here

@whikloj
Copy link
Member

whikloj commented Feb 13, 2018

The one hook method is...iffy, I think I am in the wrong spot. Probably need a service between the normalizer and encoder to do this. But I was able to make Islandora inject the URL with the chosen predicate of owl:sameAs (which I configured).

{
  "@graph": [
    {
      "@id": "http://localhost:8000/node/1?_format=jsonld",
      "@type": [
        "http://pcdm.org/models#Object",
        "http://schema.org/ImageObject"
      ],
      "http://purl.org/dc/terms/title": [
        {
          "@value": "This is an image",
          "@type": "http://www.w3.org/2001/XMLSchema#string"
        }
      ],
      "http://schema.org/author": [
        {
          "@id": "http://localhost:8000/user/1?_format=jsonld"
        }
      ],
      "http://schema.org/dateCreated": [
        {
          "@value": "2018-02-12T21:09:57+00:00",
          "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
        }
      ],
      "http://schema.org/dateModified": [
        {
          "@value": "2018-02-12T21:10:30+00:00",
          "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
        }
      ],
      "http://www.w3.org/2002/07/owl#sameAs": [
        {
          "@value": "http://localhost:8000/node/1?_format=jsonld"
        }
      ]
    },
    {
      "@id": "http://localhost:8000/user/1?_format=jsonld",
      "@type": [
        "http://schema.org/Person"
      ]
    }
  ]
}

@whikloj
Copy link
Member

whikloj commented Feb 13, 2018

Here is my work so far on the one hook solution. It gets called for each item, so I need to move where the hook is invoked in jsonld to after the normalizer is totally finished.

But this gives an idea of my idea?
json-ld diff
Islandora diff

@dannylamb
Copy link
Contributor Author

So the two hook method would be adding fake fields after adding those to the fake mapping? Maybe the one hook approach isn't so iffy. We'll have to do something similar to add rdf:types if we want to break away from the one bundle per mapping constraint.

But yeah, I'm pickin' up what you're puttin' down. 😃

@DiegoPino
Copy link
Contributor

Question folks: if you are already invested in Context module (@mjordan ping ping) or Rules, would it not an option to deal with those extra RDFs properties/types via any of those module by implementing a context aware/rule based implementation here and maybe even at display level? That would allow for much greater flexibility for admin users with no code... Just an idea.

@dannylamb
Copy link
Contributor Author

@DiegoPino 👍 This would definitely play nicely with Context.

@whikloj
Copy link
Member

whikloj commented Feb 14, 2018

So I have no idea how to do this in Context, can you give me some guidance or any documentation if there is.

@DiegoPino
Copy link
Contributor

@whikloj can do some research this weekend but i guess @mjordan would be a very good/better-than-me primary source for this. What i know right now is that at least a piece of Context one is built into Drupal 8 in the way of the plugins and reactions can be configured via the UI.

https://www.drupal.org/docs/8/api/plugin-api/plugin-contexts and https://www.drupal.org/project/context (says the same)

But I don't know enough to be useful 😢

@mjordan
Copy link
Contributor

mjordan commented Feb 14, 2018

Alas, my hands-on experience with Context has not expanded much past 7.x.... but IIRC @dannylamb just opened a PR (which I cannot now find) that included a full Context reaction, which would be a good example to start with. @dannylamb .... can haz link?

@whikloj
Copy link
Member

whikloj commented Feb 15, 2018

So there is no documentation for Context...that is disappointing. @dannylamb was there a good example you turned to when you started with this stuff?

@whikloj
Copy link
Member

whikloj commented Feb 15, 2018

Yeah if anyone has a suggestion. I'm not clear if the idea here is now that we are adding a context to the entity or to the normalized array? If its the entity then I guess we also have to make a context to the rdf_mapping? I'm looking at the original Using Context instead of Rules PR, but there is sooooo much in that one I'm having trouble understanding what does what.

@mjordan
Copy link
Contributor

mjordan commented Feb 15, 2018

@whikloj if you look in the Context module's src/Plugin directory, there are several plugins that might get you going. Talking from the perspective of someone who's written plugins for 7.x, all the action happens in the ->execute() method. Your UI configuration happens in the various form methods. The hard part is knowing where in your module code (in this case, the Islandora module) you invoke the plugin. Looking at the D8 context.module file and the .yml files might be useful.

The example that I was thinking of is at https://github.com/Islandora-CLAW/islandora/pull/75/files, but if you look at the other PRs listed in https://github.com/Islandora-CLAW/islandora/pulls?utf8=%E2%9C%93&q=is%3Apr+context+is%3Aclosed+context you might find more helpful examples.

@dannylamb
Copy link
Contributor Author

dannylamb commented Feb 15, 2018

I'll try my best to distill this. You can do this all with a single context reaction. The reaction encompasses both the 'execute' function and a configuration form.

There's some extra structure there, like I'm pointing you to an abstract class that won't be neccessary in your case. You can just make the thing in src/Plugin/ContextReaction and you should be ok. Be sure to implement the summary function so it'll show up in the UI, and set the annotations correctly (they're pretty simple for D8 annotations).

@dannylamb
Copy link
Contributor Author

@mjordan @whikloj Oh, and the PR you're looking for was with a Condition, which is mostly similar, except it has a well-defined evaluate() function instead of an ad hoc "execute". You need to add an entry into the module's schema file for the condition plugin.

https://github.com/Islandora-CLAW/islandora/pull/75/files

@dannylamb
Copy link
Contributor Author

@whikloj Me again... I learned by looking through the Context module's source, so here's a good non-CLAW example of using a context reaction like a hook. Here's the reaction, and check its execute, it just returns its own config: https://cgit.drupalcode.org/context/tree/src/Plugin/ContextReaction/Menu.php?h=8.x-1.x

Then at the call site, that config is used to mangle a menu link: https://cgit.drupalcode.org/context/tree/src/ContextMenuActiveTrail.php?h=8.x-1.x

@mjordan
Copy link
Contributor

mjordan commented Feb 15, 2018

Thanks for the clarification @dannylamb.

@whikloj
Copy link
Member

whikloj commented Feb 15, 2018

Thanks for all that @dannylamb, this is probably going to be a s&*t show of a PR but I'll give it a try.

@dannylamb
Copy link
Contributor Author

Resolved with 21124f3

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

No branches or pull requests

4 participants