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

Add TermsCardinalitySets as an index #8

Conversation

pietercolpaert
Copy link

@pietercolpaert pietercolpaert commented Apr 4, 2024

This pull request introduces a new index called TermsCardinalitySets, speeding up distinct look-ups of subject, predicate, objects and/or graphs.

In the index, we maintain an overview of their cardinalities of how many times they have been used in that position. While currently to exploited, this could also be useful towards speeding up certain counts.

Full test coverage should be reached, but I lack the typescript coverage experience to understand how the last line can be covered as well. Can you help with that?

…redicates and getObjects - need to fix coverage still
@pietercolpaert pietercolpaert marked this pull request as ready for review April 4, 2024 18:46
@pietercolpaert pietercolpaert changed the title First design of TermsCardinalitySets Add TermsCardinalitySets as an index Apr 5, 2024
@rubensworks
Copy link
Owner

Thanks for the PR @pietercolpaert!

I had a quick look at the proposed API, but It's quite a bit different to what I had in mind, which might be caused by our different requirements.

While we already had quad indexes, this PR adds unary indexes. But there is also a need for binary and ternary indexes.
As such, I think the most sustainable way forward to implement this is to extend or abstract the IRdfStoreIndex interface, given their common logic.

But the current implementation with TermsCardinalitySets obviously works, and solves your use case. So one option might be to use your fork of this library until I've managed to look into implementing this index abstraction.

@pietercolpaert
Copy link
Author

Thanks! That works for me. Can we however agree already on the method names then, such as getSubjects() in order to get a distinct list of subjects?

@rubensworks
Copy link
Owner

Can we however agree already on the method names then, such as getSubjects() in order to get a distinct list of subjects?

I'm not too sure to be honest. If we follow this approach for binary and ternary access as well, then will need a huge amount of methods for handling all possible combinations of access. So we may need something more abstract. But I don't have a clean way in mind atm. Possible something using QuadTermName as params.

@pietercolpaert
Copy link
Author

How about getDistinct(term1: QuadTermName, term2?: QuadTermName, term3?: QuadTermName, term4?: QuadTermName)

@rubensworks
Copy link
Owner

How about getDistinct(term1: QuadTermName, term2?: QuadTermName, term3?: QuadTermName, term4?: QuadTermName)

I don't think that will be sufficient to capture queries such as S? or ?P on SP index.

@pietercolpaert
Copy link
Author

Right... How about:

getDistinct(terms: QuadTermName[], quad?: QuadPattern)

That way you can then bind the variables to the distincts you want?

i.e.

getDistinct(['subject'], [null, df.namedNode('rdf:type'),df.namedNode('foaf:Person')])

Would translate into:

SELECT DISTINCT ?s WHERE {
   ?s a foaf:Person .
}

@rubensworks
Copy link
Owner

Perhaps, something like that could work.
But I'm not 100% certain yet, I feel like additional requirements may pop up once I start designing the architecture for handling these different indexes into comunica 😅

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

Successfully merging this pull request may close these issues.

None yet

2 participants