當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。