Skip to content

Commit

Permalink
queries: add comments
Browse files Browse the repository at this point in the history
outside of the built query to avoid sending unnecessary long queries

re-commit of befb87f post-decaffeinate
  • Loading branch information
maxlath committed Aug 30, 2020
1 parent 2d66c95 commit 0054009
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions server/data/wikidata/queries/author_works.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module.exports = {
parameters: [ 'qid' ],
query: params => {
const { qid: authorQid } = params

// P50 author
// P58 screenwriter
// P110 illustrator
// P6338 colorist

// Filter-out instances of edition (Q3331189)

return `SELECT ?work ?type ?date ?serie WHERE {
?work wdt:P50|wdt:P58|wdt:P110|wdt:P6338 wd:${authorQid} .
?work wdt:P31 ?type .
Expand Down
12 changes: 11 additions & 1 deletion server/data/wikidata/queries/editions_reverse_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ module.exports = {
parameters: [ 'pid', 'qid' ],
query: params => {
const { pid, qid } = params
// Filter-out entities tagged as both work and edition (Q3331189)

// Work types:
// Q571 book
// Q47461344 written work
// Q7725634 literary work
// Q2831984 comic book album
// Q1004 comic
// Q1760610 comic book
// Q8274 manga

return `SELECT DISTINCT ?item WHERE {
?item wdt:${pid} wd:${qid} .
?item wdt:P31 wd:Q3331189 .
# Filter-out entities tagged as both work and edition
FILTER NOT EXISTS {
VALUES (?work_type) { (wd:Q571) (wd:Q47461344) (wd:Q7725634) (wd:Q2831984) (wd:Q1004) (wd:Q1760610) (wd:Q8274) } .
?item wdt:P31 ?work_type
Expand Down
13 changes: 11 additions & 2 deletions server/data/wikidata/queries/humans_reverse_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ module.exports = {
parameters: [ 'pid', 'qid' ],
query: params => {
const { pid, qid } = params
// Keep only humans that are known for at least one work

// Work types:
// Q571 book
// Q47461344 written work
// Q7725634 literary work
// Q2831984 comic book album
// Q1004 comic
// Q1760610 comic book
// Q8274 manga

return `SELECT DISTINCT ?item WHERE {
?item wdt:${pid} wd:${qid} .
?item wdt:P31 wd:Q5 .
# Keep only humans that are known for at least one work
?work wdt:P50 ?item .
VALUES (?work_type) { (wd:Q571) (wd:Q47461344) (wd:Q7725634) (wd:Q2831984) (wd:Q1004) (wd:Q1760610) (wd:Q8274) } .
?work wdt:P31 ?work_type .
Expand Down
17 changes: 13 additions & 4 deletions server/data/wikidata/queries/serie_parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ module.exports = {
parameters: [ 'qid' ],
query: params => {
const { qid: serieQid } = params
// Reject circular series/parts relations
// Reject parts that have an associated work (duck-typing editions)
// Reject parts that are instance of editions (Q3331189)
// but recover parts that are also instances of work

// Work types:
// Q571 book
// Q47461344 written work
// Q7725634 literary work
// Q2831984 comic book album
// Q1004 comic
// Q1760610 comic book
// Q8274 manga

return `SELECT ?part ?date ?ordinal (COUNT(?subpart) AS ?subparts) ?superpart WHERE {
?part p:P179|p:P361 ?serie_statement .
?serie_statement ps:P179|ps:P361 wd:${serieQid} .
# Reject circular series/parts relations
FILTER NOT EXISTS { wd:${serieQid} wdt:P179|wdt:P361 ?part }
# Reject parts that have an associated work (duck-typing editions)
FILTER NOT EXISTS { ?part wdt:P629 ?work }
# Reject parts that are instance of editions
FILTER NOT EXISTS {
?part wdt:P31 wd:Q3331189
# but recover parts that are also instances of work
FILTER NOT EXISTS {
VALUES (?work_type) { (wd:Q571) (wd:Q47461344) (wd:Q7725634) (wd:Q2831984) (wd:Q1004) (wd:Q1760610) (wd:Q8274) } .
?part wdt:P31 ?work_type .
Expand Down
10 changes: 10 additions & 0 deletions server/data/wikidata/queries/works_reverse_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ module.exports = {
parameters: [ 'pid', 'qid' ],
query: params => {
const { pid, qid } = params

// Work types:
// Q571 book
// Q47461344 written work
// Q7725634 literary work
// Q2831984 comic book album
// Q1004 comic
// Q1760610 comic book
// Q8274 manga

return `SELECT DISTINCT ?item WHERE {
?item wdt:${pid} wd:${qid} .
VALUES (?work_type) { (wd:Q571) (wd:Q47461344) (wd:Q7725634) (wd:Q2831984) (wd:Q1004) (wd:Q1760610) (wd:Q8274) } .
Expand Down

0 comments on commit 0054009

Please sign in to comment.