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

Named solution sets #44

Open
dbooth-boston opened this issue Dec 7, 2018 · 11 comments
Open

Named solution sets #44

dbooth-boston opened this issue Dec 7, 2018 · 11 comments
Labels
query Extends the Query spec

Comments

@dbooth-boston
Copy link
Collaborator

"another gap in SPARQL that I have felt, and that Bryan Thompson
aptly suggested a few years ago, is that SPARQL does not provide any
mechanism for naming or saving solution sets, even though they are a
fundamental concept in SPARQL. On a number of occasions I have wished
that I could save an intermediate result set and then refer to it later,
in producing final results."
https://lists.w3.org/Archives/Public/semantic-web/2018Nov/0300.html

@dbooth-boston dbooth-boston changed the title Named solution sets in SPARQL SPARQL: Named solution sets Dec 12, 2018
@VladimirAlexiev
Copy link
Contributor

BlazeGraph has WITH/INCLUDE. Eg see this puppy from current work (querying Wikidata)

prefix ps:   <http://www.wikidata.org/prop/statement/>
prefix pq:   <http://www.wikidata.org/prop/qualifier/>
prefix wd:   <http://www.wikidata.org/entity/>
prefix wdt:  <http://www.wikidata.org/prop/direct/>
prefix bd:   <http://www.bigdata.com/rdf#>
prefix wikibase: <http://wikiba.se/ontology#>

select ?orgId ?GRID ?orgLabel ?officialName ?orgDescription ?countryLabel ?locationLabel ?year ?officialWebsite ?orgURL ?identifierWD ?identifierGRID ?sourceURL ?linkWD ?linkGRID
with {select distinct ?award {
  ?award wdt:P31/wdt:P279* wd:Q11448906. # science award
  ?award wdt:P444 []. # review score
}} as %AWARD
with {select distinct ?person {
  include %AWARD
  ?person wdt:P166 ?award.
}} as %PERSON
with {select distinct ?org {
  include %PERSON
  ?person
    wdt:P108      | # employer
    wdt:P436      | # member of (learned society)
    wdt:P69       | # educated at
    p:P512/pq:P69 | # academic degree / educated at
    p:P166/pq:P1416 # won award / affiliation. This may not be a notable award, but I can't write the correct union with include %AWARD
  ?org.
  filter not exists {?org wdt:P31/wdt:P279* wd:Q170584} # not a project
}} as %ORG {
  include %ORG
  optional {?org wdt:P1448 ?officialName}
  optional {?org wdt:P17 ?country}
  optional {?org wdt:P131 ?location} # located in administrative territorial entity
  optional {?org wdt:P580|wdt:P571 ?date bind(year(?date) as ?year)} # inception|start date
  optional {?org wdt:P856 ?officialWebsite}
  optional {?org wdt:P2427 ?GRID}
  bind(strafter(str(?org),str(wd:)) as ?orgId)
  bind(uri(concat("organization/Wikidata/",          ?orgId)) as ?orgURL)
  bind(uri(concat("source/Wikidata/",                ?orgId)) as ?sourceURL)
  bind(uri(concat("identifier/Wikidata/",            ?orgId)) as ?identifierWD)
  bind(uri(concat("identifier/GRID/",                ?GRID))  as ?identifierGRID)
  bind(uri(concat("https://www.wikidata.org/wiki/",  ?orgId)) as ?linkWD)
  bind(uri(concat("https://www.grid.ac/institutes/", ?GRID))  as ?linkGRID)
  service wikibase:label {bd:serviceParam wikibase:language "en,fr,it,de,nl"}
}

@dbooth-boston dbooth-boston transferred this issue from w3c/EasierRDF Apr 3, 2019
@dydra
Copy link

dydra commented Apr 4, 2019

  • is the solution set to be named or the select form which can produce it?
  • where the name is defined outside of the query within which it is referenced, this relates to Need views of RDF data #41.

@VladimirAlexiev
Copy link
Contributor

Blazegraph WITH/INCLUDE is local. WITH defines a subquery with fixed execution order. The subquery is repeated every time you run the main query, so the result set is not saved.

I think #44 and #41 are the same. We don't need 2 variants of something we don't have :-)

@dydra
Copy link

dydra commented Apr 4, 2019

the scope of the WITH/AS is not obvious.
what happens when an INCLUDE with the same name appears in more than one place in the query?

@cygri
Copy link

cygri commented Apr 4, 2019

A number of related issues:

So this is all about computing some sort of intermediate result, but varies along several dimensions:

  1. Is the intermediate result a graph or a solution sequence?
  2. Is the intermediate result usable only within the same query that defined it, or is it made available under some name/IRI for use in later queries?
  3. Is the intermediate result virtual or materialised, that is, does it change when the underlying data changes?

The only combination of these dimensions that is currently possible is “store a materialised graph for use in subsequent queries”, by using a named graph and INSERT { ... } WHERE { ... }.

@dbooth-boston
Copy link
Collaborator Author

To clarify, while I agree that this issue is related to others, this one is specifically about solution sets -- not graphs. Solution sets are a very central concept to SPARQL, but at present (in standard SPARQL) there is no way to name, save or refer to them, and this makes it hard to subdivide the work of a complex query into a series of simpler steps. I have not looked at the BlazeGraph WITH / INCLUDE feature, but it was Bryan Thompson of BlazeGraph (formerly BigData) who first suggested this idea a few years ago.

@cygri
Copy link

cygri commented Apr 4, 2019

@dbooth-boston So, questions for you:

  1. Is the intermediate result usable only within the same query that defined it, or is it made available under some name/IRI for use in later queries?
  2. Is the intermediate result virtual or materialised, that is, does it change when the underlying data changes?

@dbooth-boston
Copy link
Collaborator Author

@cygri , my understanding was that it would be materialized and only available within the same query. I assume that would be easiest to implement. However, other options are worth considering, and at this point I do not have a strong opinion either way.

@cygri
Copy link

cygri commented Apr 4, 2019

@dbooth-boston Got it, thanks. So that's indeed what BlazeGraph WITH/INCLUDE provides.

@JervenBolleman JervenBolleman added the query Extends the Query spec label Apr 4, 2019
@afs afs changed the title SPARQL: Named solution sets Named solution sets Apr 5, 2019
@afs
Copy link
Collaborator

afs commented Apr 5, 2019

Removing "SPARQL: " on transferred issue.

@bergos
Copy link

bergos commented Nov 9, 2022

I wrote a blog post about this topic. My proposal uses a slightly different syntax. You can try it on the POC Web application. See also the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
query Extends the Query spec
Projects
None yet
Development

No branches or pull requests

7 participants