CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
82 stars 16 forks source link

Need documentation to query an entity #47

Open ganeshkmurthy opened 5 years ago

ganeshkmurthy commented 5 years ago

I am looking for a way to query an entity using the name and finding the QID for it. Can someone point me to an example? Thanks!

Here is what I have so far. I am able to fetch an entity using QID, but I am looking to fetch an entity by it's name.

// A WikiClient has its own CookieContainer. var client = new WikiClient { ClientUserAgent = "WCLQuickStart/1.0 (your user name or contact information here)" };

var myWikiDataSite = new WikiSite(client, "https://www.wikidata.org/w/api.php"); try { await myWikiDataSite.LoginAsync(Username, Password); } catch (Exception ex) { Console.WriteLine(ex.Message); }

try { await myWikiDataSite.Initialization; } catch (Exception ex) { Console.WriteLine(ex.Message); }

var entity = new Entity(myWikiDataSite, "Q60204555"); await entity.RefreshAsync( EntityQueryOptions.FetchAllProperties);

await myWikiDataSite.LogoutAsync(); client.Dispose();
return;

CXuesong commented 5 years ago

Perhaps you may take a look at Entity.IdsFromSiteLinksAsync. It can give you the entity IDs of the specified page titles on the specified Wiki site.

However, for now there is no implementation in WCL that can let you find the entity IDs from the specific entity title. Though it can be implemented in the future.

CXuesong commented 5 years ago

I know your problem has been solved in some way, but personally I'd like to implement something like searching by entity label/alias rather than sitelink.