// Constructor public FileStats(string fileName, string filePath, Lingva language, string project) { FileName = fileName; FilePath = filePath; Lingva = language; Project = project; }
// Constructor public FileStats(string fileName, string filePath, Lingva language, string project) { this.fileName = fileName; this.filePath = filePath; this.lingva = language; this.project = project; }
/// <summary> /// Stops previously selected language from being watched. /// </summary> public void UnselectLanguage() { currentLanguage = null; // Stop watching previous corpus folder. Have to do stop watcher // from raising event that lead to insertion into Null project list. watcher.ToggleOffCorpus(); // Remove old projects while (Projects.Count > 0) { Projects.RemoveAt(0); } ; }
/// <summary> /// Removes leftover projects from DB. /// </summary> /// <param name="projectsInDir"></param> /// <param name="selectedLang"></param> private void RemoveOldProjects(IEnumerable <string> projectsInDir, Lingva selectedLang) { // Get known projects from DB List <string> projectsInDB = Storage.GetProjects(selectedLang); // Find projects left only in DB foreach (string leftover in projectsInDB.Except(projectsInDir)) { // Remove leftover projects Log.Logger.Debug(string.Format("Deleting project:{0} - {1}", selectedLang.Language, leftover)); Storage.RemoveProject(selectedLang, leftover); } }
/// <summary> /// Adds new language and it's folder to DB. /// </summary> /// <param name="language"></param> /// <param name="directory"></param> /// <returns></returns> public void AddLanguage(Lingva lang) { string sql = "INSERT INTO Languages VALUES(@lang, @directory)"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = lang.Language; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = new SQLiteParameter("@directory"); param.Value = lang.Folder; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } }
/// <summary> /// Sets new language as current. /// </summary> /// <param name="lang"></param> public void SelectLanguage(Lingva lang) { Log.Logger.Debug("New language is chosen."); currentLanguage = lang; IEnumerable <string> projectsInDir; // Start watching new language corpus folder watcher.ToggleOnCorpus(Config.CorpusPath); if (IOTools.ListDirectories(Config.CorpusPath, out projectsInDir)) { // Remove old unused projects from DB RemoveOldProjects(projectsInDir, currentLanguage); } // Add new projects foreach (string prj in projectsInDir) { Projects.Add(prj); } }
/// <summary> /// Removes language from DB and model. /// </summary> /// <param name="language"></param> public void RemoveOldLanguage(Lingva language) { // Remove old language from DB Storage.RemoveLanguage(language); Languages.Remove(language); }
/// <summary> /// Adds new language to DB and model. /// </summary> /// <param name="newLang"></param> public void AddNewLanguage(Lingva newLang) { // Add new language to DB. Storage.AddLanguage(newLang); Languages.Add(newLang); }
/// <summary> /// Adds new language to viewmodel and model. /// </summary> /// <param name="languageViewModel"></param> public void AddNewLanguage(LingvaViewModel languageViewModel) { L.Logger.Debug("Adding new language."); // Use copy constructor. Lingva lang = new Lingva(languageViewModel.CurrentLanguage); model.AddNewLanguage(lang); }
// Constructors public LingvaViewModel(Lingva language) { currentLanguage = language; validProperties.Add("Language", false); validProperties.Add("Folder", false); }
/// <summary> /// Removes the project from DB. /// </summary> /// <param name="language"></param> /// <param name="project"></param> public void RemoveProject(Lingva language, string project) { SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = language.Language; langParam.DbType = System.Data.DbType.String; SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; using (SQLiteCommand cmd = new SQLiteCommand(dbConn)) { cmd.Parameters.Add(langParam); cmd.Parameters.Add(projectParam); // Delete all words from previous analysis. cmd.CommandText = "DELETE FROM Words WHERE file IN " + "(SELECT path FROM Files WHERE lang=@lang AND project=@project)"; cmd.ExecuteNonQuery(); // Delete all stats from previous analysis cmd.CommandText = "DELETE FROM Files WHERE lang=@lang AND project=@project"; cmd.ExecuteNonQuery(); } }
/// <summary> /// Removes the stats of the given language from DB. /// </summary> /// <param name="language"></param> public void RemoveLanguage(Lingva language) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = language.Language; param.DbType = System.Data.DbType.String; using (SQLiteCommand cmd = new SQLiteCommand(dbConn)) { cmd.Parameters.Add(param); // Delete all words from previous analysis. cmd.CommandText = "DELETE FROM Words WHERE file IN " + "(SELECT path FROM Files WHERE lang=@lang)"; cmd.ExecuteNonQuery(); // Delete language and files. cmd.CommandText = "DELETE FROM Languages WHERE lang=@lang"; cmd.ExecuteNonQuery(); } }
/// <summary> /// Provides the list of unknown words and quantities for given /// project. /// </summary> /// <param name="project"></param> /// <returns></returns> public Dictionary<string, int> GetUnknownWords(Lingva lang, string project) { Dictionary<string, int> words = new Dictionary<string, int>(); SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = lang.Language; langParam.DbType = System.Data.DbType.String; string sql = "SELECT word, SUM(quantity) as sum " + "FROM Words JOIN Files on Words.file = Files.path " + "WHERE project=@project AND lang=@lang " + "GROUP BY word ORDER BY sum DESC LIMIT 100"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { cmd.Parameters.Add(projectParam); cmd.Parameters.Add(langParam); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { words[dr.GetString(0)] = dr.GetInt32(1); } dr.Close(); } return words; }
/// <summary> /// Return projects for chosen language. /// </summary> /// <param name="selectedLang"></param> /// <returns></returns> public List<string> GetProjects(Lingva selectedLang) { List<string> projects = new List<string>(); string sql = "SELECT project FROM Files WHERE lang=@lang GROUP BY project"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = selectedLang.Language; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { projects.Add(dr.GetString(0)); } dr.Close(); } return projects; }
/// <summary> /// Returns list of fileStats for given language and project. /// </summary> /// <param name="language"></param> /// <param name="project"></param> /// <returns></returns> public List<FileStats> GetFilesStats(Lingva language, string project) { SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = language.Language; langParam.DbType = System.Data.DbType.String; SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; string sql = "SELECT name, path, size, known, maybe, unknown FROM Files " + "WHERE lang=@lang AND project=@project"; List<FileStats> stats = new List<FileStats>(); using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { cmd.Parameters.Add(langParam); cmd.Parameters.Add(projectParam); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { stats.Add(new FileStats( dr.GetString(0), dr.GetString(1), language, project) { Size = dr.GetInt32(2), Known = dr.GetInt32(3), Maybe = dr.GetInt32(4), Unknown = dr.GetInt32(5) }); } dr.Close(); } return stats; }