-
Notifications
You must be signed in to change notification settings - Fork 6
EntityProvider
Benestar edited this page Oct 21, 2013
·
5 revisions
The EntityProvider
provides, as the name suggests, access to entities. You can get one or even multiple entities at once, by giving either their ids or pairs of sites and titles. Note that the second oppertunity will only return items. You can also specifiy that data should only be loaded in some specific languages.
The examples below assume that you already now how to work with the api and that you have created an instance of the WikibaseApi class called api
.
// Create a new EntityProvider instance and pass the api created above.
EntityProvider entityProvider = new EntityProvider(api);
// Get an entity by searching for the id
Entity entityById = entityProvider.getEntityFromId(EntityId.newFromPrefixedId("Q10"));
// Get several entities
EntityId[] entityIds = new EntityId[2];
entityIds[0] = EntityId.newFromPrefixedId("Q19");
entityIds[1] = EntityId.newFromPrefixedId("Q20");
Entity[] entities = entityProvider.getEntitiesFromIds(entityIds);
// Get an entity by site and title and get the data only in English and German
string[] languages = new string[] { "en", "de" };
Entity entityBySitelink = entityProvider.getEntityFromSitelink("enwiki", "GitHub", languages);
Take me home!