public void TestAddDomainToIndex() { const string filename = @"Resources/PropertyDomain.nt"; const string propertiesIndexPath = "PropertyDomain-PropertyIndex"; const string entitiesIndexPath = "PropertyDomain-EntitiesIndex"; propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); //Act: new EntitiesIndexer(filename, entitiesIndexPath).Index(); new PropertiesIndexer(filename, propertiesIndexPath, entitiesIndexPath).Index(); var properties = new BatchIdPropertyQuery(propertiesIndexPath, new List <string> { "P27", "P555", "P777" }) .Query().ToArray(); //Assert: Assert.NotEmpty(properties); Assert.Equal(3, properties.Length); Assert.Equal("P555", properties[0].Id); Assert.Equal("P27", properties[1].Id); Assert.Equal("P777", properties[2].Id); var property555 = properties[0]; var property27 = properties[1]; var property777 = properties[2]; Assert.Equal("country of citinzenship", property27.Label); Assert.Equal("random property 555", property555.Label); Assert.Equal("random property 777", property777.Label); Assert.NotEmpty(property27.Domain); Assert.Equal(5, property27.Domain.ElementAt(0)); Assert.NotEmpty(property555.Domain); Assert.Equal(5, property555.Domain.ElementAt(0)); Assert.Equal(17, property555.Domain.ElementAt(1)); Assert.NotEmpty(property777.Domain); Assert.Equal(17, property777.Domain.ElementAt(0)); propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); }
public static void AddProperties(this List <Entity> entities, string indexPath) { var propertiesIds = entities.SelectMany(x => x.Properties).Select(x => x.Id).Distinct(); var properties = new BatchIdPropertyQuery(indexPath, propertiesIds).GetDocuments().ToPropertiesList(); foreach (var entity in entities) { foreach (var property in entity.Properties) { var prop = properties.FirstOrDefault(x => x.Id.Equals(property.Id)); if (prop == null) { continue; } property.Label = prop.Label; } } }