public void TestCreateEntityIndex5k() { const string filename = "Resources/EntityIndex5k.nt"; const string outputPath = "CreateEntityIndex5k"; outputPath.DeleteIfExists(); Assert.False(Directory.Exists(outputPath)); new EntitiesIndexer(filename, outputPath).Index(); Assert.True(Directory.Exists(outputPath)); var queryBerlin = new SingleLabelEntityQuery(outputPath, "Berli").Query().ToArray(); Assert.NotEmpty(queryBerlin); var result = queryBerlin[0]; Assert.Equal("Q64", result.Id); Assert.Equal("Berlin", result.Label); Assert.Equal("capital city of Germany", result.Description); Assert.Contains("Berlin, Germany", result.AltLabels); var properties = result.Properties.Select(x => x.Id).ToArray(); Assert.Contains("P17", properties); Assert.Contains("P1376", properties); Assert.False(result.IsType); Assert.Contains("Q515", result.ParentTypes); Assert.Contains("Q5119", result.ParentTypes); //Assert.Contains("Q999", result.SubClass); outputPath.DeleteIfExists(); }
public void TestQueryNonExistingEntityByLabel() { const string indexPath = "Resources/IndexSingle"; var actual = new SingleLabelEntityQuery(indexPath, "Non-Existing").Query(); Assert.Empty(actual); }
public void TestSingleQuery_MichelleObama_ShouldShowFirst() { const string filename = "Resources/QuerySingle.nt"; const string outputPath = "QuerySingleIndexMichelle"; outputPath.DeleteIfExists(); new EntitiesIndexer(filename, outputPath).Index(); var entity = new SingleLabelEntityQuery(outputPath, "Michelle Obama").Query().FirstOrDefault(); Debug.Assert(entity != null, nameof(entity) + " != null"); Assert.Equal("Q13133", entity.Id); outputPath.DeleteIfExists(); }
public void TestQuerySingleInstanceByLabel() { const string indexPath = "Resources/IndexSingle"; var entity = new SingleLabelEntityQuery(indexPath, "Northern Ireland").Query().FirstOrDefault(); Assert.NotNull(entity); Assert.Equal("Q26", entity.Id); entity = new SingleLabelEntityQuery(indexPath, "Ireland").Query().FirstOrDefault(); Assert.NotNull(entity); Assert.Equal("Q26", entity.Id); entity = new SingleLabelEntityQuery(indexPath, "Northern").Query().FirstOrDefault(); Assert.NotNull(entity); Assert.Equal("Q26", entity.Id); entity = new SingleLabelEntityQuery(indexPath, "north").Query().FirstOrDefault(); Assert.NotNull(entity); Assert.Equal("Q26", entity.Id); }
public static void TestMapEntitySingleInstance() { const string filename = "Resources/EntityIndexSingleInstance-Map.nt"; const string outputPath = "Resources/IndexSingleMapping"; outputPath.DeleteIfExists(); new EntitiesIndexer(filename, outputPath).Index(); var expected = new Entity { Id = "Q26", Label = "Northern Ireland", Description = "region in north-west Europe, part of the United Kingdom", AltLabels = new List <string> { "NIR", "UKN", "North Ireland" }, ParentTypes = new List <string> { "Q100" }, //SubClass = new List<string> //{ // "Q46" //}, Properties = new List <Property> { new Property { Id = "P17", Value = "Q145" }, new Property { Id = "P47", Value = "Q27" }, new Property { Id = "P279", }, new Property { Id = "P131", Value = "Q145" }, new Property { Id = "P31", }, } }; var actual = new SingleLabelEntityQuery(outputPath, expected.Label).Query().FirstOrDefault(); //var actual = SingleDocumentQueries.QueryEntityByLabel(expected.Label, luceneDirectory); Assert.NotNull(actual); //Id Assert.Equal(expected.Id, actual.Id); //Label Assert.Equal(expected.Label, actual.Label); //InstanceOf Assert.Equal(expected.ParentTypes.Count, actual.ParentTypes.Count); Assert.Equal(expected.ParentTypes.FirstOrDefault(), actual.ParentTypes.FirstOrDefault()); //SubClass //Assert.Equal(expected.SubClass.Count, actual.SubClass.Count); //Assert.Equal(expected.SubClass.FirstOrDefault(), actual.SubClass.FirstOrDefault()); //IsType Assert.False(actual.IsType); //Rank Assert.Equal(1, actual.Rank); //Alt-Label: Assert.Equal(expected.AltLabels.Count(), actual.AltLabels.Count()); Assert.Equal(expected.AltLabels.ElementAt(0), actual.AltLabels.ElementAt(0)); Assert.Equal(expected.AltLabels.ElementAt(1), actual.AltLabels.ElementAt(1)); Assert.Equal(expected.AltLabels.ElementAt(2), actual.AltLabels.ElementAt(2)); //Description Assert.Equal(expected.Description, actual.Description); //Properties Assert.Equal(expected.Properties.Count(), actual.Properties.Count()); Assert.Equal(expected.Properties.ElementAt(0).Id, actual.Properties.ElementAt(0).Id); Assert.Equal(expected.Properties.ElementAt(1).Id, actual.Properties.ElementAt(1).Id); Assert.Equal(expected.Properties.ElementAt(2).Id, actual.Properties.ElementAt(2).Id); }
public static void TestMapEntityTwoInstances() { const string filename = "Resources/EntityIndexTwoInstanceOfWithTypes-Map.nt"; const string outputPath = "Resources/IndexTwoInstanceMapping"; outputPath.DeleteIfExists(); var expected1 = new Entity { Id = "Q26", Label = "Northern Ireland", Description = "region in north-west Europe, part of the United Kingdom", AltLabels = new List <string> { "NIR", "UKN", "North Ireland" }, ParentTypes = new List <string> { "Q27", "Q145" }, //SubClass = new List<string> //{ // "Q46", // "Q47" //}, Properties = new List <Property> { new Property { Id = "P17", Value = "Q145" }, new Property { Id = "P47", Value = "Q27" }, new Property { Id = "P131", Value = "Q145" }, new Property { Id = "P279", }, new Property { Id = "P31", }, } }; var expected2 = new Entity { Id = "Q145", Label = "Base1", Description = "Base Type1" }; var expected3 = new Entity { Id = "Q27", Label = "Base2", Description = "Base Type2" }; new EntitiesIndexer(filename, outputPath).Index(); var actual = new SingleLabelEntityQuery(outputPath, expected1.Label).Query().FirstOrDefault(); { //Expected 1: Id, Label, InstanceOf, SubClass, Rank, IsType, Alt-Label, Description, Properties Assert.NotNull(actual); Assert.Equal(expected1.Id, actual.Id); Assert.Equal(expected1.Label, actual.Label); Assert.Equal(expected1.Description, actual.Description); Assert.Equal(expected1.ParentTypes.Count, actual.ParentTypes.Count); Assert.Equal(expected1.ParentTypes.FirstOrDefault(), actual.ParentTypes.FirstOrDefault()); //Assert.Equal(expected1.SubClass.Count, actual.SubClass.Count); //Assert.Equal(expected1.SubClass.FirstOrDefault(), actual.SubClass.FirstOrDefault()); Assert.False(actual.IsType); Assert.Equal(0.333, actual.Rank.ToThreeDecimals()); Assert.Equal(expected1.AltLabels.Count(), actual.AltLabels.Count()); Assert.Equal(expected1.AltLabels.ElementAt(0), actual.AltLabels.ElementAt(0)); Assert.Equal(expected1.AltLabels.ElementAt(1), actual.AltLabels.ElementAt(1)); Assert.Equal(expected1.AltLabels.ElementAt(2), actual.AltLabels.ElementAt(2)); Assert.Equal(expected1.Properties.Count(), actual.Properties.Count()); Assert.Equal(expected1.Properties.ElementAt(0).Id, actual.Properties.ElementAt(0).Id); Assert.Equal(expected1.Properties.ElementAt(1).Id, actual.Properties.ElementAt(1).Id); Assert.Equal(expected1.Properties.ElementAt(2).Id, actual.Properties.ElementAt(2).Id); //Expected 2: Id, Label actual = new SingleLabelEntityQuery(outputPath, expected2.Label).Query().FirstOrDefault(); Assert.NotNull(actual); Assert.Equal(expected2.Id, actual.Id); Assert.True(actual.IsType); Assert.Equal(0.333, actual.Rank.ToThreeDecimals()); Assert.Equal(expected2.Label, actual.Label); //Expected 3: Id, Label actual = new SingleLabelEntityQuery(outputPath, expected3.Label).Query().FirstOrDefault(); Assert.NotNull(actual); Assert.Equal(expected3.Id, actual.Id); Assert.True(actual.IsType); Assert.Equal(0.333, actual.Rank.ToThreeDecimals()); Assert.Equal(expected3.Label, actual.Label); } }