1

I have a list of verified Twitter User-IDs.

data['screen_name'] = [MOFAJapan_en, serenawilliams, JeffBezos ....]
data['twitter_ids'] =  [303735625, 26589987, 15506669 ....]

and I want to get their respective Q-IDs from Wikidata. For the above Twitter-username-IDs, it will look sort of like this:

q_id_list = [Q222241, Q11459, Q312556 ....]

I ran into a slight complication here: if you search for MOFAJapan_en or MOFA of Japan, Wikidata API cannot recognize it. However, MOFAJapan has a wikidata page.

example wikidata entity for Twitter ID

I know that the Property # for Twitter username is P2002, but how do I query for this without knowing the Q-ID?

Thank you in advance.

Yash
  • 81
  • 7
  • As you have added both tags: Do you use the API or the SPARQL endpoint? Can you [edit] your question to include the way you’ve tried? – Stefan - brox IT-Solutions Sep 14 '22 at 08:22
  • @Stefan-broxIT-Solutions either one is fine, but I'm making an API call right now using python-requests. I also found Q-id from google search API and then got the wiki data page with that Q-id, however, it's not working well. Just need to search for Q-id based on twitter username id. – Yash Sep 19 '22 at 03:40

1 Answers1

1

Given a list of Twitter names (inside VALUES), this SPARQL query will find the persons:

SELECT ?twitterName ?person
WHERE {

  VALUES ?twitterName {
    "MOFAJapan_en"
    "serenawilliams"
    "JeffBezos"
  }

  ?person wdt:P2002 ?twitterName .
  
}

It won’t find anything for MOFAJapan_en, as the correct value seems to be MofaJapan_en. To ignore case, you can use a FILTER with LCASE, but this will increase runtime performance:

SELECT ?twitterName ?person
WHERE {

  VALUES ?twitterName_anyCase {
    "MOFAJapan_en"
    "serenawilliams"
    "JeffBezos"
  }
  
  FILTER( LCASE(?twitterName_anyCase) = LCASE(?twitterName) ) .

  ?person wdt:P2002 ?twitterName .
  
}