Пример #1
0
        private static void UpdateData(string key, string value, StructedData data)
        {
            if (value == key)
            {
                return;
            }

            switch (key)
            {
            case "intent":
                data.Intent = value;
                break;

            case "dst_city":
                data.Destination = value;
                break;

            case "or_city":
                data.Origin = value;
                break;

            case "str_date":
                data.Date = value;
                break;

            case "n_adults":
                data.Adults = value;
                break;

            case "budget":
                data.Budget = value;
                break;
            }
        }
Пример #2
0
        private static List <StructedData> ExtractFirstConversation(string path)
        {
            var file     = File.ReadAllText(path);
            var json     = JsonConvert.DeserializeObject <List <RootObject> >(file);
            var index    = 0;
            var dataList = new List <StructedData>();
            var none     = "none";

            foreach (var rootObject in json)
            {
                StructedData current = null;
                index++;
                foreach (var turns in rootObject.turns)
                {
                    var data = new StructedData
                    {
                        Text           = turns.text,
                        User           = turns.author,
                        FrameNumber    = turns.labels.active_frame.ToString(),
                        ConversationId = rootObject.id
                    };

                    if (current != null)
                    {
                        if (data.FrameNumber != current.FrameNumber)
                        {
                            data.FrameSwitched = true;
                        }

                        data.PrevAdults      = string.IsNullOrEmpty(current.Adults) ? none : current.Adults;
                        data.PrevBudget      = string.IsNullOrEmpty(current.Budget) ? none : current.Budget;
                        data.PrevDate        = string.IsNullOrEmpty(current.Date) ? none : current.Date;
                        data.PrevDestination = string.IsNullOrEmpty(current.Destination) ? none : current.Destination;
                        data.PrevOrigin      = string.IsNullOrEmpty(current.Origin) ? none : current.Origin;
                        data.PrevIntent      = string.IsNullOrEmpty(current.Intent) ? none : current.Intent;
                    }
                    else
                    {
                        data.PrevAdults      = none;
                        data.PrevBudget      = none;
                        data.PrevDate        = none;
                        data.PrevDestination = none;
                        data.PrevOrigin      = none;
                        data.PrevIntent      = none;
                    }

                    foreach (var turnsLabel in turns.labels.acts)
                    {
                        foreach (JToken turnsLabelArg in turnsLabel.args)
                        {
                            var children = turnsLabelArg.Children();
                            var first    = (JProperty)children.First();
                            var value    = first.Value.ToString();
                            var second   = (JProperty)children.Last();
                            var key      = second.Value.ToString();
                            UpdateData(key, value, data);
                        }
                    }

                    dataList.Add(data);
                    current = data;
                }
            }

            return(dataList);
        }