Ejemplo n.º 1
0
        public BasicLuisDialog(Activity activity) : base(new LuisService(new LuisModelAttribute(
                                                                             ConfigurationManager.AppSettings["LuisAppId"],
                                                                             ConfigurationManager.AppSettings["LuisAPIKey"],
                                                                             domain: ConfigurationManager.AppSettings["LuisAPIHostName"])))
        {
            channel = activity.ChannelId;
            convID  = activity.Conversation.Id;
            DbAccess db = DbAccess.GetInstanceOfDbAccess();

            db.OpenConnection();
            CommandQuery command = CommandQuery.GetInstanceCommandQuery();

            if (command.InsertNewUser(convID, db.GetConnection()))
            {
                Debug.Print($"Inserimento dell'utente {convID} andato a buon fine!");
            }
            else
            {
                Debug.Print($"Utente già presente!");
            }
            db.CloseConnection();
        }
Ejemplo n.º 2
0
        public static async Task <string> InvokeRequestResponseRecommendationService(string convID)
        {
            using (var client = new HttpClient())
            {
                var scoreRequest = new
                {
                    Inputs = new Dictionary <string, List <Dictionary <string, string> > >()
                    {
                    },
                    GlobalParameters = new Dictionary <string, string>()
                    {
                        {
                            "Database query", "select * " +
                            "from users left join movie_rating on users.id_user=movie_rating.id_user " +
                            "left join movie on movie_rating.id_movie=movie.id_movie " +
                            "left join director_rating on director_rating.id_user=users.id_user " +
                            "left join genre_rating on genre_rating.id_user=users.id_user " +
                            "left join actor_rating on actor_rating.id_user=users.id_user "
                        },
                    }
                };

                const string apiKey = "WHYLuugnhW0ufiSqxPu/0ldypGKY5jMnAAfMi3ZaRm3J9VPvguR/OZpesbNPDetXofDlRG+dvfjDaWbp7JSmRg=="; // Replace this with the API key for the web service

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                client.BaseAddress = new Uri("https://uswestcentral.services.azureml.net/subscriptions/dba37ecf66f64b7e825abc8cbd365998/services/22d1ccd130d24cb2a05dff0790245912/execute?api-version=2.0&format=swagger");

                HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);

                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();

                    Debug.Print("Result: {0}", result);

                    //parserizzo il contenuto di result

                    DbAccess db = DbAccess.GetInstanceOfDbAccess();
                    db.OpenConnection();
                    CommandQuery cm = CommandQuery.GetInstanceCommandQuery();

                    int idUser = Convert.ToInt32(cm.GetIdUserFromIdChat(convID, db.GetConnection()));

                    string checkString = ($"{{\"User\":\"{idUser}\",\"Item 1\":\"");

                    int indexItem = result.IndexOf(checkString);

                    char[] arrayCharResult = result.ToCharArray();

                    Debug.Print($"ITEM CONSIGLIATO {arrayCharResult[indexItem+checkString.Length]}");


                    string suggest = cm.GetMovieNameFromId(Convert.ToInt32(arrayCharResult[indexItem + checkString.Length]), db.GetConnection());

                    db.CloseConnection();

                    return(suggest);
                }
                else
                {
                    Debug.Print(string.Format("The request failed with status code: {0}", response.StatusCode));

                    Debug.Print(response.Headers.ToString());

                    string responseContent = await response.Content.ReadAsStringAsync();

                    Debug.Print(responseContent);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static string InsertIntoDbVlutation(Dictionary <EntityRecommendation, double?> entityScore, Dictionary <EntityRecommendation, List <string> > entityType, string convID)
        {
            DbAccess db = DbAccess.GetInstanceOfDbAccess();

            db.OpenConnection();

            string insert = "ok";

            CommandQuery command = CommandQuery.GetInstanceCommandQuery();

            if (entityType != null)
            {
                Dictionary <EntityRecommendation, List <string> > .Enumerator key = entityType.GetEnumerator();

                while (key.MoveNext() && insert.Equals("ok"))
                {
                    Dictionary <EntityRecommendation, double?> .Enumerator entityEnumerator = entityScore.GetEnumerator();
                    List <string> entityConsidered = new List <string>();
                    while (entityEnumerator.MoveNext())
                    {
                        if (key.Current.Key.Entity.Equals(entityEnumerator.Current.Key.Entity) && !entityConsidered.Contains(entityEnumerator.Current.Key.Entity))//quando trovo l'entità
                        {
                            entityConsidered.Add(entityEnumerator.Current.Key.Entity);
                            List <string> .Enumerator enumList = key.Current.Value.GetEnumerator();
                            string type = string.Empty;
                            while (enumList.MoveNext())
                            {
                                int rating = 0;
                                if (entityEnumerator.Current.Value > 0.5)
                                {
                                    rating = 1;
                                }



                                switch (enumList.Current)
                                {
                                case "movie":
                                    insert = command.InsertPreferencesMovie(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetMovieIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                                    break;

                                case "actor":
                                    insert = command.InsertPrferencesActor(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetActorIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                                    break;

                                case "director":
                                    insert = command.InsertPreferencesDirector(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetDirectorIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                                    break;

                                case "genre":
                                    insert = command.InsertPrferencesGenre(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetGenreIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                                    break;
                                }
                            }
                            enumList.Dispose();
                        }
                    }
                }

                key.Dispose();
            }
            else
            {
                Dictionary <EntityRecommendation, double?> .Enumerator entityEnumerator = entityScore.GetEnumerator();

                while (entityEnumerator.MoveNext())
                {
                    int rating = 0;
                    if (entityEnumerator.Current.Value > 0.5)
                    {
                        rating = 1;
                    }



                    switch (entityEnumerator.Current.Key.Type)
                    {
                    case "movie":
                        insert = command.InsertPreferencesMovie(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetMovieIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                        break;

                    case "actor":
                        insert = command.InsertPrferencesActor(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetActorIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                        break;

                    case "director":
                        insert = command.InsertPreferencesDirector(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetDirectorIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                        break;

                    case "genre":
                        insert = command.InsertPrferencesGenre(Convert.ToInt32(command.GetIdUserFromIdChat(convID, db.GetConnection())), Convert.ToInt32(command.GetGenreIdFromName(entityEnumerator.Current.Key.Entity, db.GetConnection())), rating, db.GetConnection());
                        break;
                    }
                }
                entityEnumerator.Dispose();
            }

            db.CloseConnection();
            return(insert);
        }