Beispiel #1
0
        private void SetPopulationData(IEnumerable <Entity> entities, StringBuilder collisionInfo, Boolean overrideData, PopulationDataSourceType dataSource, Int16 year)
        {
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }
            ClearRunInfo();
            GlobalData.LoadPopulationData(dataSource, year);
            foreach (var entity in entities.Where(x => x.population.Any(y => y.source == dataSource && y.Year == year)))
            {
                var item = _helper.GetWikiDataItemForEntity(entity);
                if (item == null)
                {
                    _runInfo[WikiDataState.ItemNotFound]++;
                    collisionInfo.AppendFormat("{0}: {1} was deleted!", entity.wiki.wikidata, entity.english);
                }
                else
                {
                    var data = entity.population.First(y => y.source == dataSource && y.Year == year);

                    var state = _helper.PopulationDataCorrect(item, data);
                    _runInfo[state]++;
                    if (state != WikiDataState.Valid)
                    {
                        var statement = _helper.SetPopulationData(item, data, overrideData);
                        if (statement != null)
                        {
                            statement.save(_helper.GetClaimSaveEditSummary(statement));
                            _helper.AddPopulationDataReferences(statement, data, entity);
                            foreach (var reference in statement.References)
                            {
                                reference.Save(_helper.GetReferenceSaveEditSummary(reference));
                            }

                            _helper.AddPopulationDataQualifiers(statement, data);
                            foreach (var qualifier in statement.Qualifiers)
                            {
                                qualifier.Save(_helper.GetQualifierSaveEditSummary(qualifier));
                            }
                        }
                    }
                }
            }
        }