本文整理汇总了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]++;
}
}
}
}
示例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]++;
}
}
}
}
示例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;
}