public void TestIndexWithDifferentIdsHasCorrectRankingFields()
        {
            const string filename   = "Resources/EntityIndexPageRankDifferentIds.nt";
            const string outputPath = "IndexWithDifferentIdsHasCorrectRankingFields";

            var nodesGraph = EntityPageRank.BuildSimpleNodesGraph(filename);

            var ranks = EntityPageRank.CalculateRanks(nodesGraph, 20);

            Assert.Equal(1, Math.Round(ranks.Sum()), 10);

            outputPath.DeleteIfExists();

            Assert.False(Directory.Exists(outputPath));

            new EntitiesIndexer(filename, outputPath).Index();
            using (var luceneDirectory = FSDirectory.Open(outputPath.GetOrCreateDirectory())) {
                using (var reader = DirectoryReader.Open(luceneDirectory)) {
                    Assert.True(Directory.Exists(outputPath));

                    var docCount = reader.MaxDoc;

                    Assert.Equal(7, docCount);

                    for (var i = 0; i < docCount; i++)
                    {
                        var doc = reader.Document(i);
                        double.TryParse(doc.GetValue(Labels.Rank), out var rank);
                        Assert.Equal(ranks[i].ToThreeDecimals(), rank.ToThreeDecimals());
                    }
                }
            }

            outputPath.DeleteIfExists();
        }
Пример #2
0
        public void TestCalculateFloatRankOneIteration()
        {
            const string filename   = "Resources/PageRankBuildGraph-Floats.nt";
            var          nodesGraph = EntityPageRank.BuildSimpleNodesGraph(filename);

            var ranks = EntityPageRank.CalculateRanks(nodesGraph, 1);

            Assert.Equal(1, Math.Round(ranks.Sum()), 10);

            Assert.Equal(0.119, ranks[0].ToThreeDecimals());
            Assert.Equal(0.119, ranks[1].ToThreeDecimals());
            Assert.Equal(0.059, ranks[2].ToThreeDecimals());
            Assert.Equal(0.160, ranks[3].ToThreeDecimals());
            Assert.Equal(0.160, ranks[4].ToThreeDecimals());
            Assert.Equal(0.220, ranks[5].ToThreeDecimals());
            Assert.Equal(0.160, ranks[6].ToThreeDecimals());
        }
Пример #3
0
        public void TestCalculateFloatRankSevenIterationsMultipleProperties()
        {
            const string filename   = "Resources/PageRankBuildGraphMultipleProperties.nt";
            var          nodesGraph = EntityPageRank.BuildSimpleNodesGraph(filename);

            var ranks = EntityPageRank.CalculateRanks(nodesGraph, 7);

            Assert.Equal(1, Math.Round(ranks.Sum()), 10);

            Assert.Equal(0.138, ranks[0].ToThreeDecimals());
            Assert.Equal(0.087, ranks[1].ToThreeDecimals());
            Assert.Equal(0.061, ranks[2].ToThreeDecimals());
            Assert.Equal(0.180, ranks[3].ToThreeDecimals());
            Assert.Equal(0.128, ranks[4].ToThreeDecimals());
            Assert.Equal(0.222, ranks[5].ToThreeDecimals());
            Assert.Equal(0.180, ranks[6].ToThreeDecimals());
        }
Пример #4
0
        public void TestBuildNodeArrayGraph()
        {
            const string filename      = "Resources/PageRankBuildGraph.nt";
            var          lines         = FileHelper.GetInputLines(filename);
            var          groups        = lines.GroupBySubject();
            var          entitiesCount = groups.Count();

            var nodesGraph = EntityPageRank.BuildSimpleNodesGraph(filename);

            Assert.Equal(entitiesCount, nodesGraph.Count());
            Assert.Equal(2, nodesGraph[0].Length);
            Assert.Equal(3, nodesGraph[1].Length);
            Assert.Equal(2, nodesGraph[2].Length);
            Assert.Equal(2, nodesGraph[3].Length);
            Assert.Equal(6, nodesGraph[4].Length);
            Assert.Equal(2, nodesGraph[5].Length);
            Assert.Empty(nodesGraph[6]);
        }