public List <Syllable> ReadSyllables() { List <string> syllableIds; using (var dc = ChatbotEntities.GetDataContext()) { syllableIds = dc.chatbot_syllable.Select(p => p.id).ToList(); } WebClient webClient = new WebClient(); List <Syllable> syllables = new List <Syllable>(); foreach (string syllableId in syllableIds) { Syllable syllable = new Syllable(); string url = m_urlSoundTemplate.Replace("{syllable}", syllableId); string filename = Path.GetFileName(url); string filepath = Path.Combine(m_path, "Sound", Source.ykyi.ToString(), filename); filepath = Path.GetFullPath(filepath); syllable.Name = syllableId; syllable.SoundPath = filepath; if (!File.Exists(filepath)) { webClient.DownloadFile(url, filepath); } syllables.Add(syllable); } return(syllables); }
public List <Word> UpdateWords(Source source) { List <string> syllableNames; using (ChatbotEntities dc = ChatbotEntities.GetDataContext()) { string sql = "SELECT DISTINCT * FROM `chatbot_symbol` s left join `chatbot_wordphrase` w on s.id = w.symbol_id where w.symbol_id is null"; List <chatbot_symbol> dbSymbols = dc.Database.SqlQuery <chatbot_symbol>(sql).ToList(); syllableNames = dbSymbols.Select(p => p.id).ToList(); syllableNames = dc.chatbot_symbol.Select(p => p.id).ToList(); // syllableNames = new List<string> { "不" }; } string folder = "../../../../"; string filepath = Path.Combine(folder, "word.json"); List <Word> words; WordsReader reader = new WordsReader(folder); if (!File.Exists(filepath)) { words = reader.ReadWords(syllableNames); string data = JsonConvert.SerializeObject(words); using (StreamWriter sw = new StreamWriter(filepath)) { sw.Write(data); } } else { using (StreamReader sr = new StreamReader(filepath)) { string data = sr.ReadToEnd(); words = JsonConvert.DeserializeObject <List <Word> >(data); reader.SetWords(words); } } return(words); }
public MonitorRepository(ChatbotEntities context) { _context = context; }
public QuestionRepository(ChatbotEntities context) { _context = context; }
public MonitorIdFetch(ChatbotEntities context) { _context = context; }
public MonitorIdFetch() { _context = new ChatbotEntities(); }
public void SaveSyllables(List <Syllable> syllables) { using (ChatbotEntities dc = ChatbotEntities.GetDataContext()) { //1) get symbol list from syllables List <string> currentSymbolIds = dc.chatbot_symbol.Select(p => p.id).ToList(); List <string> symbolIds = syllables.SelectMany(p => p.Symbols).GroupBy(p => p).Select(p => p.First()).ToList(); foreach (string symbolId in symbolIds) { if (!currentSymbolIds.Contains(symbolId)) { chatbot_symbol dbSymbol = new chatbot_symbol(); dbSymbol.id = symbolId; dc.chatbot_symbol.Add(dbSymbol); } } dc.SaveChanges(); List <string> currentSyllableIds = dc.chatbot_syllable.Select(p => p.id).ToList(); List <string> syllableIds = syllables.GroupBy(p => p.Name).Select(p => p.Key).ToList(); //2) create syllables foreach (string syllableId in syllableIds) { if (!currentSyllableIds.Contains(syllableId)) { chatbot_syllable dbSyllable = new chatbot_syllable(); dbSyllable.id = syllableId; dc.chatbot_syllable.Add(dbSyllable); dc.SaveChanges(); } } //3) create sounds for the data source string sourceId = Source.ykyi.ToString(); chatbot_source dbSource = dc.chatbot_source.Where(p => p.id == sourceId).FirstOrDefault(); if (dbSource == null) { dbSource = new chatbot_source { id = sourceId }; dc.chatbot_source.Add(dbSource); dc.SaveChanges(); } List <string> currentSoundIds = dc.chatbot_sound.Where(p => p.source_id == sourceId).Select(p => p.syllable_id).ToList(); foreach (Syllable syllable in syllables) { if (!currentSoundIds.Contains(syllable.Name)) { chatbot_sound dbSound = new chatbot_sound { sound_path = syllable.SoundPath, source_id = sourceId, syllable_id = syllable.Name }; dc.chatbot_sound.Add(dbSound); currentSoundIds.Add(syllable.Name); } } dc.SaveChanges(); //4) create words foreach (Syllable syllable in syllables) { foreach (string symbol in syllable.Symbols) { chatbot_word dbWord = dc.chatbot_word.Where(p => p.syllable_id == syllable.Name && p.symbol_id == symbol).FirstOrDefault(); if (dbWord == null) { dbWord = new chatbot_word(); dbWord.syllable_id = syllable.Name; dbWord.symbol_id = symbol; dc.chatbot_word.Add(dbWord); dc.SaveChanges(); } } } } }
public void SaveWords(List <Word> words) { using (var dc = ChatbotEntities.GetDataContext()) { foreach (Word word in words) { chatbot_syllable syllable = dc.chatbot_syllable.Where(p => p.id == word.Syllable).FirstOrDefault(); if (syllable != null) { if (!string.IsNullOrEmpty(word.Symbol)) { chatbot_symbol dbSymbol = dc.chatbot_symbol.Where(p => p.id == word.Symbol).FirstOrDefault(); if (dbSymbol == null) { dbSymbol = new chatbot_symbol(); dbSymbol.id = word.Symbol; dc.chatbot_symbol.Add(dbSymbol); dc.SaveChanges(); } chatbot_word dbWord = dc.chatbot_word.Where(p => p.syllable_id == word.Syllable && p.symbol_id == word.Symbol).FirstOrDefault(); if (dbWord == null) { dbWord = new chatbot_word(); dbWord.syllable_id = word.Syllable; dbWord.symbol_id = word.Symbol; dbWord.explanation = word.Explanation; dc.chatbot_word.Add(dbWord); dc.SaveChanges(); } else { dbWord.syllable_id = word.Syllable; dbWord.symbol_id = word.Symbol; dbWord.explanation = word.Explanation; dc.Entry(dbWord).State = System.Data.Entity.EntityState.Modified; dc.SaveChanges(); } } if (word.Phrases != null) { foreach (string phrase in word.Phrases) { if (!dc.chatbot_phrase.Any(p => p.id == phrase)) { chatbot_phrase dbPhrase = new chatbot_phrase(); dbPhrase.id = phrase; dc.chatbot_phrase.Add(dbPhrase); dc.SaveChanges(); } if (!dc.chatbot_wordphrase.Any(p => p.phrase_id == phrase && p.syllable_id == word.Syllable && p.symbol_id == word.Symbol)) { chatbot_wordphrase dbWordPhrase = new chatbot_wordphrase(); dbWordPhrase = new chatbot_wordphrase(); dbWordPhrase.phrase_id = phrase; dbWordPhrase.syllable_id = word.Syllable; dbWordPhrase.symbol_id = word.Symbol; dbWordPhrase.location = phrase.IndexOf(word.Symbol); dc.chatbot_wordphrase.Add(dbWordPhrase); dc.SaveChanges(); } } } } } dc.SaveChanges(); } }
public CustomerRepository(ChatbotEntities context) { _context = context; }
public Service() { this.DbSet = new ChatbotEntities(); }
public LinkIdFetch(ChatbotEntities context) { _context = context; }
public LinkIdFetch() { _context = new ChatbotEntities(); }
public OptionsRepository(ChatbotEntities context) { _context = context; }