maxbbraun / trump2cash

A stock trading bot powered by Trump tweets
https://trump2cash.biz
MIT License
6.25k stars 857 forks source link

Improve Wikidata query #4

Open maxbbraun opened 7 years ago

maxbbraun commented 7 years ago

The current Wikidata query, for example, takes chains of ownership and subsidiaries into account, but doesn't mix those chains.

There are also probably additional relationships between companies that should be taken into account.

maxbbraun commented 7 years ago

Some improvements in https://github.com/maxbbraun/trump2cash/commit/02e66eddc4ea0666e4be1abec302cad7c48f2053, https://github.com/maxbbraun/trump2cash/commit/954f4621a1adf17132cfa8e7ded6dd6813dd2b25, https://github.com/maxbbraun/trump2cash/commit/725c0596773d58158a8b8cdab1b3b7b4a579b500, https://github.com/maxbbraun/trump2cash/commit/14d861fb3dc0e911afd60ae3f5cb48cfed4598f1, and https://github.com/maxbbraun/trump2cash/commit/77c609bfaac8151c7948d26ab0d66bc9ba84787f.

CraigglesO commented 7 years ago

This is a great query system. For some reason I get get no results though: https://query.wikidata.org/#SELECT%20%3FcompanyLabel%20%3FrootLabel%20%3FtickerLabel%20%3FexchangeNameLabel%0A%20%20%20%20%20WHERE%20%7B%0A%20%20%20%20%20%20%3Fentity%20wdt%3AP646%20%22Apple%22%20.%20%20%23%20Entity%20with%20specified%20Freebase%20ID.%0A%20%20%20%20%20%20%3Fentity%20wdt%3AP176%2a%20%3Fmanufacturer%20.%20%20%23%20Entity%20may%20be%20product.%0A%20%20%20%20%20%20%3Fmanufacturer%20wdt%3AP156%2a%20%3Fcompany%20.%20%20%23%20Company%20may%20have%20restructured.%0A%20%20%20%20%20%20%7B%20%3Fcompany%20p%3AP414%20%3Fexchange%20%7D%20UNION%20%20%23%20Company%20traded%20on%20exchange%20or...%0A%20%20%20%20%20%20%7B%20%3Fcompany%20wdt%3AP127%2B%20%2F%20wdt%3AP156%2a%20%3Froot%20.%20%20%23%20...%20company%20has%20owner.%0A%20%20%20%20%20%20%20%20%3Froot%20p%3AP414%20%3Fexchange%20%7D%20UNION%20%20%23%20Owner%20traded%20on%20exchange%20or%20...%0A%20%20%20%20%20%20%7B%20%3Fcompany%20wdt%3AP749%2B%20%2F%20wdt%3AP156%2a%20%3Froot%20.%20%20%23%20...%20company%20has%20parent.%0A%20%20%20%20%20%20%20%20%3Froot%20p%3AP414%20%3Fexchange%20%7D%20.%20%20%23%20Parent%20traded%20on%20exchange.%0A%20%20%20%20%20%20VALUES%20%3Fexchanges%20%7B%20wd%3AQ13677%20wd%3AQ82059%20%7D%20.%20%20%23%20Whitelist%20NYSE%2C%20NASDAQ.%0A%20%20%20%20%20%20%3Fexchange%20ps%3AP414%20%3Fexchanges%20.%20%20%23%20Stock%20exchange%20is%20whitelisted.%0A%20%20%20%20%20%20%3Fexchange%20pq%3AP249%20%3Fticker%20.%20%20%23%20Get%20ticker%20symbol.%0A%20%20%20%20%20%20%3Fexchange%20ps%3AP414%20%3FexchangeName%20.%20%20%23%20Get%20name%20of%20exchange.%0A%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%0A%20%20%20%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20.%20%20%23%20Use%20English%20labels.%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%7D%20GROUP%20BY%20%3FcompanyLabel%20%3FrootLabel%20%3FtickerLabel%20%3FexchangeNameLabel

CraigglesO commented 7 years ago

stupid me. For anyone else learning wikidata and the SPARQL system, the freebase requires and ID

https://www.wikidata.org/wiki/Property:P646

https://github.com/maxbbraun/trump2cash/blob/master/analysis.py#L125