A little messier than you might like, but the following query does what you ask:
    http://tinyurl.com/zxlsyk5


      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      PREFIX wikibase: <http://wikiba.se/ontology#>
      PREFIX entity: <http://www.wikidata.org/entity/>
      PREFIX p: <http://www.wikidata.org/prop/direct/>

      SELECT ?propUrl ?propLabel ?valUrl ?valLabel ?picture
      WHERE {
        hint:Query hint:optimizer 'None' .
        { BIND(entity:Q42 AS ?valUrl) .
          BIND("N/A" AS ?propUrl ) .
          BIND("identity"@en AS ?propLabel ) .
        }
        UNION
        { entity:Q42 ?propUrl ?valUrl .

          ?property ?ref ?propUrl .
          ?property a wikibase:Property .
          ?property rdfs:label ?propLabel
        }

        ?valUrl rdfs:label ?valLabel
        FILTER (LANG(?valLabel) = 'en') .

        OPTIONAL{
          ?valUrl p:P18 ?picture .
        }
        FILTER (lang(?propLabel) = 'en' )
       }
      ORDER BY ?propUrl ?valUrl LIMIT 200





On 06/04/2016 19:38, [email protected] wrote:
I have the following SPARQL query that returns the items related to Q42.
  To avoid the compute time of making an additional query I would like to
tweak this query to return one additional row that contains the
information about Q42 itself using the same columns.  Is there a special
property that indicates a self relationship, or any other way of
accomplishing the above in one query?

       PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
       PREFIX wikibase: <http://wikiba.se/ontology#>
       PREFIX entity: <http://www.wikidata.org/entity/>
       PREFIX p: <http://www.wikidata.org/prop/direct/>

       SELECT ?propUrl ?propLabel ?valUrl ?valLabel ?picture
       WHERE {
         hint:Query hint:optimizer 'None' .
         entity:Q42 ?propUrl ?valUrl .
         ?valUrl rdfs:label ?valLabel

         FILTER (LANG(?valLabel) = 'en') .

         ?property ?ref ?propUrl .
         ?property a wikibase:Property .
         ?property rdfs:label ?propLabel

         OPTIONAL{
           ?valUrl p:P18 ?picture .
         }
         FILTER (lang(?propLabel) = 'en' )
        }
       ORDER BY ?propUrl ?valUrl LIMIT 200


Please advise,
James Weaver

_______________________________________________
Wikidata mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata



_______________________________________________
Wikidata mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata

Reply via email to