Example #1
0
        public GraphExecutor(string datastoreName)
        {
            log = Log.Logger.ForContext <GraphExecutor>();

            DataStoreFrame dsFrame = DataStoreManager.GetInstance().GetDataStore(datastoreName);

            if (dsFrame != null)
            {
                this.kgDF = dsFrame.GetKG();
            }
        }
Example #2
0
        public KnowledgeGraphDataFrame ParseKG(List <Vertex> vertexes, List <Edge> edges)
        {
            (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);
            }



            KnowledgeGraphDataFrame kgDF = new KnowledgeGraphDataFrame();

            kgDF.SetRootVertexes(roots);
            kgDF.SetVertexIdCache(vIdCache);
            kgDF.SetVertexNameCache(vNameCache);
            kgDF.SetOutRelationDict(outRelationDict);
            kgDF.SetInRelationDict(inRelationDict);
            kgDF.SetScenarioEdgesDict(scenarioEdgesMap);
            kgDF.SetScenarioNames(scenarioNames);

            return(kgDF);
        }
Example #3
0
        public DataStoreFrame LoadDataStore(string dsName)
        {
            List <Vertex>             vList  = null;
            List <Edge>               eList  = null;
            List <VisulizationConfig> vcList = null;

            List <NLUIntentRule>       iList  = null;
            List <EntityData>          enList = null;
            List <EntityAttributeData> eaList = null;

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

            if (vcList == null || vList == null || eList == null)
            {
                log.Here().Warning("No KG Data loaded from persistence");
                return(null);
            }

            DataPersistanceKGParser kgParser      = new DataPersistanceKGParser();
            KnowledgeGraphDataFrame kgDF          = kgParser.ParseKG(vList, eList);
            KGConfigFrame           kgConfigFrame = kgParser.ParseKGConfig(vcList);

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

            NLUDataFrame nluDF = null;

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

                log.Information("NLU materials is parsed.");
                Console.WriteLine("NLU materials is parsed.");
            }

            DataStoreFrame dsFrame = new DataStoreFrame(dsName, kgDF, kgConfigFrame, nluDF);

            return(dsFrame);
        }