Esempio n. 1
0
        private static DialogNode ParseNode(JObject jsonNode, VectorDataStore vectorData, Dictionary <string, DialogContext> contextMap)
        {
            DialogContext context    = ParseContext(jsonNode.Value <string>("context"), contextMap);
            DialogContext inContext  = ParseContext(jsonNode.Value <string>("inContext"), contextMap);
            DialogContext outContext = ParseContext(jsonNode.Value <string>("outContext"), contextMap);

            Statement input = new Statement(inContext ?? context);

            foreach (JObject jsonMessage in jsonNode.Value <JArray>("input"))
            {
                Message message = ParseMessage(jsonMessage, vectorData, contextMap);
                input.Add(message);
            }

            Statement output = new Statement(outContext ?? context);

            foreach (JObject jsonMessage in jsonNode.Value <JArray>("output"))
            {
                Message message = ParseMessage(jsonMessage, vectorData, contextMap);
                output.Add(message);
            }

            DialogNode node = new DialogNode(input, output);

            return(node);
        }
Esempio n. 2
0
        public static DialogTree Load(string filePath, VectorDataStore vectorData)
        {
            DialogTree tree = new DialogPrototype.DialogTree();
            Dictionary <string, DialogContext> contextMap = new Dictionary <string, DialogContext>();

            using (Stream stream = File.OpenRead(filePath))
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8, true))
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        JObject jsonRoot = JObject.Load(jsonReader);

                        JObject jsonDontGetItNode = jsonRoot.Value <JObject>("dontGetItNode");
                        tree.dontGetItNode = ParseNode(jsonDontGetItNode, vectorData, contextMap);

                        JArray jsonNodes = jsonRoot.Value <JArray>("nodes");
                        foreach (JObject jsonNode in jsonNodes)
                        {
                            DialogNode node = ParseNode(jsonNode, vectorData, contextMap);
                            tree.Add(node);
                        }
                    }

            return(tree);
        }
Esempio n. 3
0
 public void Add(DialogNode node)
 {
     this.nodes.Add(node);
 }