Exemple #1
0
        public static AcademicSearchClient CreateSearchClient()
        {
            var client = GlobalServices.CreateASClient();

            client.PagingSize            = Configurations.ASClientPagingSize;
            client.ConcurrentPagingCount = Configurations.ASClientConcurrentPagingCount;
            return(client);
        }
        public void ASClientTestMethod2()
        {
            var client = GlobalServices.CreateASClient();
            var result = TestUtility.AwaitSync(
                client.EvaluateAsync("Composite(AA.AuN=='meredith ringel morris')", 10, 0,
                                     GlobalServices.DebugASEvaluationAttributes));

            Assert.IsTrue(result.Entities.Any());
            DumpEvaluationResult(result);
        }
        public void ASClientTestMethod4EstimateCount()
        {
            const int maxCount = 100000;
            var       client   = GlobalServices.CreateASClient();
            var       est      = TestUtility.AwaitSync(client.EstimateEvaluationCountAsync(
                                                           "Composite(AA.AfN=='microsoft')", maxCount, 0.01f));

            Trace.WriteLine($"{est} Entities.");
            Assert.IsTrue(est <= maxCount);
            Assert.IsTrue(est >= 23200);
        }
Exemple #4
0
        private IReadOnlyCollection <KgNode[]> FindPaths(long id1, long id2, bool assertPathExists)
        {
            var asc   = GlobalServices.CreateASClient();
            var a     = new Analyzer(asc);
            var paths = TestUtility.AwaitSync(a.FindPathsAsync(id1, id2));

            Trace.WriteLine(a.DumpStatistics());
            Trace.WriteLine(asc.DumpStatistics());
            //a.TraceGraph();
            var hop1Count = paths.Count(p => p.Length == 2);
            var hop2Count = paths.Count(p => p.Length == 3);
            var hop3Count = paths.Count(p => p.Length == 4);

            Trace.WriteLine($"路径 {id1} -> {id2} [{hop1Count} + {hop2Count} + {hop3Count} = {paths.Count}]");
            Trace.Indent();
            foreach (var p in paths)
            {
                Trace.WriteLine(string.Join("\n\t->", (IEnumerable <KgNode>)p));
            }
            Trace.Unindent();
            if (assertPathExists)
            {
                Assert.AreNotEqual(0, paths.Count);
            }
            foreach (var p in paths)
            {
                Assert.IsTrue(p.Length >= 2); // >= 1-hop
                Assert.IsTrue(p.Length <= 4); // <= 3-hop
                Assert.AreEqual(id1, p[0].Id);
                Assert.AreEqual(id2, p[p.Length - 1].Id);
            }
            TraceAsJson(paths);
#if CACHE_TEST_ENABLED
            var sw     = Stopwatch.StartNew();
            var paths2 = TestUtility.AwaitSync(a.FindPathsAsync(id1, id2));
            sw.Stop();
            Trace.WriteLine("Cached: " + sw.Elapsed);
            try
            {
                Assert.AreEqual(paths.Count, paths2.Count);
                Assert.IsTrue(paths.SequenceEqual(paths2, ArrayEqualityComparer <KgNode> .Default));
                Trace.WriteLine(a.DumpStatistics());
                Trace.WriteLine(asc.DumpStatistics());
            }
            catch (Exception)
            {
                Trace.WriteLine("========================");
                TraceAsJson(paths2);
                throw;
            }
#endif
            return(paths);
        }
        public void ASClientTestMethod3()
        {
            var client = GlobalServices.CreateASClient();
            var result = new List <EvaluationResult>();

            client.EvaluateAsync("Composite(AA.AfN=='microsoft')", 5000, null, "Id",
                                 er =>
            {
                result.Add(er);
                return(Task.CompletedTask);
            }).Wait();
            Assert.IsTrue(result.Any());
            Trace.WriteLine($"{result.Count} Entities.");
            foreach (var entity in result)
            {
                Trace.WriteLine(entity);
            }
        }
        public void ASClientTestMethod5()
        {
            const int queryCount = 100;
            var       client     = GlobalServices.CreateASClient();
            var       result     = TestUtility.AwaitSync(client.CalcHistogramAsync(
                                                             "Composite(AA.AuN=='jaime teevan')", queryCount, 0, "AA.AfN"));

            DumpCalcHistogram(result);
            //if (result.Aborted) Assert.Inconclusive("查询被取消。");
            Assert.AreEqual(result.Histograms.Count, 1);
            Assert.AreEqual(result.Histograms[0].Attribute, "AA.AfN");
            Assert.IsTrue(result.EntityCount >= result.Histograms[0].EntryCount);
            if (result.Histograms[0].EntryCount > queryCount)
            {
                Assert.Inconclusive("返回直方图的分类太多。");
            }
            Assert.AreEqual(result.Histograms[0].EntityCount, result.Histograms[0].Entries.Sum(e => e.Count));
        }
        public void ASClientTestMethod6()
        {
            var client = GlobalServices.CreateASClient();

            client.PagingSize = 20;
            var result = new List <CalcHistogramResult>();

            // 注意:我们得到的其实是 co-author affiliations
            client.CalcHistogramAsync("Composite(AA.AuN=='jaime teevan')", "AA.AfN")
            .PartitionContinueWith(hr =>
            {
                result.Add(hr);
                return(Task.CompletedTask);
            }).WhenCompleted().Wait();
            foreach (var hr in result)
            {
                Trace.WriteLine(" ============= PAGE =============");
                DumpCalcHistogram(hr);
            }
            Assert.IsTrue(result.Sum(r => r.EntityCount) >= result.Sum(r => r.Histograms[0].EntryCount));
            Assert.AreEqual(result[0].Histograms[0].EntityCount,
                            result.Sum(hr => hr.Histograms[0].Entries.Sum(e => e.Count)));
        }