コード例 #1
0
        public void ParseKG()
        {
            List <Vertex> vertexes = this.vCollection; // this.GetVertexes(null);
            List <Edge>   edges    = this.eColletion;  // this.GetEdges(null);

            (Dictionary <string, HashSet <string> > nameIdMap, Dictionary <string, Dictionary <RelationLink, List <string> > > outRelationDict, Dictionary <string, Dictionary <RelationLink, List <string> > > inRelationDict, Dictionary <string, List <Edge> > scenarioEdgesMap) = this.GenerateRelationship(vertexes, edges);

            Dictionary <string, List <Vertex> > vNameCache = new Dictionary <string, List <Vertex> >();
            Dictionary <string, Vertex>         vIdCache   = new Dictionary <string, Vertex>();
            List <Vertex> roots = new List <Vertex>();

            HashSet <string> scenarioNames = new HashSet <string>();

            foreach (Vertex vertex in vertexes)
            {
                scenarioNames.UnionWith(vertex.scenarios);

                if (vertex.nodeType == "ROOT")
                {
                    roots.Add(vertex);
                }

                if (vNameCache.ContainsKey(vertex.name))
                {
                    vNameCache[vertex.name].Add(vertex);
                }
                else
                {
                    List <Vertex> vertexesGroupedByName = new List <Vertex>();
                    vertexesGroupedByName.Add(vertex);
                    vNameCache.Add(vertex.name, vertexesGroupedByName);
                }
                vIdCache.Add(vertex.id, vertex);
            }

            Dictionary <string, List <ColorConfig> > vertexLabelsMap = new Dictionary <string, List <ColorConfig> >();

            foreach (VisulizationConfig vc in this.vcList)
            {
                string             scenarioName = vc.scenario;
                List <ColorConfig> cc           = vc.labelsOfVertexes;

                vertexLabelsMap.Add(scenarioName, cc);
            }

            KnowledgeGraphStore store = KnowledgeGraphStore.GetInstance();

            store.SetRootVertexes(roots);
            store.SetVertexIdCache(vIdCache);
            store.SetVertexNameCache(vNameCache);
            store.SetOutRelationDict(outRelationDict);
            store.SetInRelationDict(inRelationDict);
            store.SetNameIdCache(nameIdMap);
            store.SetScenarioEdgesDict(scenarioEdgesMap);
            store.SetScenarioNames(scenarioNames);
            store.SetVertexLabelColorMap(vertexLabelsMap);
        }
コード例 #2
0
ファイル: DataLoader.cs プロジェクト: wangyoucaocxl/SmartKG
        public void Load(string dsName)
        {
            KnowledgeGraphStore.GetInstance().Clean();
            NLUStore.GetInstance().Clean();

            this.currentDataStoreName = dsName;

            (this.vList, this.eList, this.vcList, this.iList, this.enList, this.eaList) = this.dataAccessor.Load(dsName);

            if (this.vcList == null || this.vList == null || this.eList == null)
            {
                throw new Exception("Cannot load KG data from persistance.");
            }

            DataPersistanceKGParser kgParser = new DataPersistanceKGParser(this.vList, this.eList, this.vcList);

            kgParser.ParseKG();

            log.Information("Knowledge Graph is parsed.");
            Console.WriteLine("Knowledge Graph is parsed.");

            if (this.iList == null || this.enList == null)
            {
                log.Here().Warning("No NLU Data loaded from persistence");
            }
            else
            {
                DataPersistanceNLUParser nluParser = new DataPersistanceNLUParser(this.iList, this.enList, this.eaList);
                nluParser.Parse();

                List <Vertex> roots = KnowledgeGraphStore.GetInstance().GetAllVertexes();
                nluParser.ParseScenarioSettings(this.settings, roots);

                log.Information("NLU materials is parsed.");
                Console.WriteLine("NLU materials is parsed.");
            }
        }
コード例 #3
0
 public GraphExecutor()
 {
     this.store = KnowledgeGraphStore.GetInstance();
     log        = Log.Logger.ForContext <GraphExecutor>();
 }
コード例 #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ILogger <Startup> _log)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseCors(builder =>
            {
                builder.AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin();
            });

            app.UseHttpsRedirection();
            app.UseSession();
            app.UseMvcWithDefaultRoute();

            loggerFactory.AddSerilog();

            Serilog.ILogger log = Log.Logger.ForContext <Startup>().Here();


            try
            {
                KGDataAccessor.initInstance(Configuration);
                log.Information("KG Data is initialized.");
            }
            catch (Exception e)
            {
                log.Error("Exception in KG Data initializing.\n" + e.Message);
            }

            try
            {
                KGDataAccessor            accessor = KGDataAccessor.GetInstance();
                List <Vertex>             vList    = accessor.GetVertexCollection();
                List <Edge>               eList    = accessor.GetEdgeCollection();
                List <VisulizationConfig> vcList   = accessor.GetVisulizationConfigs();


                DataPersistanceKGParser kgParser = new DataPersistanceKGParser(vList, eList, vcList);
                kgParser.ParseKG();

                log.Information("Knowledge Graph is parsed.");
                Console.WriteLine("Knowledge Graph is parsed.");
            }
            catch (Exception e)
            {
                log.Error("Exception in KnowledgeGraph parsing.\n" + e.Message);
                Console.WriteLine("[Error]" + e.Message);
            }

            try
            {
                NLUDataAccessor.initInstance(Configuration);
                log.Information("NLU Data is initialized.");
            }
            catch (Exception e)
            {
                log.Error("Exception in NLU Data initializing.\n" + e.Message);
            }

            try
            {
                List <ScenarioSetting> settings = Configuration.GetSection("Scenarios").Get <List <ScenarioSetting> >();

                NLUDataAccessor accessor = NLUDataAccessor.GetInstance();

                DataPersistanceNLUParser nluParser = new DataPersistanceNLUParser(accessor.GetIntentCollection(), accessor.GetEntityCollection(), accessor.GetEntityAttributeCollection());
                nluParser.Parse();

                List <Vertex> roots = KnowledgeGraphStore.GetInstance().GetAllVertexes();
                nluParser.ParseScenarioSettings(settings, roots);

                log.Information("NLU materials is parsed.");
                Console.WriteLine("NLU materials is parsed.");
            }
            catch (Exception e)
            {
                log.Error("Exception in NLU materials parsing.\n" + e.Message);
            }

            try
            {
                ContextAccessController.initInstance(Configuration);
                log.Information("Context Data is initialized.");
            }
            catch (Exception e)
            {
                log.Error("Exception in Context Data initializing.\n" + e.Message);
            }
        }
コード例 #5
0
 public DataManager()
 {
     this.kgStore  = KnowledgeGraphStore.GetInstance();
     this.nluStore = NLUStore.GetInstance();
     log           = Log.Logger.ForContext <DataManager>();
 }