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

Count distinct query #45

Open
koslambrou opened this issue Jan 11, 2021 · 0 comments
Open

Count distinct query #45

koslambrou opened this issue Jan 11, 2021 · 0 comments

Comments

@koslambrou
Copy link

The following SPARQL query allows to fetch the number of distinct subjects in the database:

SELECT (COUNT(DISTINCT ?s) as ?count) WHERE {
  ?s ?p ?o .
}

However, there's doesn't seem to be a way to translate that query in HSparql.

An equivalent way would be to translate it as a sub query such as:

SELECT (COUNT(?s) as ?count) WHERE {
  SELECT DISTINCT ?s WHERE {
    ?s ?p ?o .
  }
}

Which can be translated to HSparql as:

countSubjsQuery :: Query SelectQuery
countSubjsQuery = do
    s <- var
    p <- var
    o <- var

    subQuery_ $ do
        triple_ s p o
        distinct_
        selectVars [s]

    c <- var
    select [count r `as` c]

Possible enhancement in order to use the distinct function with the count function to produce a SPARQL query similar to the first one ?

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

1 participant