query-5cd1f9b42fc2f410eacc4423347e7fb4

rq turtle/ttl

Script #2 SELECT (MIN(?dateYear) AS ?dateYears) (GROUP_CONCAT(DISTINCT ?gameENLabelTxt; separator = ", ") AS ?gameENLabelTxts) # English label (GROUP_CONCAT(DISTINCT ?genreLabel; separator = ", ") AS ?gamGenreLabels) (GROUP_CONCAT(DISTINCT ?themeLabel; separator = ", ") AS ?ficGenreLabels) (GROUP_CONCAT(DISTINCT ?devLabel; separator = ", ") AS ?devLabels) (GROUP_CONCAT(DISTINCT ?pubLabel; separator = ", ") AS ?pubLabels) (GROUP_CONCAT(DISTINCT ?platLabel; separator = ", ") AS ?platLabels) (GROUP_CONCAT(DISTINCT ?seriesLabel; separator = ", ") AS ?seriesLabels)

(?game AS ?dataLink)

WHERE
{
    #hint:Query hint:optimizer "None".

    # test values

VALUES ?game

{

wd:Q4850488 # Baldur's Gate III: The Black Hound (should have "no value" due to being cancelled)

wd:Q4931588 # Bob's Game (should have "no value" due to not being released yet)

wd:Q5315330 # Dunjonquest (1979)

wd:Q5250229 # Deep Labyrinth (should have multiple dates)

wd:Q1462499 # Starflight (1986, has multiple genres)

wd:Q22124593 # God Wars: Beyond Time (should have blank date since the property does not exist)

}

    # types of item
          {?game wdt:P136  wd:Q744038}  # regular RPGs
    UNION {?game wdt:P136 wd:Q1529437}  # tactical RPGs
    UNION {?game wdt:P136 wd:Q1422746}  # action RPGs
    UNION {?game wdt:P136 wd:Q1143132}  # roguelikes

?game wdt:P136/wdt:P279* wd:Q744038. # any class or subclass of role-playing video game, including MMORPGs

    ?game wdt:P31 wd:Q7889.                         # instance of video game

    # English label
    OPTIONAL
    {
        ?game rdfs:label ?gameENLabel FILTER(LANG(?gameENLabel) = "en").
        BIND(CONCAT(?gameENLabel, " (EN)") AS ?gameENLabelTxt)
    }

    # release date (simple)
    OPTIONAL {?game wdt:P577 ?date BIND(YEAR(?date) AS ?dateYear)}

    # gameplay genres
    OPTIONAL
    {
        ?game wdt:P136 ?gameGenre.
        ?gameGenre wdt:P31 wd:Q659563.
        FILTER(?gameGenre != wd:Q744038).
        ?gameGenre rdfs:label ?gameplayGenreString.
        FILTER(LANG(?gameplayGenreString) = "en").
        BIND(CONCAT(UCASE(SUBSTR(?gameplayGenreString, 1, 1)), SUBSTR(?gameplayGenreString, 2)) AS ?genreLabel).        # makes the first character in the string upper case

BIND(STR(?gameplayGenreString) AS ?genreLabel). # faster substitute

    }

    # fiction genres
    OPTIONAL
    {
        ?game wdt:P136 ?otherGenre.
        MINUS {?otherGenre wdt:P31 wd:Q659563}.
        ?otherGenre rdfs:label ?fictionGenreString.
        FILTER(LANG(?fictionGenreString) = "en").
        BIND(CONCAT(UCASE(SUBSTR(?fictionGenreString, 1, 1)), SUBSTR(?fictionGenreString, 2)) AS ?themeLabel).      # makes the first character in the string upper case

BIND(STR(?fictionGenreString) AS ?themeLabel). # faster substitute

    }

    # developer, publisher, platform and series
    OPTIONAL {?game wdt:P178    ?developer}
    OPTIONAL {?game wdt:P123    ?publisher}
    OPTIONAL {?game wdt:P400     ?platform}
    OPTIONAL {?game wdt:P179       ?series}

    # labels
    SERVICE wikibase:label
    {
        bd:serviceParam wikibase:language "en".
        ?developer rdfs:label          ?devLabel.
        ?publisher rdfs:label          ?pubLabel.
         ?platform rdfs:label         ?platLabel.
           ?series rdfs:label       ?seriesLabel.
    }
}

GROUP BY $game ORDER BY ASC (?dateYears) ASC (?gameENLabelTxts)

limit 100

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Script #2
SELECT
    (MIN(?dateYear) AS  ?dateYears)
    (GROUP_CONCAT(DISTINCT  ?gameENLabelTxt;    separator = ", ") AS    ?gameENLabelTxts)       # English label
    (GROUP_CONCAT(DISTINCT  ?genreLabel;        separator = ", ") AS    ?gamGenreLabels)
    (GROUP_CONCAT(DISTINCT  ?themeLabel;        separator = ", ") AS    ?ficGenreLabels)
    (GROUP_CONCAT(DISTINCT  ?devLabel;      separator = ", ") AS    ?devLabels)
    (GROUP_CONCAT(DISTINCT  ?pubLabel;      separator = ", ") AS    ?pubLabels)
    (GROUP_CONCAT(DISTINCT  ?platLabel;     separator = ", ") AS    ?platLabels)
    (GROUP_CONCAT(DISTINCT  ?seriesLabel;       separator = ", ") AS    ?seriesLabels)
#   (?game AS ?dataLink)
    WHERE
    {
        #hint:Query hint:optimizer "None".

        # test values
#       VALUES ?game
#       {
#           wd:Q4850488     # Baldur's Gate III: The Black Hound (should have "no value" due to being cancelled)
#           wd:Q4931588     # Bob's Game (should have "no value" due to not being released yet)
#           wd:Q5315330     # Dunjonquest (1979)
#           wd:Q5250229     # Deep Labyrinth (should have multiple dates)
#           wd:Q1462499     # Starflight (1986, has multiple genres)
#           wd:Q22124593        # God Wars: Beyond Time (should have blank date since the property does not exist)
#       }

        # types of item
              {?game wdt:P136  wd:Q744038}  # regular RPGs
        UNION {?game wdt:P136 wd:Q1529437}  # tactical RPGs
        UNION {?game wdt:P136 wd:Q1422746}  # action RPGs
        UNION {?game wdt:P136 wd:Q1143132}  # roguelikes
#       ?game wdt:P136/wdt:P279* wd:Q744038.    # any class or subclass of role-playing video game, including MMORPGs
        ?game wdt:P31 wd:Q7889.                         # instance of video game

        # English label
        OPTIONAL
        {
            ?game rdfs:label ?gameENLabel FILTER(LANG(?gameENLabel) = "en").
            BIND(CONCAT(?gameENLabel, " (EN)") AS ?gameENLabelTxt)
        }

        # release date (simple)
        OPTIONAL {?game wdt:P577 ?date BIND(YEAR(?date) AS ?dateYear)}

        # gameplay genres
        OPTIONAL
        {
            ?game wdt:P136 ?gameGenre.
            ?gameGenre wdt:P31 wd:Q659563.
            FILTER(?gameGenre != wd:Q744038).
            ?gameGenre rdfs:label ?gameplayGenreString.
            FILTER(LANG(?gameplayGenreString) = "en").
            BIND(CONCAT(UCASE(SUBSTR(?gameplayGenreString, 1, 1)), SUBSTR(?gameplayGenreString, 2)) AS ?genreLabel).        # makes the first character in the string upper case
#           BIND(STR(?gameplayGenreString) AS ?genreLabel).     # faster substitute
        }

        # fiction genres
        OPTIONAL
        {
            ?game wdt:P136 ?otherGenre.
            MINUS {?otherGenre wdt:P31 wd:Q659563}.
            ?otherGenre rdfs:label ?fictionGenreString.
            FILTER(LANG(?fictionGenreString) = "en").
            BIND(CONCAT(UCASE(SUBSTR(?fictionGenreString, 1, 1)), SUBSTR(?fictionGenreString, 2)) AS ?themeLabel).      # makes the first character in the string upper case
#           BIND(STR(?fictionGenreString) AS ?themeLabel).      # faster substitute
        }

        # developer, publisher, platform and series
        OPTIONAL {?game wdt:P178    ?developer}
        OPTIONAL {?game wdt:P123    ?publisher}
        OPTIONAL {?game wdt:P400     ?platform}
        OPTIONAL {?game wdt:P179       ?series}

        # labels
        SERVICE wikibase:label
        {
            bd:serviceParam wikibase:language "en".
            ?developer rdfs:label          ?devLabel.
            ?publisher rdfs:label          ?pubLabel.
             ?platform rdfs:label         ?platLabel.
               ?series rdfs:label       ?seriesLabel.
        }
    }
GROUP BY $game
ORDER BY ASC (?dateYears) ASC (?gameENLabelTxts)
#limit 100

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?date") v10("?dateYear"):::projected v22("?dateYears") v18("?devLabel"):::projected v24("?devLabels") v14("?developer") v23("?ficGenreLabels") v3("?fictionGenreString") v22("?gamGenreLabels") v7("?game") v6("?gameENLabel") v8("?gameENLabelTxt"):::projected v22("?gameENLabelTxts") v4("?gameGenre") v5("?gameplayGenreString") v11("?genreLabel"):::projected v12("?otherGenre") v20("?platLabel"):::projected v26("?platLabels") v16("?platform") v19("?pubLabel"):::projected v25("?pubLabels") v15("?publisher") v17("?series") v21("?seriesLabel"):::projected v27("?seriesLabels") v13("?themeLabel"):::projected c2(["wd:Q744038"]):::iri c1(["en"]):::literal c5(["wd:Q1422746"]):::iri c4(["wd:Q1529437"]):::iri c17(["bd:serviceParam"]):::iri c8(["wd:Q7889"]):::iri c11(["wd:Q659563"]):::iri c6(["wd:Q1143132"]):::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; v7 --"wdt:P136"--> c6 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v7 --"wdt:P136"--> c5 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v7 --"wdt:P136"--> c4 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v7 --"wdt:P136"--> c2 end union0r <== or ==> union0l end v7 --"wdt:P31"--> c8 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."rdfs:label".-> v6 bind0[/"concat(?gameENLabel,' (EN)')"/] v6 --o bind0 bind0 --as--o v8 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P577".-> v9 bind1[/"year-from-dateTime(?date)"/] v9 --o bind1 bind1 --as--o v10 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P136".-> v4 v4 --"wdt:P31"--> c11 v4 --"rdfs:label"--> v5 bind2[/"concat(upper-case(substring(?gameplayGenreString,'1^^xsd:integer','1^^xsd:integer')),substring(?gameplayGenreString,'2^^xsd:integer'))"/] v5 --o bind2 bind2 --as--o v11 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P136".-> v12 subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; v12 --"wdt:P31"--> c11 end v12 --"rdfs:label"--> v3 bind4[/"concat(upper-case(substring(?fictionGenreString,'1^^xsd:integer','1^^xsd:integer')),substring(?fictionGenreString,'2^^xsd:integer'))"/] v3 --o bind4 bind4 --as--o v13 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P178".-> v14 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P123".-> v15 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P400".-> v16 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P179".-> v17 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c17 --"wikibase:language"--> c1 v14 --"rdfs:label"--> v18 v15 --"rdfs:label"--> v19 v16 --"rdfs:label"--> v20 v17 --"rdfs:label"--> v21 end bind13[/"min(?dateYear)"/] v10 --o bind13 bind13 --as--o v22 bind14[/"?gameENLabelTxt"/] v8 --o bind14 bind14 --as--o v22 bind15[/"?genreLabel"/] v11 --o bind15 bind15 --as--o v22 bind16[/"?themeLabel"/] v13 --o bind16 bind16 --as--o v23 bind17[/"?devLabel"/] v18 --o bind17 bind17 --as--o v24 bind18[/"?pubLabel"/] v19 --o bind18 bind18 --as--o v25 bind19[/"?platLabel"/] v20 --o bind19 bind19 --as--o v26 bind20[/"?seriesLabel"/] v21 --o bind20 bind20 --as--o v27