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

Fetch an RDF list and return it as a Javascript array #53

Closed
james-martin-jd opened this issue Jan 3, 2020 · 3 comments
Closed

Fetch an RDF list and return it as a Javascript array #53

james-martin-jd opened this issue Jan 3, 2020 · 3 comments
Labels
feature A new feature to be added

Comments

@james-martin-jd
Copy link

It would be a very nice feature-add to be able to fetch an RDF collection such as:

<#_:_book_shex_BookDemo__parts_7> a ui:Classifier;
    ui:values ("Science Fiction" "Fantasy" "Romance" "Western" "Non-fiction" "Thriller" "Horror" "Douglas Adams").

... and return the values as a JS array. (This is real data I've used for demos and testing the SDK, using the Form Model syntax and vocabs).

Right now we have to run the results of values through a custom function that parses the collection recursively into an array by removing the rdf$first item, appending it to an array, then sending rdf$rest recursively into itself. The code snippet we use is here:

async function loopList(doc: any) {
  let parts: any = []

  const field = await doc.rdf$first
  if (field) {
    const nextField = await loopList(doc.rdf$rest)
    parts = [...parts, field.value, ...nextField]
  }

  return parts
}

This currently works and returns a collection as an array, but something like this seems extremely useful for managing other datatypes than just Literals.

@RubenVerborgh RubenVerborgh added the feature A new feature to be added label Jan 3, 2020
@rubensworks
Copy link
Contributor

For reference, there's an abstraction for this in rdf-object: https://github.com/rubensworks/rdf-object.js#conveniently-access-rdf-lists
We could easily port this code to LDflex: https://github.com/rubensworks/rdf-object.js/blob/master/lib/RdfListMaterializer.ts

@RubenVerborgh
Copy link
Member

Just want to note that we'll need to be careful with blank nodes (#34).

@RubenVerborgh RubenVerborgh changed the title Fetch an RDF collection and return it as a Javascript array Fetch an RDF list and return it as a Javascript array Jan 12, 2020
@jeswr
Copy link
Member

jeswr commented Dec 26, 2021

Resolved upstream in the main LDflex package LDflex/LDflex#122

@jeswr jeswr closed this as completed Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature to be added
Projects
None yet
Development

No branches or pull requests

4 participants