Esempio n. 1
0
        public ActionResult CreateDictionary(string s)
        {
            string path;
            path = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string localPath = new Uri(path).LocalPath;

            string userPreferencesFile = "C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/UserPreference.json";
            string trainingSetFile = "C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/TrainingSet.json";

            JSONService<UserPreference> userPreferenceReader = new JSONService<UserPreference>();
            UserPreference up = userPreferenceReader.ConvertJSONToObject(userPreferencesFile);

            JSONService<List<TrainingSet>> trainingSetReader = new JSONService<List<TrainingSet>>();

            List<TrainingSet> ts = trainingSetReader.ConvertJSONToObject(trainingSetFile);

            Dictionary<string, List<string>> keywordDict = new Dictionary<string, List<string>>();

            foreach (string item in up.ShoppingDomain)
            {
                foreach (TrainingSet t in ts)
                {
                    if (t.From.Contains(item))
                    {
                        List<string> subjectWords = new List<string>(t.Subject.Split(' '));
                        List<string> bodyWords = new List<string>(t.Body.Split(' '));
                        List<string> allWords = new List<string>();

                        subjectWords = (from x in subjectWords
                                        where IsWordAStopWord(x) == false
                                        select x).ToList();
                        bodyWords = (from x in bodyWords
                                     where IsWordAStopWord(x) == false
                                     select x).ToList();
                        allWords.AddRange(subjectWords);
                        allWords.AddRange(bodyWords);
                        List<string> mostFreqWords = GetWordsWithMostFrequency(allWords, 1);
                        if (keywordDict.ContainsKey("ShoppingDomain"))
                        {
                            List<string> keywordList = keywordDict["ShoppingDomain"];
                            keywordList.AddRange(mostFreqWords);

                        }
                        else // no key exists...create a key and assign the value
                        {
                            keywordDict["ShoppingDomain"] = mostFreqWords;
                        }

                    }
                }

            }

            string keywordjson = JsonConvert.SerializeObject(keywordDict);
            //System.IO.File.Delete(localPath + @"\Data\KeywordDictFile.json");
            System.IO.File.WriteAllText("C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/KeywordDictFile.json", keywordjson);

            Dictionary<string, List<string>> key = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(keywordjson);
            return View();
        }
Esempio n. 2
0
        public ActionResult UserHome()
        {
            JSONService<UserPreference> jsonReader = new JSONService<UserPreference>();

            string path;
            path = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string localPath = new Uri(path).LocalPath;

            //UserPreference up = jsonReader.ConvertJSONToObject(localPath + @"\Data\UserPreference.json");

            UserPreference up = jsonReader.ConvertJSONToObject("C:/Users/swapn/Desktop/Thesis/ThesisProject/ThesisProject/Data/UserPreference.json");

            return View(up);
        }