query-97fb064b9753af3324521b9bcbaa7507

rq turtle/ttl

Case variations of author name strings

Example uppercase strings: https://w.wiki/nDK

Example items: Q2381157 Q21076181 Q21339258 Q21391696 Q21393244 Q21514479 Q21609166 Q22112765 Q22222864 Q63496558 Q64008584 Q88059762

PREFIX target: http://www.wikidata.org/entity/Q21393244

SELECT DISTINCT ?string (COUNT(?work) AS ?count) WITH { # Find strings associated with the target item SELECT DISTINCT ?string_ WHERE { { target: rdfs:label ?string_. } # in label UNION { target: skos:altLabel ?string_. } # in alias UNION { ?author_statement ps:P50 target: ; pq:P1932 ?string_. # in "stated as" strings for "author" statements on work items } } } AS %RAWstrings WITH { # Calculate capitalization variants of these raw strings SELECT DISTINCT ?string WHERE { { INCLUDE %RAWstrings BIND(STR(?string_) AS ?string) # the raw strings } UNION { INCLUDE %RAWstrings BIND(UCASE(STR(?string_)) AS ?string) # uppercased versions of the raw strings } UNION { INCLUDE %RAWstrings BIND(LCASE(STR(?string_)) AS ?string) # lowercased versions of the raw strings } } } AS %NORMALIZEDstrings WHERE { # Find works that have "author name string" values equal to these normalized strings INCLUDE %NORMALIZEDstrings OPTIONAL { ?work wdt:P2093 ?string. } } GROUP BY ?string ORDER BY DESC (?count)

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
# Case variations of author name strings
# Example uppercase strings: https://w.wiki/nDK
# Example items: Q2381157 Q21076181 Q21339258 Q21391696 Q21393244 Q21514479 Q21609166 Q22112765 Q22222864 Q63496558 Q64008584 Q88059762

PREFIX target: <http://www.wikidata.org/entity/Q21393244>

SELECT DISTINCT ?string (COUNT(?work) AS ?count) 
WHERE {
  # Find works that have "author name string" values equal to these normalized strings

{
  # Calculate capitalization variants of these raw strings
  SELECT DISTINCT ?string
  WHERE
  {
    {

{
  # Find strings associated with the target item
  SELECT DISTINCT ?string_
  WHERE
  {
    { target: rdfs:label ?string_. } # in label
    UNION
    { target: skos:altLabel ?string_. } # in alias
    UNION
    {
      ?author_statement ps:P50 target: ; 
                        pq:P1932 ?string_. # in "stated as" strings for "author" statements on work items
    }
  }
}      BIND(STR(?string_) AS ?string) # the raw strings
    }
    UNION
    {

{
  # Find strings associated with the target item
  SELECT DISTINCT ?string_
  WHERE
  {
    { target: rdfs:label ?string_. } # in label
    UNION
    { target: skos:altLabel ?string_. } # in alias
    UNION
    {
      ?author_statement ps:P50 target: ; 
                        pq:P1932 ?string_. # in "stated as" strings for "author" statements on work items
    }
  }
}      BIND(UCASE(STR(?string_)) AS ?string) # uppercased versions of the raw strings
    }
    UNION
    {

{
  # Find strings associated with the target item
  SELECT DISTINCT ?string_
  WHERE
  {
    { target: rdfs:label ?string_. } # in label
    UNION
    { target: skos:altLabel ?string_. } # in alias
    UNION
    {
      ?author_statement ps:P50 target: ; 
                        pq:P1932 ?string_. # in "stated as" strings for "author" statements on work items
    }
  }
}      BIND(LCASE(STR(?string_)) AS ?string) # lowercased versions of the raw strings
    }
  }
}  OPTIONAL { ?work wdt:P2093 ?string. }
}
GROUP BY ?string
ORDER BY DESC (?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?author_statement") v6("?count") v5("?string"):::projected v2("?string_") v5("?work"):::projected c1([http://www.wikidata.org/entity/Q21393244]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v3 --"ps:P50"--> c1 v3 --"pq:P1932"--> v2 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; c1 --"skos:altLabel"--> v2 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; c1 --"rdfs:label"--> v2 end union2r <== or ==> union2l end bind0[/"lower-case(str(?string_))"/] v2 --o bind0 bind0 --as--o v5 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; subgraph union5[" Union "] subgraph union5l[" "] style union5l fill:#abf,stroke-dasharray: 3 3; v3 --"ps:P50"--> c1 v3 --"pq:P1932"--> v2 end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; c1 --"skos:altLabel"--> v2 end union5r <== or ==> union5l end end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; c1 --"rdfs:label"--> v2 end union4r <== or ==> union4l end bind1[/"upper-case(str(?string_))"/] v2 --o bind1 bind1 --as--o v5 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph union6[" Union "] subgraph union6l[" "] style union6l fill:#abf,stroke-dasharray: 3 3; subgraph union7[" Union "] subgraph union7l[" "] style union7l fill:#abf,stroke-dasharray: 3 3; v3 --"ps:P50"--> c1 v3 --"pq:P1932"--> v2 end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; c1 --"skos:altLabel"--> v2 end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; c1 --"rdfs:label"--> v2 end union6r <== or ==> union6l end bind2[/"str(?string_)"/] v2 --o bind2 bind2 --as--o v5 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."wdt:P2093".-> v5 end bind4[/"count(?work)"/] v5 --o bind4 bind4 --as--o v6