DS Catalog:SPARQL Query Service/example queries: Difference between revisions

Jump to navigation Jump to search
Line 614: Line 614:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


# find manuscript records with genre terms
# find manuscript records with scribes recorded
SELECT ?record ?recordLabel ?genreString (GROUP_CONCAT(?termLabel;separator="|") as ?terms) (GROUP_CONCAT(?externalID;separator="|") as ?externalIDs)
SELECT ?record ?recordLabel ?nameString (GROUP_CONCAT(?nameLabel;separator="|") as ?scribes) (GROUP_CONCAT(?externalID;separator="|") as ?externalIDs)
WHERE {
WHERE {
# bind query variables
# bind query variables
   BIND(p:P18 AS ?genreAsRecordedStatement).
   BIND(p:P14 AS ?nameAsRecordedStatement).
   BIND(ps:P18 AS ?genreAsRecorded).
  BIND(pq:P15 AS ?hasRole).
   BIND(pq:P20 AS ?hasTerm).
   BIND(ps:P14 AS ?nameAsRecorded).
   BIND(wdt:P44 AS ?hasExternalURI).
   BIND(pq:P17 AS ?hasName).
# statement: manuscript record has statement for genre
   BIND(wdt:P42 AS ?hasWikidataQID).
   ?record ?genreAsRecordedStatement ?genreStatement .
# statement: manuscript record has statement for associated name
# statement: genre statement has genre object recorded as string value
   ?record ?nameAsRecordedStatement ?nameStatement .
   ?genreStatement ?genreAsRecorded ?genreString .
# statement: associated name has role of scribe
# statement: genre statement has qualifier for structured/authority value
  ?nameStatement ?hasRole wd:Q20.
  ?genreStatement ?hasTerm ?term .
# statement: name statement has name object recorded as string value
   ?nameStatement ?nameAsRecorded ?nameString .
# statement: name statement may have qualifier for structured/authority value
# statement: authority value is represented by URI in external controlled vocabulary
# statement: authority value is represented by URI in external controlled vocabulary
   ?term ?hasExternalURI ?externalID .
  OPTIONAL {
   ?nameStatement ?hasName ?name .
  ?name ?hasWikidataQID ?QID .
    }
 
# render QIDs as URLs
  BIND(CONCAT("https://wikidata.org/entity/",?QID) AS ?externalID)


# return English language labels
# return English language labels
Line 635: Line 643:
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
     ?record rdfs:label ?recordLabel .
     ?record rdfs:label ?recordLabel .
     ?term rdfs:label ?termLabel .
     ?name rdfs:label ?nameLabel .
   }
   }
   }
   }
GROUP BY ?record ?recordLabel ?genreString
GROUP BY ?record ?recordLabel ?nameString
ORDER BY ?recordLabel
ORDER BY ?recordLabel
LIMIT 10000
LIMIT 10000
</syntaxhighlight>
</syntaxhighlight>
Try it [https://catalog.digital-scriptorium.org/query/#%23%20prefixes%0APREFIX%20wd%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fentity%2F%3E%0APREFIX%20wds%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fentity%2Fstatement%2F%3E%0APREFIX%20wdv%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fvalue%2F%3E%0APREFIX%20wdt%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20p%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2F%3E%0APREFIX%20ps%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20pq%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%0A%23%20find%20manuscript%20records%20with%20genre%20terms%0ASELECT%20%3Frecord%20%3FrecordLabel%20%3FgenreString%20%28GROUP_CONCAT%28%3FtermLabel%3Bseparator%3D%22%7C%22%29%20as%20%3Fterms%29%20%28GROUP_CONCAT%28%3FexternalID%3Bseparator%3D%22%7C%22%29%20as%20%3FexternalIDs%29%0AWHERE%20%7B%0A%23%20bind%20query%20variables%0A%20%20BIND%28p%3AP18%20AS%20%3FgenreAsRecordedStatement%29.%0A%20%20BIND%28ps%3AP18%20AS%20%3FgenreAsRecorded%29.%0A%20%20BIND%28pq%3AP20%20AS%20%3FhasTerm%29.%0A%20%20BIND%28wdt%3AP44%20AS%20%3FhasExternalURI%29.%0A%23%20statement%3A%20manuscript%20record%20has%20statement%20for%20genre%0A%20%20%3Frecord%20%3FgenreAsRecordedStatement%20%3FgenreStatement%20.%0A%23%20statement%3A%20genre%20statement%20has%20genre%20object%20recorded%20as%20string%20value%0A%20%20%3FgenreStatement%20%3FgenreAsRecorded%20%3FgenreString%20.%0A%23%20statement%3A%20genre%20statement%20has%20qualifier%20for%20structured%2Fauthority%20value%0A%20%20%3FgenreStatement%20%3FhasTerm%20%3Fterm%20.%0A%23%20statement%3A%20authority%20value%20is%20represented%20by%20URI%20in%20external%20controlled%20vocabulary%0A%20%20%3Fterm%20%3FhasExternalURI%20%3FexternalID%20.%0A%0A%23%20return%20English%20language%20labels%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%0A%20%20%20%20%3Frecord%20rdfs%3Alabel%20%3FrecordLabel%20.%0A%20%20%20%20%3Fterm%20rdfs%3Alabel%20%3FtermLabel%20.%0A%20%20%7D%0A%20%20%7D%0AGROUP%20BY%20%3Frecord%20%3FrecordLabel%20%3FgenreString%0AORDER%20BY%20%3FrecordLabel%0ALIMIT%2010000 here].
Try it [https://catalog.digital-scriptorium.org/query/#%23%20prefixes%0APREFIX%20wd%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fentity%2F%3E%0APREFIX%20wds%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fentity%2Fstatement%2F%3E%0APREFIX%20wdv%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fvalue%2F%3E%0APREFIX%20wdt%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20p%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2F%3E%0APREFIX%20ps%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20pq%3A%20%3Chttps%3A%2F%2Fcatalog.digital-scriptorium.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%0A%23%20find%20manuscript%20records%20with%20scribes%20recorded%0ASELECT%20%3Frecord%20%3FrecordLabel%20%3FnameString%20%28GROUP_CONCAT%28%3FnameLabel%3Bseparator%3D%22%7C%22%29%20as%20%3Fscribes%29%20%28GROUP_CONCAT%28%3FexternalID%3Bseparator%3D%22%7C%22%29%20as%20%3FexternalIDs%29%0AWHERE%20%7B%0A%23%20bind%20query%20variables%0A%20%20BIND%28p%3AP14%20AS%20%3FnameAsRecordedStatement%29.%0A%20%20BIND%28pq%3AP15%20AS%20%3FhasRole%29.%0A%20%20BIND%28ps%3AP14%20AS%20%3FnameAsRecorded%29.%0A%20%20BIND%28pq%3AP17%20AS%20%3FhasName%29.%0A%20%20BIND%28wdt%3AP42%20AS%20%3FhasWikidataQID%29.%0A%23%20statement%3A%20manuscript%20record%20has%20statement%20for%20associated%20name%0A%20%20%3Frecord%20%3FnameAsRecordedStatement%20%3FnameStatement%20.%0A%23%20statement%3A%20associated%20name%20has%20role%20of%20scribe%0A%20%20%3FnameStatement%20%3FhasRole%20wd%3AQ20.%0A%23%20statement%3A%20name%20statement%20has%20name%20object%20recorded%20as%20string%20value%0A%20%20%3FnameStatement%20%3FnameAsRecorded%20%3FnameString%20.%0A%23%20statement%3A%20name%20statement%20may%20have%20qualifier%20for%20structured%2Fauthority%20value%0A%23%20statement%3A%20authority%20value%20is%20represented%20by%20URI%20in%20external%20controlled%20vocabulary%0A%20%20OPTIONAL%20%7B%0A%20%20%3FnameStatement%20%3FhasName%20%3Fname%20.%0A%20%20%3Fname%20%3FhasWikidataQID%20%3FQID%20.%0A%20%20%20%20%7D%0A%20%20%0A%23%20render%20QIDs%20as%20URLs%0A%20%20BIND%28CONCAT%28%22https%3A%2F%2Fwikidata.org%2Fentity%2F%22%2C%3FQID%29%20AS%20%3FexternalID%29%0A%0A%23%20return%20English%20language%20labels%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%0A%20%20%20%20%3Frecord%20rdfs%3Alabel%20%3FrecordLabel%20.%0A%20%20%20%20%3Fname%20rdfs%3Alabel%20%3FnameLabel%20.%0A%20%20%7D%0A%20%20%7D%0AGROUP%20BY%20%3Frecord%20%3FrecordLabel%20%3FnameString%0AORDER%20BY%20%3FrecordLabel%0ALIMIT%2010000 here].


====Subjects====
====Subjects====
Bots, Bureaucrats, emailconfirmed, Administrators
30,537

edits

Navigation menu