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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page