/// <summary> /// Creates a new instance of <see cref="WikiDataHelper"/>. /// </summary> /// <param name="api">The WikiData API encapsulation.</param> public WikiDataHelper(WikibaseApi api) { if ( api == null ) throw new ArgumentNullException("api"); Api = api; _entityProvider = new EntityProvider(Api); var entities = GlobalData.CompleteGeocodeList(); _allEntities = entities.FlatList(); }
internal static Entity newFromArray(WikibaseApi api, JsonObject data) { if (data.get("type") != null) { switch (data.get("type").asString()) { case "item": return(new Item(api, data)); case "property": return(new Property(api, data)); } } throw new Exception("Unknown type"); }
internal Entity(WikibaseApi api, JsonObject data) { this.api = api; this.fillData(data); }
/// <summary> /// Constructor /// </summary> /// <param name="api">The api</param> public Entity(WikibaseApi api) : this(api, new JsonObject()) { }
internal static Entity newFromArray(WikibaseApi api, JsonObject data) { if (data.get("type") != null) { switch (data.get("type").asString()) { case "item": return new Item(api, data); case "property": return new Property(api, data); } } throw new Exception("Unknown type"); }
internal Item(WikibaseApi api, JsonObject data) : base(api, data) { }
/// <summary> /// Constructor /// </summary> /// <param name="api">The api</param> public Item(WikibaseApi api) : base(api) { }
internal Property(WikibaseApi api, JsonObject data) : base(api, data) { }
private Dictionary<Entity, String> RetrieveWikpediaLinks(IEnumerable<Entity> entities, Language language) { var result = new Dictionary<Entity, String>(); var api = new WikibaseApi("https://www.wikidata.org", "TambonBot"); var helper = new WikiDataHelper(api); foreach ( var entity in entities.Where(x => x.wiki != null && !String.IsNullOrEmpty(x.wiki.wikidata)) ) { var item = helper.GetWikiDataItemForEntity(entity); if ( item != null ) { var links = item.getSitelinks(); String languageLink; String wikiIdentifier = String.Empty; switch ( language ) { case Language.German: wikiIdentifier = "dewiki"; break; case Language.English: wikiIdentifier = "enwiki"; break; case Language.Thai: wikiIdentifier = "thwiki"; break; } if ( item.getSitelinks().TryGetValue(wikiIdentifier, out languageLink) ) { result[entity] = languageLink; } } } return result; }
/// <summary> /// Constructor /// </summary> /// <param name="api">The api</param> public EntityProvider(WikibaseApi api) { this.api = api; }
/// <summary> /// Constructor /// </summary> /// <param name="api">The api</param> public Property(WikibaseApi api) : base(api) { }