Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Counts the links to the various Wikimedia projects.
        /// </summary>
        /// <param name="entities">Entities to check.</param>
        /// <returns>Number of sitelinks by name of the wiki.</returns>
        public Dictionary<String, Int32> CountSiteLinks(IEnumerable<Entity> entities, StringBuilder collisionData)
        {
            var result = new Dictionary<String, Int32>();
            result["Orphan"] = 0;
            result["Deleted"] = 0;
            // Create a new EntityProvider instance and pass the api created above.
            EntityProvider entityProvider = new EntityProvider(_helper.Api);
            foreach ( var entity in entities )
            {
                // Get an entity by searching for the id
                var item = _helper.GetWikiDataItemForEntity(entity);
                if ( item != null )
                {
                    var links = item.getSitelinks();
                    if ( !links.Any() )
                    {
                        result["Orphan"]++;
                        if ( collisionData != null )
                        {
                            collisionData.AppendFormat("Orphan: {0} - {1} ({2})", entity.wiki.wikidata, entity.english, entity.geocode);
                            collisionData.AppendLine();
                        }
                    }

                    foreach ( var key in links.Keys )
                    {
                        if ( !result.ContainsKey(key) )
                        {
                            result[key] = 0;
                        }
                        result[key]++;
                    }
                }
                else
                {
                    result["Deleted"]++;
                    if ( collisionData != null )
                    {
                        collisionData.AppendFormat("Deleted: {0} - {1} ({2})", entity.wiki.wikidata, entity.english, entity.geocode);
                        collisionData.AppendLine();
                    }
                }
            }
            return result;
        }