Example #1
0
        /// <summary>
        /// Checks and evetually sets a link property.
        /// </summary>
        /// <param name="item">Wikidata item.</param>
        /// <param name="propertyId">Id of the property.</param>
        /// <param name="expectedItemId">Expected item id.</param>
        /// <param name="createStatement"><c>true</c> to create the statement if not existing yet.</param>
        /// <param name="overrideWrongData"><c>true</c> to overwrite wrong data.</param>
        /// <param name="statement">Newly created statement.</param>
        /// <returns>Status of the link property.</returns>
        public WikiDataState CheckPropertyValue(Item item, String propertyId, String expectedItemId, Boolean createStatement, Boolean overrideWrongData, out Statement statement)
        {
            if ( item == null )
                throw new ArgumentNullException("item");

            WikiDataState result = WikiDataState.Unknown;

            // Statement claim = item.Claims.FirstOrDefault(x => x.IsAboutProperty(WikiBase.PropertyIdCountry)) as Statement;
            var property = new EntityId(propertyId);
            Statement claim = item.Claims.FirstOrDefault(x => property.Equals(x.mainSnak.PropertyId)) as Statement;

            var entity = new EntityId(expectedItemId);
            var dataValue = new EntityIdValue(entity);

            var snak = new Snak(SnakType.Value, new EntityId(propertyId), dataValue);
            if ( claim == null )
            {
                if ( String.IsNullOrEmpty(expectedItemId) )
                {
                    result = WikiDataState.Valid;
                }
                else
                {
                    result = WikiDataState.NotSet;
                    if ( createStatement )
                    {
                        claim = item.createStatementForSnak(snak);
                    }
                }
            }
            else
            {
                Snak oldSnak = claim.mainSnak;
                var oldDataValue = oldSnak.DataValue as EntityIdValue;
                if ( oldDataValue.NumericId == dataValue.NumericId )
                {
                    result = WikiDataState.Valid;
                }
                else
                {
                    if ( !String.IsNullOrEmpty(expectedItemId) )
                    {
                        result = WikiDataState.WrongValue;
                        if ( overrideWrongData )
                        {
                            claim.mainSnak = snak;
                        }
                    }
                    else
                    {
                        result = WikiDataState.DataMissing;
                    }
                }
            }

            statement = claim as Statement;
            return result;
        }
Example #2
0
        public void AddCategoryCombinesTopic(Item item, Entity entity, EntityType entityType)
        {
            if ( !item.Claims.Any(x => x.IsAboutProperty(WikiBase.PropertyIdCategoryCombinesTopic)) )
            {
                var dataValue1 = new EntityIdValue(new EntityId(WikiBase.WikiDataItems[entityType]));
                var snak1 = new Snak(SnakType.Value, new EntityId(WikiBase.PropertyIdCategoryCombinesTopic), dataValue1);
                var claim1 = item.createStatementForSnak(snak1);
                claim1.save(GetClaimSaveEditSummary(claim1));

                var dataValue2 = new EntityIdValue(new EntityId(entity.wiki.wikidata));
                var snak2 = new Snak(SnakType.Value, new EntityId(WikiBase.PropertyIdCategoryCombinesTopic), dataValue2);
                var claim2 = item.createStatementForSnak(snak2);
                claim2.save(GetClaimSaveEditSummary(claim2));
            }
        }
Example #3
0
        public void AddCategoryListOf(Item item, Entity entity, EntityType entityType)
        {
            if ( !item.Claims.Any(x => x.IsAboutProperty(WikiBase.PropertyIdIsListOf)) )
            {
                var dataValue = new EntityIdValue(new EntityId(WikiBase.WikiDataItems[entityType]));
                var snak = new Snak(SnakType.Value, new EntityId(WikiBase.PropertyIdIsListOf), dataValue);
                var claim = item.createStatementForSnak(snak);
                claim.save(GetClaimSaveEditSummary(claim));

                var dataValue2 = new EntityIdValue(new EntityId(entity.wiki.wikidata));
                var qualifier = new Qualifier(claim, SnakType.Value, new EntityId(WikiBase.PropertyIdIsInAdministrativeUnit), dataValue2);
                qualifier.Save(GetQualifierSaveEditSummary(qualifier));
            }
        }
Example #4
0
        private WikiDataState CheckPropertyMultiValue(Item item, String propertyId, String expectedItemId, Boolean createStatement, out Statement statement)
        {
            if ( item == null )
                throw new ArgumentNullException("item");

            WikiDataState result = WikiDataState.Unknown;

            if ( String.IsNullOrEmpty(expectedItemId) )
            {
                statement = null;
                return result;  // TODO better handling!
            }
            var entity = new EntityId(expectedItemId);
            var dataValue = new EntityIdValue(entity);
            var snak = new Snak(SnakType.Value, new EntityId(propertyId), dataValue);

            var property = new EntityId(propertyId);
            Statement foundStatement = null;
            foreach ( var claim in item.Claims.Where(x => property.Equals(x.mainSnak.PropertyId)) )
            {
                Snak oldSnak = claim.mainSnak;
                var oldDataValue = oldSnak.DataValue as EntityIdValue;
                if ( oldDataValue.NumericId == dataValue.NumericId )
                {
                    foundStatement = claim as Statement;
                    result = WikiDataState.Valid;
                }
            }

            if ( foundStatement == null )
            {
                if ( String.IsNullOrEmpty(expectedItemId) )
                {
                    result = WikiDataState.Valid;
                }
                else
                {
                    result = WikiDataState.Incomplete;
                    if ( createStatement )
                    {
                        foundStatement = item.createStatementForSnak(snak);
                    }
                }
            }

            statement = foundStatement;
            return result;
        }