public static void TestCreateIndexAddTypesFields() { const string filename = "Resources/EntityIndexTypes.nt"; const string outputPath = "CreateIndexAddTypesFields"; outputPath.DeleteIfExists(); Assert.False(Directory.Exists(outputPath)); new EntitiesIndexer(filename, outputPath).Index(); var obama = new SingleIdEntityQuery(outputPath, "Q76").Query().FirstOrDefault(); var person = new SingleIdEntityQuery(outputPath, "Q5").Query().FirstOrDefault(); var country = new SingleIdEntityQuery(outputPath, "Q17").Query().FirstOrDefault(); var chile = new SingleIdEntityQuery(outputPath, "Q298").Query().FirstOrDefault(); Assert.Equal("Q76", obama.Id); Assert.Equal("Q5", person.Id); Assert.Equal("Q17", country.Id); Assert.Equal("Q298", chile.Id); Assert.False(obama.IsType); Assert.False(chile.IsType); Assert.True(person.IsType); Assert.True(country.IsType); outputPath.DeleteIfExists(); }
public void TestQueryNonExistingEntityById() { const string indexPath = "Resources/IndexSingle"; var actual = new SingleIdEntityQuery(indexPath, "Q666").Query(); Assert.Empty(actual); }
public void TestQuerySingleInstanceById() { const string indexPath = "Resources/IndexSingle"; var actual = new SingleIdEntityQuery(indexPath, "Q26").Query().FirstOrDefault(); Assert.NotNull(actual); Assert.Equal("Q26", actual.Id); }
public void TestScenario4GetPropertiesForKnownSubjectObjectType() { /* In this test, I will have two "nodes" connected. * "node1" is unknown type and has a property to "node2" * "node2" is InstanceOf (Human). * I want to display all the properties that have Range Human. * * As sample database I have the following: * Q76 (Obama) -> P31 (InstanceOf) -> Q5 (Human) * Q76 (Obama) -> P27 (CountryOfCitizenship) -> Q30 (USA) * Q76 (Obama) -> Pxx (Others) -> Qxx * * Q30 (USA) -> P31 (InstanceOf) -> Q6256 (Country) * Q30 (USA) -> Pyy (Others) -> Qyy * ... * Las propiedades que se deben mostrar que: * ``` * Q30: Domain P27 * Q5: Range P27 */ const string filename = @"Resources/QueryByRangeAndProperty.nt"; const string propertiesIndexPath = "QueryByRangeAndProperty"; const string entitiesIndexPath = "QueryByDomain-EntitiesIndex"; propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); //Act: new EntitiesIndexer(filename, entitiesIndexPath).Index(); new PropertiesIndexer(filename, propertiesIndexPath, entitiesIndexPath).Index(); var rangeProperties = new MultiRangePropertyQuery(propertiesIndexPath, "Q6256").Query(); var domainProperties = new MultiDomainPropertyQuery(propertiesIndexPath, "Q5").Query(); var properties = rangeProperties.Intersect(domainProperties, new PropertyComparer()).ToArray(); var entity = new SingleIdEntityQuery(entitiesIndexPath, "Q76").Query().ToList(); Assert.NotEmpty(properties); Assert.Equal(2, properties.Length); // P27, P31 Assert.Equal("P31", properties[0].Id); Assert.Equal("P27", properties[1].Id); Assert.NotEmpty(entity); Assert.Equal("P27", entity[0].Properties[0].Id); Assert.Equal("P31", entity[0].Properties[1].Id); propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); }
public void TestQueryAddProperties() { const string outputPath = "Resources/PropertyIndex"; Assert.True(Directory.Exists(outputPath)); var entity = new SingleIdEntityQuery(outputPath, "Q26").Query().FirstOrDefault(); Assert.NotNull(entity); Assert.Equal("Q26", entity.Id); //Properties Assert.Equal(4, entity.Properties.Count); Assert.Equal("P17", entity.Properties.ElementAt(0).Id); Assert.Equal(string.Empty, entity.Properties.ElementAt(0).Label); Assert.Equal("P47", entity.Properties.ElementAt(1).Id); Assert.Equal(string.Empty, entity.Properties.ElementAt(1).Label); Assert.Equal("P30", entity.Properties.ElementAt(2).Id); Assert.Equal(string.Empty, entity.Properties.ElementAt(2).Label); Assert.Equal("P131", entity.Properties.ElementAt(3).Id); Assert.Equal(string.Empty, entity.Properties.ElementAt(3).Label); entity.AddProperties(outputPath); Assert.Equal("P17", entity.Properties.ElementAt(0).Id); Assert.Equal("country", entity.Properties.ElementAt(0).Label); Assert.Equal("P47", entity.Properties.ElementAt(1).Id); Assert.Equal("shares border with", entity.Properties.ElementAt(1).Label); Assert.Equal("P30", entity.Properties.ElementAt(2).Id); Assert.Equal("continent", entity.Properties.ElementAt(2).Label); Assert.Equal("P131", entity.Properties.ElementAt(3).Id); Assert.Equal("located in the administrative territorial entity", entity.Properties.ElementAt(3).Label); }