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

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

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