1

I am trying to create a wiki data SPARQL query. What I want to do is to get multiple items from the some property For example: I am trying to fetch all data that have property of instance of statistical packages. But the problem I am facing is for example a Statistical Package of Social Sciences have property type 348 which have multiple versions. I wanted to fetch all these version and also the publication date if the version have publication date as well. I read some document and try to create a query but I am unable to get all version from the property p:348.

SELECT ?software ?softwareLabel ?developerLabel ?versionLabel ?date
WHERE
{
  ?software wdt:P31 wd:Q13199995 . 
   OPTIONAL { ?software wdt:P178 ?developer. }
  OPTIONAL { ?software  wdt:P348 ?version. }
   OPTIONAL { 
  FILTER EXISTS {
       ?software wdt:P348 ?version2. 
      FILTER ( ?version != ?version2 )
      }
     }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}

Here I have attached the query that I am using to get all the required information. I am really stuck on this problem. I would be really grateful for any kind of help.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Abdul Muqeet
  • 65
  • 2
  • 8
  • 1
    `SELECT ?software ?softwareLabel ?developerLabel ?versionLabel ?date WHERE { ?software wdt:P31 wd:Q13199995 . OPTIONAL { ?software wdt:P178 ?developer. } OPTIONAL { ?software p:P348 ?stmt . ?stmt ps:P348 ?version. OPTIONAL {?stmt pq:P577 ?date }} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }` – UninformedUser Jul 01 '21 at 08:14
  • That works thanks alot. you are great! Can you also help me with dbpedia query. I want multiple version and if available the releasedate too, my query is select distinct ?software ,?name, ?date , ?version where { ?software rdf:type dbo:Software. FILTER NOT EXISTS {?software rdf:type dbo:VideoGame} OPTIONAL {?software foaf:name ?name.} OPTIONAL{ ?software rdfs:label ?label. FILTER(LANG(?label) = 'en'). }. OPTIONAL {?software dbo:latestReleaseDate ?date. } OPTIONAL {?software dbo:latestReleaseVersion ?version. } } – Abdul Muqeet Jul 01 '21 at 08:42
  • what's not working with the DBpedia query? – UninformedUser Jul 01 '21 at 09:24
  • Like wikidata query that you wrote fetching name and all version and its publication date. I wanted to do the same but I am getting only one version and release date. – Abdul Muqeet Jul 01 '21 at 09:35
  • 1
    well, did you check any of the data? I mean, have a look at https://dbpedia.org/page/ACIS, there is indeed only one version of any. It's also quite obvious given that the property is called "latestReleaseVersion", isn't it? From my experience, DBpedia isn't good at modeling historical data and the data is usually a mapping to the Wikipedia infobox, see https://en.wikipedia.org/wiki/ACIS - only the latest version is kept – UninformedUser Jul 01 '21 at 09:59
  • Thanks a lot. This surely helps me. – Abdul Muqeet Jul 01 '21 at 10:04
  • Just one last this can you help me with the one other issue. The query you wrote works perfectly but if I want to get values not only from instance statistical packages (wd: Q13199995) But also from Software(Q7397) and application (Q166142), How can I query to get the same column with these two properties as well. Currently I am writing two different queries and combing them in dataframes in python but this would be great I could resolve this in a single query. – Abdul Muqeet Jul 01 '21 at 10:31
  • 1
    Sparkql is not SQL, so I removed the SQL tag. – Gordon Linoff Jul 01 '21 at 10:48
  • 1
    @AbdulMuqeet either `UNION` or `VALUES` is your friend: `SELECT ?software ?softwareLabel ?developerLabel ?versionLabel ?date WHERE { VALUES ?type {wd:Q7397 wd:Q13199995 wd:Q166142} ?software wdt:P31 ?type OPTIONAL { ?software wdt:P178 ?developer. } OPTIONAL { ?software p:P348 ?stmt. ?stmt ps:P348 ?version. OPTIONAL { ?stmt pq:P577 ?date. } } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }` – UninformedUser Jul 01 '21 at 11:22
  • You are the best thank you so much. – Abdul Muqeet Jul 01 '21 at 11:52

1 Answers1

3

either UNION or VALUES is your friend:

SELECT ?software ?softwareLabel ?developerLabel
    ?versionLabel ?date WHERE {   VALUES ?type 
    {wd:Q7397 wd:Q13199995 wd:Q166142}   ?software wdt:P31 ?type   
    OPTIONAL { ?software wdt:P178 ?developer. }  
    OPTIONAL {     ?software p:P348 ?stmt.    
    ?stmt ps:P348 ?version.     
    OPTIONAL { ?stmt pq:P577 ?date. }   }   
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }
Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76