WikiCrawler/Tasks/Commons/CommonsCreatorFromWikidata.cs
/// <summary>
/// Searches for a wikidata entity matching the specified info.
/// </summary>
/// <param name="name"></param>
/// <param name="yob"></param>
/// <param name="yod"></param>
Searches for a wikidata entity matching the specified info.
Searches for a wikidata entity matching the specified info .
private static string GetWikidataId(string name, string yearOfBirth, string yearOfDeath)
		{
			string[] search = Wikidata.SearchEntities(name);
			foreach (string result in search)
			{
				Entity entity = Wikidata.GetEntity(result);
				if (!entity.HasClaim(MediaWiki.Wikidata.Prop_DateOfBirth)
					|| entity.GetClaimValueAsDate(MediaWiki.Wikidata.Prop_DateOfBirth).GetYear().ToString() != yearOfBirth)
				{
					continue;
				}
				if (!entity.HasClaim(MediaWiki.Wikidata.Prop_DateOfDeath)
					|| entity.GetClaimValueAsDate(MediaWiki.Wikidata.Prop_DateOfDeath).GetYear().ToString() != yearOfDeath)
				{
					continue;
				}
				foreach (string label in entity.labels.Values)
				{
					if (label == name)
					{
						return result;
					}
				}
				foreach (string[] labels in entity.aliases.Values)
				{
					foreach (string label in labels)
					{
						if (label == name)
						{
							return result;
						}
					}
				}
			}
			return "";
		}
private static string GetWikidataId ( string name , string yearOfBirth , string yearOfDeath ) { string [ ] search = Wikidata . SearchEntities ( name ) ; foreach ( string result in search ) { Entity entity = Wikidata . GetEntity ( result ) ; if ( ! entity . HasClaim ( MediaWiki . Wikidata . Prop_DateOfBirth ) || entity . GetClaimValueAsDate ( MediaWiki . Wikidata . Prop_DateOfBirth ) . GetYear ( ) . ToString ( ) != yearOfBirth ) { continue ; } if ( ! entity . HasClaim ( MediaWiki . Wikidata . Prop_DateOfDeath ) || entity . GetClaimValueAsDate ( MediaWiki . Wikidata . Prop_DateOfDeath ) . GetYear ( ) . ToString ( ) != yearOfDeath ) { continue ; } foreach ( string label in entity . labels . Values ) { if ( label == name ) { return result ; } } foreach ( string [ ] labels in entity . aliases . Values ) { foreach ( string label in labels ) { if ( label == name ) { return result ; } } } } return " " ; }
Searches for a wikidata entity matching the specified info.
Searches for a wikidata entity matching the specified info .
// search wikidata
name
string
None
yearOfBirth
string
yearOfDeath
string
yob
None
yod
None