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

Question: What is the best method for retrieving supported properties from memberAssertion? #260

Open
johnslaughter-ihsmarkit opened this issue Oct 13, 2021 · 1 comment

Comments

@johnslaughter-ihsmarkit

So, this might tie into my earlier question about apiDocumentation (#259). I'm currently attempting to map from memberAssertion to supported properties. How is this expected to be done in Alcaeus?

@tpluscode
Copy link
Member

If I understood correctly, you'd want to do smth like finding the supported properties of types used in member assertion?

Here's an example using Alcaeus' object model

const client = require("alcaeus@1.3.0/node").Hydra
const { rdf } = require('@tpluscode/rdf-ns-builders')

const { representation: { root: collection } } = await client.loadResource('https://always-read-the-plaque.herokuapp.com/plaques');
const apiDoc = client.apiDocumentations[0].root

// find hydra:object of member assertions for rdf:type
const types = collection.memberAssertion
  .filter(ma => ma.property.equals(rdf.type))
  .map(ma => ma.object)

// create a map of [type URI, properties]
types.map(type => {
  const typeResource = apiDoc.supportedClass.find(sc => sc.equals(type))    
  return [type.id, typeResource ? typeResource.supportedProperty : []]
})

This returns empty in the example because of subclassing. The supported class is a subclass of the type from member assertion

RunKit: https://runkit.com/embed/k03op2du1o4h


Alternatively you can use clownface. IT is a good way to traverse the graphs that way

const client = require("alcaeus@1.3.0/node").Hydra
const { rdf, hydra } = require('@tpluscode/rdf-ns-builders')

const { representation: { root: collection } } = await client.loadResource('https://always-read-the-plaque.herokuapp.com/plaques');
const apiDoc = client.apiDocumentations[0].root

let types = collection.pointer
  .out(hydra.memberAssertion)
  .has(hydra.property, rdf.type)
  .out(hydra.object)
  .terms

types.map(type => {
  return [type, apiDoc.pointer
    .node(type)
    .out(hydra.supportedProperty)
    .toArray()]
})

RunKit: https://runkit.com/embed/275daycyc1iz

Does this help? Could you explain some more, what is the usage scenario and desired outcome?

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

2 participants