2

Here are some example records:

https://www.wikidata.org/wiki/Q11361734

https://www.wikidata.org/wiki/Q74669

I have the following (updated) query:

# Script #2
SELECT
    (GROUP_CONCAT(       ?dateYear ; separator = ", ") AS        ?dateYears)
    (GROUP_CONCAT(       ?cooLabel ; separator = ", ") AS        ?cooLabels)
    (GROUP_CONCAT(DISTINCT ?gameENLabel ; separator = ", ") AS ?gameENLabels)       # English
    (GROUP_CONCAT(DISTINCT      ?dataLink ; separator = ", ") AS        ?dataLinks)
WHERE
{
    # 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
    ?game rdfs:label ?gameENLabel.
    FILTER(LANG(?gameENLabel) = "en"). # we mainly want English labels

    # wikidata link
    BIND(CONCAT("=hyperlink(\"",replace(replace(STR(?game), "entity", "wiki"), "http", "https"),"\")") AS ?dataLink).       # changes the target of the URL and creates a MS Excel compatible hyperlink
    #BIND(STR(?game) AS ?dataLink).     # faster substitute

    # release date (simple)
    OPTIONAL
    {
        ?game wdt:P577 ?date BIND(YEAR(?date) AS ?dateYear)
        OPTIONAL
        {
            ?game p:P577 ?dateProp.
            ?dateProp pq:P291 ?region.
            ?region wdt:P297 ?cooLabel.
        }
    }
}
GROUP BY $game
ORDER BY asc (?dateYears) ASC (?gameENLabels)
#limit 100

However, there are some issues:

  1. It is not rendering all "publication dates" when those dates do not also have a "place of publication" sub-property
  2. If the "place of publication" is missing, I would like the missing property to be replaced with "???" (or something similar), so that every game has a date/region pair of some sort in the output

Can someone show me how to accomplish this? Thanks!

[edit]

Here is some example current output:

1983        Ultima III: Exodus  =hyperlink("https://www.wikidata.org/wiki/Q2240236")
1983        Ultima: Escape from Mt. Drash   =hyperlink("https://www.wikidata.org/wiki/Q4003118")
1983        Universe    =hyperlink("https://www.wikidata.org/wiki/Q7894198")
1983        Wizardry III: Legacy of Llylgamyn   =hyperlink("https://www.wikidata.org/wiki/Q8028765")
1983, 1982, 1978        Beneath Apple Manor =hyperlink("https://www.wikidata.org/wiki/Q4887174")
1984        50 Mission Crush    =hyperlink("https://www.wikidata.org/wiki/Q635707")
1984        Gemstone Warrior    =hyperlink("https://www.wikidata.org/wiki/Q5530766")
1984        Questron    =hyperlink("https://www.wikidata.org/wiki/Q2687236")
1985    JP  Cosmic Soldier  =hyperlink("https://www.wikidata.org/wiki/Q869287")
2016, 2016, 2016, 2016, 2015, 2015  JP, AU, JP, AU, JP, AU  Monster Hunter Generations  =hyperlink("https://www.wikidata.org/wiki/Q20856979")
2016, 2016, 2016, 2016, 2016, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2013, 2013, 2013, 2013, 2013, 2012, 2012, 2012, 2012, 2012    JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP, JP  Phantasy Star Online 2  =hyperlink("https://www.wikidata.org/wiki/Q2709892")

[edit]

Here is some example desired output:

2014, 2015, 2017    JP, ??, ??  Game Title =hyperlink("https://www.wikidata.org/wiki/Q2709892")
  • 2
    1. Use nested OPTIONALs. 2. Please paste example output. – Stanislav Kralin Oct 27 '17 at 7:49
  • Thanks. You can view the (updated) query and output here: tinyurl.com/y9nefmj9 – posfan12 Oct 27 '17 at 7:59
  • 1
    The order of strings is not specified. Nobody can guarantee that 1st ?dateYear corresponds to 1st ?coolLabel after concatenation. – Stanislav Kralin Oct 27 '17 at 8:11
  • 1
    At your own risk: place BIND (IF(!bound(?cooLabel), "???", ?cooLabel) AS ?coolLabel) inside the first OPTIONAL. Respectively in the projection: (SAMPLE(?coolLabel) AS ?cooLabels). – Stanislav Kralin Oct 27 '17 at 8:19
  • 1
    Projection is a part between SELECT and WHERE. But this was my mistake, you do not need to replace group_concat with sample. BTW, see jira.blazegraph.com/browse/BLZG-842. However, one could look into query execution plan (adding &explain to your SPARQL query) or into Blazegraph source code hoping that two group_concat's are "isomorphic". – Stanislav Kralin Oct 27 '17 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.