コード例 #1
0
        public async Task <IResponse> PopulateDatastore()
        {
            var resp      = new EnumerableResponse <dynamic>();
            var accessors = new Dictionary <string, string>();
            var r         = new List <LoadOntologyResponse>();

            Dictionary <string, Dictionary <string, string> > data = new Dictionary <string, Dictionary <string, string> >();

            try
            {
                var finalStatus = ResponseStatus.DataLoaded;
                var d           = _rdfSourceContext.All();
                foreach (var x in d)
                {
                    try
                    {
                        accessors[x.Accessor] = x.Label;
                        var graph = RdfHelper.GetGraphFromOntology(x);
                        var items = RdfHelper.GetFlatDataFromGraph(x.RootTypes, graph);

                        data[x.Accessor] = items;
                        r.Add(new LoadOntologyResponse(x.Location));
                    }
                    catch (Exception e)
                    {
                        r.Add(new LoadOntologyResponse(x.Location, ResponseStatus.Error, e));
                        finalStatus  = ResponseStatus.Error;
                        resp.Message = "One or more ontologies could not be loaded";
                    }
                }
                await _datastoreContext.Populate(accessors, data);

                resp.Status = finalStatus;
            }
            catch (Exception e)
            {
                resp.Status    = Enums.ResponseStatus.Error;
                resp.Exception = e;
            }
            resp.Data = r;
            return(resp);
        }
コード例 #2
0
        public void RdfHelper_GetLookupItems()
        {
            var expected = new Dictionary <string, string>()
            {
                { "http://www.stew.test.uk/ontologytypeaheadapi/this", "This Label" },
                { "http://www.stew.test.uk/ontologytypeaheadapi/that", "that" },
                { "http://www.stew.test.uk/ontologytypeaheadapi/the_other", "The Other Label" },
                { "http://www.stew.test.uk/ontologytypeaheadapi/child_of_this", "Child Of This Label" }
            };

            // this will fail if RdfHelper_LoadTtl_OK() fails

            Exception e     = null;
            IGraph    graph = null;

            var ontology = new Ontology(
                testTtl,
                "test",
                "Test Label",
                new List <string>()
            {
                "http://www.stew.test.uk/ontologytypeaheadapi/root"
            },
                RdfSource.String, RdfType.TTL
                );

            try
            {
                graph = RdfHelper.GetGraphFromOntology(ontology);
            }
            catch (Exception ee)
            {
                e = ee;
            }

            Assert.AreEqual(null, e);

            var result = RdfHelper.GetFlatDataFromGraph(ontology.RootTypes, graph);

            AssertHelper.DictionariesAreEqual(expected, result);
        }