How do I COUNT and FILTER? (Wikidata query)2019 Community Moderator ElectionWikidata SPARQL QueryFilter by type in WikidataWikidata query duplicatesWikidata query timeoutQuery Wikidata by GeoNames IDWikidata Query by ItemIdentifiesHow to Query Wikidata for US persidents?Querying wikidata for “property constraint”Apparently simple Wikidata SPARQL filter query is slowWikidata SPARQL: how to filter by date range?

Is there a math equivalent to the conditional ternary operator?

Are small insurances worth it

What does each site of a vanilla 9.1 installation do?

How do you say “my friend is throwing a party, do you wanna come?” in german

Can we carry rice to Japan?

Is the NES controller port identical to the port on a Wii remote?

What is the difference between a forward slip and a side slip?

Canadian citizen, on US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

Should we avoid writing fiction about historical events without extensive research?

Should I use HTTPS on a domain that will only be used for redirection?

Did Amazon pay $0 in taxes last year?

Create chunks from an array

Draw bounding region by list of points

Split a number into equal parts given the number of parts

Is every open circuit a capacitor?

How to disable or uninstall iTunes under High Sierra without disabling SIP

Sometimes a banana is just a banana

What are SHA-rounds?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

Is divide-by-zero a security vulnerability?

How can neutral atoms have exactly zero electric field when there is a difference in the positions of the charges?

Has Wakanda ever accepted refugees?

How can I be pwned if I'm not registered on the compromised site?

Four buttons on a table



How do I COUNT and FILTER? (Wikidata query)



2019 Community Moderator ElectionWikidata SPARQL QueryFilter by type in WikidataWikidata query duplicatesWikidata query timeoutQuery Wikidata by GeoNames IDWikidata Query by ItemIdentifiesHow to Query Wikidata for US persidents?Querying wikidata for “property constraint”Apparently simple Wikidata SPARQL filter query is slowWikidata SPARQL: how to filter by date range?










0















On Wikidata,
I am trying to filter events of certain time periods, but I get errors, or count of 0, or I get the same count no matter how I change the time period.
What am I doing wrong?



SELECT (count(distinct ?event) as ?cnt) 
WHERE

?event wdt:P31/wdt:P279* wd:Q171558.

OPTIONAL
?event rdfs:label ?eventLabel.

FILTER ( ?date >= "2000-01-01"^^xsd:date && ?date <= "2018-12-31"^^xsd:date )
.




I also see an example from the query page, but how do I count? What should I do to the first line of the query to convert it into Count without causing an error? :



SELECT ?event ?eventLabel ?date 
WHERE

?event wdt:P31/wdt:P279* wd:Q1190554.

OPTIONAL ?event wdt:P585 ?date.
OPTIONAL ?event wdt:P580 ?date.

FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
BIND(NOW() - ?date AS ?distance).

FILTER(0 <= ?distance && ?distance < 31).

OPTIONAL
?event rdfs:label ?eventLabel.
FILTER(LANG(?eventLabel) = "en").











share|improve this question









New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

    – AKSW
    8 hours ago











  • If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

    – AKSW
    8 hours ago












  • Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

    – belle
    8 hours ago












  • In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

    – belle
    8 hours ago












  • So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

    – AKSW
    7 hours ago















0















On Wikidata,
I am trying to filter events of certain time periods, but I get errors, or count of 0, or I get the same count no matter how I change the time period.
What am I doing wrong?



SELECT (count(distinct ?event) as ?cnt) 
WHERE

?event wdt:P31/wdt:P279* wd:Q171558.

OPTIONAL
?event rdfs:label ?eventLabel.

FILTER ( ?date >= "2000-01-01"^^xsd:date && ?date <= "2018-12-31"^^xsd:date )
.




I also see an example from the query page, but how do I count? What should I do to the first line of the query to convert it into Count without causing an error? :



SELECT ?event ?eventLabel ?date 
WHERE

?event wdt:P31/wdt:P279* wd:Q1190554.

OPTIONAL ?event wdt:P585 ?date.
OPTIONAL ?event wdt:P580 ?date.

FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
BIND(NOW() - ?date AS ?distance).

FILTER(0 <= ?distance && ?distance < 31).

OPTIONAL
?event rdfs:label ?eventLabel.
FILTER(LANG(?eventLabel) = "en").











share|improve this question









New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

    – AKSW
    8 hours ago











  • If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

    – AKSW
    8 hours ago












  • Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

    – belle
    8 hours ago












  • In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

    – belle
    8 hours ago












  • So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

    – AKSW
    7 hours ago













0












0








0








On Wikidata,
I am trying to filter events of certain time periods, but I get errors, or count of 0, or I get the same count no matter how I change the time period.
What am I doing wrong?



SELECT (count(distinct ?event) as ?cnt) 
WHERE

?event wdt:P31/wdt:P279* wd:Q171558.

OPTIONAL
?event rdfs:label ?eventLabel.

FILTER ( ?date >= "2000-01-01"^^xsd:date && ?date <= "2018-12-31"^^xsd:date )
.




I also see an example from the query page, but how do I count? What should I do to the first line of the query to convert it into Count without causing an error? :



SELECT ?event ?eventLabel ?date 
WHERE

?event wdt:P31/wdt:P279* wd:Q1190554.

OPTIONAL ?event wdt:P585 ?date.
OPTIONAL ?event wdt:P580 ?date.

FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
BIND(NOW() - ?date AS ?distance).

FILTER(0 <= ?distance && ?distance < 31).

OPTIONAL
?event rdfs:label ?eventLabel.
FILTER(LANG(?eventLabel) = "en").











share|improve this question









New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












On Wikidata,
I am trying to filter events of certain time periods, but I get errors, or count of 0, or I get the same count no matter how I change the time period.
What am I doing wrong?



SELECT (count(distinct ?event) as ?cnt) 
WHERE

?event wdt:P31/wdt:P279* wd:Q171558.

OPTIONAL
?event rdfs:label ?eventLabel.

FILTER ( ?date >= "2000-01-01"^^xsd:date && ?date <= "2018-12-31"^^xsd:date )
.




I also see an example from the query page, but how do I count? What should I do to the first line of the query to convert it into Count without causing an error? :



SELECT ?event ?eventLabel ?date 
WHERE

?event wdt:P31/wdt:P279* wd:Q1190554.

OPTIONAL ?event wdt:P585 ?date.
OPTIONAL ?event wdt:P580 ?date.

FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
BIND(NOW() - ?date AS ?distance).

FILTER(0 <= ?distance && ?distance < 31).

OPTIONAL
?event rdfs:label ?eventLabel.
FILTER(LANG(?eventLabel) = "en").








sparql wikidata






share|improve this question









New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 8 hours ago









AKSW

7,2081821




7,2081821






New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 9 hours ago









bellebelle

42




42




New contributor




belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






belle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

    – AKSW
    8 hours ago











  • If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

    – AKSW
    8 hours ago












  • Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

    – belle
    8 hours ago












  • In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

    – belle
    8 hours ago












  • So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

    – AKSW
    7 hours ago












  • 1





    Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

    – AKSW
    8 hours ago











  • If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

    – AKSW
    8 hours ago












  • Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

    – belle
    8 hours ago












  • In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

    – belle
    8 hours ago












  • So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

    – AKSW
    7 hours ago







1




1





Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

– AKSW
8 hours ago





Your first query doesn't make sense given that the variable ?date in the filter isn't bound to anything outside of the FILTER ...

– AKSW
8 hours ago













If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

– AKSW
8 hours ago






If you want to count something, you have to use an aggregate function. This aggregate function is applied to groups and if no grouping is defined it will be applied to all resources. That said, anything else you use in the projection (aka SELECT ... part) has to be an aggregate as well as long as you don't use it to define the groups (via group by ...). For your second query, I do not know what you want to achieve, so it's impossible to answer. What is the purpose of the second query? Is it done by yourself? What do you expect as result when counting?

– AKSW
8 hours ago














Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

– belle
8 hours ago






Well, I want to count the number of events of certain time period, and whose label is in certain language. But I think I fixed the problems... so it's fine now. Just that sparql still confuses me. The second part is an example I found on the query page which queries events in certain language. Thank you all for the comments.

– belle
8 hours ago














In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

– belle
8 hours ago






In case anyone wonders, my solution was to replace the first line of the second query with SELECT (COUNT(DISTINCT ?event) AS ?cnt) And whoever organized my queries, thank you. I'm new to all these xD

– belle
8 hours ago














So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

– AKSW
7 hours ago





So, I assume your second query is supposed to return the number of events in the last 31 days? Does this work? I'd think it will lead to a timeout most of the time

– AKSW
7 hours ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






belle is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021259%2fhow-do-i-count-and-filter-wikidata-query%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








belle is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















belle is a new contributor. Be nice, and check out our Code of Conduct.












belle is a new contributor. Be nice, and check out our Code of Conduct.











belle is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021259%2fhow-do-i-count-and-filter-wikidata-query%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229