Search code examples
sparqlwikidata

How to extract twitter id from item on Wikidata?


I'm looking at https://www.wikidata.org/wiki/Q181912. There's a section for "TWitter username" (P2002), and this also has "Twitter user numeric ID" (P6552). How do I go about extracting this value? I have tried

SELECT ?twitternameLabel ?twitteridLabel
WHERE 
{
  wd:Q181912 wdt:P2002 ?twittername .
  wd:Q181912 wdt:P3744 ?twitterid .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

But I get no results. If I remove the line wd:Q181912 wdt:P3744 ?twitterid . then I get the correct twitter name. How do I get the id?


Solution

  • So P3744 is the number of subscribers.

    In RDF you often have to 'reify' data.

    What does 'reify' mean and why would you do it? In this case, you have the company KLM (wd:Q181912) and you want their twitter handles. However, there are two such handles, KLM and KLM_JP, each with a different numeric ID, 56377143 and 171410513 respectively.

    If you had both IDs connected to wd:Q181912 directly, then the data would be ambiguous as to which ID referred to which twitter handle, i.e. does KLM_JP have 56377143 or 171410513?

    For your purposes, you need to look at properties under different namespaces therefore, see here for more.

    Here is something that works:

    SELECT ?twitterid ?twittername
    WHERE 
    {
      wd:Q181912 p:P2002 ?twitterstatement .
      ?twitterstatement pq:P6552 ?twitterid ;
                        ps:P2002 ?twittername .
    
    }