Conversation
Abbe98
left a comment
There was a problem hiding this comment.
Thank you so much for this work! Here are a few first notes.
fenymufyd
left a comment
There was a problem hiding this comment.
reviewed all except countries.rq
|
Thank you @fenymufyd, I have some time scheduled for Govdirectory on Friday and will try to get a in depth review done! |
Added a comment to clarify the purpose of the OPTIONAL block.
|
I'm rather happy now with this now! I want to merge #655 first and then rebase this. Not sure if I will be able to get it over the finish line before/during Wikimania but I hope so. |
|
EDIT: I refactored they query and it's now much faster. I haven't been able to get the following query through Qlever yet: # expected_result_count: 429
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT
?qid
?orgLabel
?orgDescription
?type
?typeLabel
?country
WHERE {
BIND(wd:Q55 AS ?country)
{
# agencies with country set to the Netherlands
VALUES ?type {
wd:Q3143387 # ministries (12)
wd:Q4500821 # appeals court (4)
wd:Q190752 # supreme court (2)
wd:Q2125157 # district court (11)
wd:Q134390 # provinces (12)
wd:Q702081 # water boards (21)
wd:Q2039348 # municipalities (342)
wd:Q26934845 # integral overseas territory (3)
}
?org wdt:P31 ?type .
?org wdt:P17 ?country .
} UNION {
# special case without a unique type
VALUES ?org {
wd:Q1857094 # cabinet of the King (1)
}
BIND("cabinet of the King" AS ?typeLabelCabinet)
}
UNION {
?org wdt:P31 wd:Q947233 . # high council of the state (6)
BIND("High Council of State" AS ?typeLabelCouncil)
}
UNION {
?org wdt:P31 wd:Q138643360 . # inspectorates (15)
BIND("Inspectorate" AS ?typeLabelInspectorate)
}
MINUS { ?org wdt:P576 [] . MINUS { ?item rdf:type wdno:P576 } }
MINUS { ?org wdt:P1366 [] }
MINUS { ?org wdt:P582 [] .
MINUS { ?org wdt:P582 ?ddate ;
wdt:P580 ?idate .
FILTER ( ?idate > ?ddate )
}
}
MINUS {
?org p:P31 ?inStatement .
?inStatement pq:P582 [] .
MINUS { ?org p:P31 ?p.
?p ps:P31 wd:Q2039348; pq:P580 ?start .
FILTER NOT EXISTS { ?p pq:P582 []}
}
}
MINUS { ?org p:P31 ?p.
?p ps:P31 wd:Q2039348; pq:P580 ?start .
FILTER ( ?start > NOW() )
}
BIND(REPLACE(STR(?org), "http://www.wikidata.org/entity/", "") AS ?qid)
OPTIONAL { ?org rdfs:label ?orgLabelEn FILTER(LANG(?orgLabelEn) = "en") }
OPTIONAL { ?org rdfs:label ?orgLabelNl FILTER(LANG(?orgLabelNl) = "nl") }
OPTIONAL { ?org rdfs:label ?orgLabelMul FILTER(LANG(?orgLabelMul) = "mul") }
BIND(COALESCE(?orgLabelEn, ?orgLabelNl, ?orgLabelMul, STR(?org)) AS ?orgLabel)
OPTIONAL { ?org schema:description ?orgDescriptionEn FILTER(LANG(?orgDescriptionEn) = "en") }
OPTIONAL { ?org schema:description ?orgDescriptionNl FILTER(LANG(?orgDescriptionNl) = "nl") }
OPTIONAL { ?org schema:description ?orgDescriptionMul FILTER(LANG(?orgDescriptionMul) = "mul") }
BIND(COALESCE(?orgDescriptionEn, ?orgDescriptionNl, ?orgDescriptionMul) AS ?orgDescription)
OPTIONAL { ?type rdfs:label ?typeLabelEn FILTER(LANG(?typeLabelEn) = "en") }
OPTIONAL { ?type rdfs:label ?typeLabelNl FILTER(LANG(?typeLabelNl) = "nl") }
OPTIONAL { ?type rdfs:label ?typeLabelMul FILTER(LANG(?typeLabelMul) = "mul") }
BIND(COALESCE(?typeLabelCabinet, ?typeLabelCouncil, ?typeLabelInspectorate, ?typeLabelEn, ?typeLabelNl, ?typeLabelMul, STR(?type)) AS ?typeLabel)
}
ORDER BY ?type ?typeLabel ?orgLabel |
|
@Abbe98 this will fix the query so it can run on QLever. It seems we need to bind custom union type like Q1857094 to ?type first then bind that type label to custom ?typeLabel2 so the final bind coalesce works below it I also moved the wd:Q947233 # High Council of State (6) union to normal ?type above it because no value is being uncounted, which also saves a bit more time (around 200-500ms iirc) # expected_result_count: 429
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT
?qid
?orgLabel
?orgDescription
?type
?typeLabel
?country
WHERE {
BIND(wd:Q55 AS ?country) # agencies with country set to the Netherlands
{
VALUES ?type {
wd:Q3143387 # ministries (12)
wd:Q4500821 # appeals court (4)
wd:Q190752 # supreme court (2)
wd:Q2125157 # district court (11)
wd:Q134390 # provinces (12)
wd:Q702081 # water boards (21)
wd:Q2039348 # municipalities (342)
wd:Q26934845 # integral overseas territory (3)
wd:Q947233 # High Council of State (6)
}
?org wdt:P31 ?type .
?org wdt:P17 ?country .
}
UNION {
VALUES ?org { wd:Q1857094 } # all instances of "Kabinet van de Koning" of netherlands (1)
BIND(wd:Q1857094 AS ?type) # bind custom type to ?type first
BIND("cabinet of the King" AS ?typeLabel2)
}
UNION {
?org wdt:P31 wd:Q138643360 . # all instances of "Inspectorate" of netherlands, whether from mainland country (Q55) or the transcontinental kingdom (Q29999) (15)
BIND(wd:Q138643360 AS ?type)
BIND("Inspectorate" AS ?typeLabel2)
}
MINUS { ?org wdt:P576 [] }
MINUS { ?org wdt:P1366 [] }
MINUS { ?org wdt:P582 [] .
MINUS { ?org wdt:P582 ?ddate ;
wdt:P580 ?idate .
FILTER ( ?idate > ?ddate )
}
}
MINUS {
?org p:P31 ?inStatement .
?inStatement pq:P582 [] .
MINUS { ?org p:P31 ?p.
?p ps:P31 wd:Q2039348; pq:P580 ?start .
FILTER NOT EXISTS { ?p pq:P582 []}
}
}
MINUS { ?org p:P31 ?p.
?p ps:P31 wd:Q2039348; pq:P580 ?start .
FILTER ( ?start > NOW() )
}
BIND(REPLACE(STR(?org), "http://www.wikidata.org/entity/", "") AS ?qid)
OPTIONAL { ?org rdfs:label ?orgLabelEn FILTER(LANG(?orgLabelEn) = "en") }
OPTIONAL { ?org rdfs:label ?orgLabelNl FILTER(LANG(?orgLabelNl) = "nl") }
OPTIONAL { ?org rdfs:label ?orgLabelMul FILTER(LANG(?orgLabelMul) = "mul") }
BIND(COALESCE(?orgLabelEn, ?orgLabelNl, ?orgLabelMul, STR(?org)) AS ?orgLabel)
OPTIONAL { ?org schema:description ?orgDescriptionEn FILTER(LANG(?orgDescriptionEn) = "en") }
OPTIONAL { ?org schema:description ?orgDescriptionNl FILTER(LANG(?orgDescriptionNl) = "nl") }
OPTIONAL { ?org schema:description ?orgDescriptionMul FILTER(LANG(?orgDescriptionMul) = "mul") }
BIND(COALESCE(?orgDescriptionEn, ?orgDescriptionNl, ?orgDescriptionMul) AS ?orgDescription)
OPTIONAL { ?type rdfs:label ?typeLabelEn FILTER(LANG(?typeLabelEn) = "en") }
OPTIONAL { ?type rdfs:label ?typeLabelNl FILTER(LANG(?typeLabelNl) = "nl") }
OPTIONAL { ?type rdfs:label ?typeLabelMul FILTER(LANG(?typeLabelMul) = "mul") }
BIND(COALESCE(?typeLabel2, ?typeLabelEn, ?typeLabelNl, ?typeLabelMul, STR(?type)) AS ?typeLabel)
}
ORDER BY ?type ?typeLabel ?orgLabel |
|
Could you also add these changes to ADD_A_COUNTRY.md? |
I've changed the markdown tutorials too at commit 552930f |
Description
I've ported all .rq query files to be compatible with QLever. I used LLM (Copilot) to do most of the tedious work but I've tested some samples of the queries manually on WQDS and QLever and it works on both services. I think it also made organization-optional.rq faster on QLever, about 5-8 sec per item.
Issue Reference
this should fix #498
Checklist
Please ensure the following before submitting the PR: