LDflex / LDflex

A JavaScript DSL for querying Linked Data on the Web
https://ldflex.github.io/LDflex/
MIT License
176 stars 18 forks source link

Feature: indexing with complex paths #79

Closed jeswr closed 3 years ago

jeswr commented 3 years ago

It would be nice to index using complex SPARQL paths, for instance

const ruben = path.create({ subject: namedNode('https://ruben.verborgh.org/profile/#me') });
showPerson(ruben);

async function showPerson(person) {
  for await (const name of person['foaf:friends*/foaf:givenName'])
    console.log(`- ${name}`);
}
RubenVerborgh commented 3 years ago

Hi @jeswr, good idea!

I will comment here on the syntactical suggestion, and in #80 on the implementation.

I think that, instead of

person['foaf:friends*/foaf:givenName']

we should consider

person['foaf:friends*'].['foaf:givenName']
person['foaf:friends*'].foaf$givenName
person['foaf:friends*'].name

which seems to fit the chaining spirit of LDflex better.

And perhaps also

person.friends['*'].name
person.friends.star.name
person.friends.recursive.name

or with better words than star/recursive that I can't seem to find now 🙂

jeswr commented 3 years ago

Hi @RubenVerborgh I agree that syntax closer to the chaining spirit of LDflex should be supported, however I am not quite sure how paths such as (ex:Mother|ex:Father)* could be expressed in that manner. The best I can come up with off the top of my head is

person.star(['ex:mother', 'ex:father'])

and even then paths with nested operators such as (ex:Mother?|ex:Father)+ couldn't be expressed. Do you have any thoughts on how this could be achieved?

I also still think it would be nice for the original syntax to be supported - a current use case I have for #80 is to extract an sh:path (SHACL path) in SPARQL/SHACLC syntax and then pass the path to LDflex.

RubenVerborgh commented 3 years ago

Right. Would person['foaf:friends*'].['foaf:givenName'] currently be supported though?

Note that introducing full SPARQL paths does introduce some demands on the query engine. It will no longer work with the rdflib.js backend, for instance.

jeswr commented 3 years ago

Yep #80 should already support that as 'foaf:friends*' would be processed using the code that I added to the JSONLD-resolver and 'foaf:givenName' would be processed by the existing predicate resolver. For all intents and purposes complex paths are just treated as a predicate by the rest of LDflex in #80

RubenVerborgh commented 3 years ago

Okay. I think it makes sense to continue with #80 then.