public async Task FetchEntityTest1() { var site = await WikidataSiteAsync; var entity = new Entity(site, WikidataItems.Chumulangma); await entity.RefreshAsync(EntityQueryOptions.FetchAllProperties); ShallowTrace(entity); ShallowTrace(entity.Claims, 4); Assert.Equal(WikidataItems.Chumulangma, entity.Title); Assert.Equal(WikidataItems.Chumulangma, entity.Id); Assert.Equal(EntityType.Item, entity.Type); Assert.Equal("Mount Everest", entity.Labels["en"]); Assert.Contains("Qomolangma", entity.Aliases["en"]); Assert.Equal("珠穆朗玛峰", entity.Labels["zh-Hans"]); Assert.Equal("珠穆朗瑪峰", entity.Labels["lzh"]); Assert.Equal("エベレスト", entity.Labels["ja"]); var claim = entity.Claims[WikidataProperties.CommonsCategory].First(); Assert.Equal(BuiltInDataTypes.String, claim.MainSnak.DataType); Assert.Equal(SnakType.Value, claim.MainSnak.SnakType); Assert.Equal("Mount Everest", claim.MainSnak.DataValue); // Now it belongs to "Seven Summits" //var parts = entity.Claims[WikidataProperties.PartOf].Select(c => c.MainSnak.DataValue).ToArray(); //Assert.Contains(WikidataItems.Earth, parts); //Assert.Contains(WikidataItems.Asia, parts); claim = entity.Claims[WikidataProperties.CoordinateLocation].First(); var location = (WbGlobeCoordinate)claim.MainSnak.DataValue; Assert.Equal(27.988055555556, location.Latitude, 12); Assert.Equal(86.925277777778, location.Longitude, 12); claim = entity.Claims[WikidataProperties.ElevationAboveSeaLevel].First(); var height = (WbQuantity)claim.MainSnak.DataValue; Assert.Equal(8848, height.Amount, 4); Assert.Equal(WikidataProperties.ReferenceUrl, claim.References[0].Snaks[0].PropertyId); Assert.Equal("https://www.peakware.com/peaks.php?pk=80", claim.References[0].Snaks[0].DataValue); var topiso = (WbQuantity)entity.Claims[WikidataProperties.TopographicIsolation] .First().MainSnak.DataValue; Assert.Equal(40008, topiso.Amount, 12); Assert.Equal(WikibaseUriFactory.Get(WikidataEntityUriPrefix + WikidataItems.KiloMeter), topiso.Unit); }
private Uri MapEntityUri(Uri uri, bool optional) { if (EntityMapping == null) { return(uri); } // For quantities without units if (uri == WbQuantity.Unity) { return(uri); } var sourceId = sourceSiteWikibaseInfo.ParseEntityId(uri.ToString()); var mapped = (string)EntityMapping[sourceId]; if (mapped != null) { return(WikibaseUriFactory.Get(destinationSiteWikibaseInfo.MakeEntityUri(mapped))); } if (!optional) { throw new KeyNotFoundException($"Cannot find mapped entity for {uri}."); } return(null); }