You can also try RelFinder to see the connections visually
http://www.visualdataweb.org/relfinder.php

You can set the wikidata endpoint in the configuration to try
and check the paper for the query generation algorithm

Best,
Dimitris

On Mon, Apr 20, 2015 at 10:53 PM, Markus Krötzsch <markus@semantic-mediawiki.org> wrote:
Hi Matthew,

You can use our experimental SPARQL endpoint http://milenio.dcc.uchile.cl/sparql. It has direct relations for all statements that have no qualifiers, and two-step relations for all statements (with or without qualifiers), which are a bit more complex but give you more power over what you can query for.

Examples:

If you only care for statements without qualifiers, you can use something like this:

PREFIX : <http://www.wikidata.org/entity/>
SELECT * WHERE {
  :Q5571382 ?simpleProperty :Q223243
}

The result is [1], in HTML format (you can also get many other formats; see the query page). The result contains IRIs like http://www.wikidata.org/entity/P54c (note the added "c") that we currently use for these simple statement properties in RDF. You can just remove the c to get the property.

If you care for qualifiers, you can ask a query that gives you all ways in which two items are connected either directly, or by a qualifier of a statement:

PREFIX : <http://www.wikidata.org/entity/>
SELECT ?statementProperty ?qualifierOrValueProperty WHERE {
  :Q5571382 ?statementProperty ?statement .
  ?statement a <http://www.wikidata.org/ontology#Statement> .
  ?statement ?qualifierOrValueProperty :Q223243
}

The result is at [2]. You can see here two properties: one is the main property of the statement, one is the value or qualifier property:

http://www.wikidata.org/entity/P54s, http://www.wikidata.org/entity/P54v

The "s" is for statement, the "v" for value. If you have a qualifier instead of the main value, you would get a property ending in q in the second position. For example:

"What has 'The Imitation Game' to do with Alan Turing?"

PREFIX : <http://www.wikidata.org/entity/>
SELECT ?statementProperty ?qualifierOrValueProperty WHERE {
  :Q14918344 ?statementProperty ?statement .
  ?statement a <http://www.wikidata.org/ontology#Statement> .
  ?statement ?qualifierOrValueProperty :Q7251
}

See [3].

So this last query pattern gives you two kinds of direct relationships: "entity -> statement value" and "entity -> qualifier value". You could also ask for "statement value -> qualifier value", e.g., what has Benedict Cumberbadge to do with Alan Turing?

PREFIX : <http://www.wikidata.org/entity/>
SELECT ?qualifierOrValueProperty1 ?qualifierOrValueProperty2 WHERE {
  ?statement a <http://www.wikidata.org/ontology#Statement> .
  ?statement ?qualifierOrValueProperty1 :Q244674 .
  ?statement ?qualifierOrValueProperty2 :Q7251
}

See [4].

Right now, you cannot easily say that you only want properties that are qualifiers/value properties. This will be better once we have classes for these (and other) types of properties. It's still experimental after all.

Also note that this is not live data.

Cheers,

Markus


[1] http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+*+WHERE+{%0D%0A%3AQ5571382+%3FsimpleProperty+%3AQ223243%0D%0A}&format=text%2Fhtml&timeout=0&debug=on

[2] http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+%3FstatementProperty+%3FqualifierOrValueProperty+WHERE+{%0D%0A++%3AQ5571382+%3FstatementProperty+%3Fstatement+.%0D%0A++%3Fstatement+%3FqualifierOrValueProperty+%3AQ223243+%0D%0A}&format=text%2Fhtml&timeout=0&debug=on

[3] http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+%3FstatementProperty+%3FqualifierOrValueProperty+WHERE+{%0D%0A++%3AQ14918344+%3FstatementProperty+%3Fstatement+.%0D%0A++%3Fstatement+a+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fontology%23Statement%3E+.%0D%0A++%3Fstatement+%3FqualifierOrValueProperty+%3AQ7251+%0D%0A}&format=text%2Fhtml&timeout=0&debug=on

[4] http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+%3FqualifierOrValueProperty1+%3FqualifierOrValueProperty2+WHERE+{%0D%0A++%3Fstatement+a+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fontology%23Statement%3E+.%0D%0A++%3Fstatement+%3FqualifierOrValueProperty1+%3AQ244674+.%0D%0A++%3Fstatement+%3FqualifierOrValueProperty2+%3AQ7251+%0D%0A}&format=text%2Fhtml&timeout=0&debug=on

On 19.04.2015 08:28, English, S. Matthew wrote:
Hi,

I've been trying to create a query in the online editor
<http://wdq.wmflabs.org/wdq/?q=claim[31:%28tree[12280][][279]%29]%20AND%20tree[183][150][17,131]> such
that I can retrieve a relationship, unknown to me in advance, for two
alpha-numeric IDs (those Q numbers).

So for instance, I have Terrell Buckley (Q5571382) and Miami Dolphins
(Q223243) I was trying to maybe use one of them as a 'TREE' and then
check to see if the other was existing on one of the nodes and them take
the relationship that equates to the link traversed to get from one to
the other, is that reasonable?

But so far I've not been able to figure it out nor find any illuminating
resources online.

In general, with two IDs I'd like to write a program that will query
Wikidata and find the relationship between them. I know the problem of
semantic relatedness, like Boston the band and Boston the city, but, I
guess I'll worry about that next.

I posted this exact question earlier to
'wiki-research-l@lists.wikimedia.org
<mailto:wiki-research-l@lists.wikimedia.org>' but I guess actually its
pretty specific to wikidata, so I think this is a better place for it.
Isn't it?

Thank you for you consideration.

Sincerely,

Matthew


_______________________________________________
Wikidata-l mailing list
Wikidata-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata-l



_______________________________________________
Wikidata-l mailing list
Wikidata-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata-l



--
Kontokostas Dimitris