当前位置: 首页>>代码示例>>C#>>正文


C# Language.ToCode方法代码示例

本文整理汇总了C#中System.Language.ToCode方法的典型用法代码示例。如果您正苦于以下问题:C# Language.ToCode方法的具体用法?C# Language.ToCode怎么用?C# Language.ToCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Language的用法示例。


在下文中一共展示了Language.ToCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetDescription

        private void SetDescription(Language language, IEnumerable<Entity> entities, StringBuilder collisionInfo, Boolean overrideData)
        {
            if ( entities == null )
            {
                throw new ArgumentNullException("entities");
            }
            var languageCode = language.ToCode();
            ClearRunInfo();

            foreach ( var entity in entities )
            {
                var item = _helper.GetWikiDataItemForEntity(entity);
                if ( item == null )
                {
                    _runInfo[WikiDataState.ItemNotFound]++;
                    collisionInfo.AppendFormat("{0}: {1} was deleted!", entity.wiki.wikidata, entity.english);
                }
                else
                {
                    var oldDescription = item.getDescription(languageCode);
                    var newDescription = entity.GetWikiDataDescription(language);

                    if ( String.IsNullOrEmpty(oldDescription) )
                    {
                        _runInfo[WikiDataState.NotSet]++;
                        item.setDescription(languageCode, newDescription);
                        item.save(String.Format("Added description [{0}]: {1}", languageCode, newDescription));
                    }
                    else if ( oldDescription != newDescription )
                    {
                        _runInfo[WikiDataState.WrongValue]++;
                        if ( collisionInfo != null )
                        {
                            collisionInfo.AppendFormat("{0}: {1} already has description [{2}] \"{3}\"", item.id, entity.english, languageCode, oldDescription);
                            collisionInfo.AppendLine();
                        }
                        if ( overrideData )
                        {
                            item.setDescription(languageCode, newDescription);
                            item.save(String.Format("Updated description [{0}]: {1}", languageCode, newDescription));
                        }
                    }
                    else
                    {
                        _runInfo[WikiDataState.Valid]++;
                    }
                }
            }
        }
开发者ID:yieldret,项目名称:tambon,代码行数:49,代码来源:WikiDataBot.cs

示例2: SetLabel

        private void SetLabel(Language language, IEnumerable<Entity> entities, StringBuilder collisionInfo, Boolean overrideData)
        {
            if ( entities == null )
            {
                throw new ArgumentNullException("entities");
            }
            var languageCode = language.ToCode();
            ClearRunInfo();

            foreach ( var entity in entities )
            {
                var item = _helper.GetWikiDataItemForEntity(entity);
                if ( item == null )
                {
                    _runInfo[WikiDataState.ItemNotFound]++;
                    collisionInfo.AppendFormat("{0}: {1} was deleted!", entity.wiki.wikidata, entity.english);
                }
                else
                {
                    var oldLabel = item.getLabel(languageCode);
                    String newLabel;
                    if ( language == Language.Thai )
                    {
                        newLabel = entity.FullName;
                    }
                    else
                    {
                        if ( entity.type == EntityType.Chumchon )
                        {
                            newLabel = entity.english.StripBanOrChumchon();
                        }
                        else
                        {
                            newLabel = entity.english;
                        }
                    }

                    if ( String.IsNullOrEmpty(oldLabel) )
                    {
                        _runInfo[WikiDataState.NotSet]++;
                        item.setLabel(languageCode, newLabel);
                        item.save(String.Format("Added label [{0}]: {1}", languageCode, newLabel));
                    }
                    else if ( oldLabel != newLabel )
                    {
                        _runInfo[WikiDataState.WrongValue]++;
                        if ( collisionInfo != null )
                        {
                            collisionInfo.AppendFormat("{0}: {1} already has label [{2}] \"{3}\"", item.id, entity.english, languageCode, oldLabel);
                            collisionInfo.AppendLine();
                        }
                        if ( overrideData )
                        {
                            item.setLabel(languageCode, newLabel);
                            item.save(String.Format("Updated label [{0}]: {1}", languageCode, newLabel));
                        }
                    }
                    else
                    {
                        _runInfo[WikiDataState.Valid]++;
                    }
                }
            }
        }
开发者ID:yieldret,项目名称:tambon,代码行数:64,代码来源:WikiDataBot.cs

示例3: CheckMonoLanguageValue

        private WikiDataState CheckMonoLanguageValue(Item item, String propertyId, Language language, String expectedValue, Boolean createStatement, out Statement statement)
        {
            if ( item == null )
                throw new ArgumentNullException("item");

            WikiDataState result = WikiDataState.Unknown;

            if ( String.IsNullOrEmpty(expectedValue) )
            {
                statement = null;
                return result;  // TODO better handling!
            }
            var languageCode = language.ToCode();
            var dataValue = new MonolingualTextValue(expectedValue, languageCode);
            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 MonolingualTextValue;
                if ( (oldDataValue.Text == dataValue.Text) && (oldDataValue.Language == dataValue.Language) )
                {
                    foundStatement = claim as Statement;
                    result = WikiDataState.Valid;
                }
            }

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

            statement = foundStatement;
            return result;
        }
开发者ID:PaulCharlton,项目名称:tambon,代码行数:48,代码来源:WikiDataHelper.cs


注:本文中的System.Language.ToCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。