public void GetSchemes() { List <DatabaseStream> streams = DatabaseHandler.Streams; List <DatabaseScheme> schemesValid = new List <DatabaseScheme>(); List <DatabaseScheme> schemes = DatabaseHandler.Schemes; foreach (DatabaseScheme scheme in schemes) { foreach (DatabaseStream stream in streams) { bool template = mode == Mode.TRAIN || mode == Mode.COMPLETE; if (getTrainer(stream, scheme, template).Count > 0) { schemesValid.Add(scheme); break; } } } SchemesBox.ItemsSource = schemesValid; if (SchemesBox.Items.Count > 0) { DatabaseScheme scheme = ((List <DatabaseScheme>)SchemesBox.ItemsSource).Find(s => s.Name == Properties.Settings.Default.CMLDefaultScheme); if (scheme != null) { SchemesBox.SelectedItem = scheme; } if (SchemesBox.SelectedItem == null) { SchemesBox.SelectedIndex = 0; } SchemesBox.ScrollIntoView(SchemesBox.SelectedItem); } }
private void SelectFinishedSessions() { List <DatabaseSession> sessions = (List <DatabaseSession>)SessionsBox.ItemsSource; if (sessions == null) { return; } DatabaseScheme scheme = (DatabaseScheme)SchemesBox.SelectedItem; DatabaseAnnotator annotator = (DatabaseAnnotator)AnnotatorsBox.SelectedItem; foreach (DatabaseRole role in RolesBox.SelectedItems) { List <DatabaseAnnotation> annotations = DatabaseHandler.GetAnnotations(scheme, role, annotator); foreach (DatabaseAnnotation annotation in annotations) { if (annotation.IsFinished) { DatabaseSession session = sessions.Find(s => s.Name == annotation.Session); if (session != null) { SessionsBox.SelectedItems.Add(session); } } } } }
private void ValidateDatabaseScheme(DatabaseScheme database) { foreach (TableScheme tableScheme in database.Tables) { ValidateTableScheme(tableScheme); } }
// GET: /<controller>/ public IActionResult Index() { string connStr = "server=mysql-server;user=ehour;database=ehour;port=3306;password=qwerty"; string sql = "SELECT * FROM USER_ROLE"; MySqlConnection conn = new MySqlConnection(connStr); MySqlCommand cmd = new MySqlCommand(sql, conn); var model = new List <DatabaseScheme>(); using (MySqlConnection conn2 = new MySqlConnection(connStr)) { conn.Open(); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { var student = new DatabaseScheme(); student.Role = $"{rdr["ROLE"]}"; student.Name = $"{rdr["NAME"]}"; model.Add(student); } } return(View(model)); }
public string CreateDBPathString(DatabaseScheme scheme) { string dbPathString = AppDomain.CurrentDomain.BaseDirectory + @"locdb\"; if (!Directory.Exists(dbPathString)) { Directory.CreateDirectory(dbPathString); } string pathFullString = string.Format(@"Data Source ={0}locdb\{1}.db", AppDomain.CurrentDomain.BaseDirectory, scheme.ToString().ToLower()); return(pathFullString); }
public IRelationalDbStorage CreateRelationalDbStorage(DatabaseScheme scheme) { var connectionStrings = _options.ConnectionStrings; switch (scheme) { case DatabaseScheme.ReadDb: return(new RelationalDbStorage(AdoNetInvariants.InvariantNameMySqlConnector, connectionStrings.ReadDb)); case DatabaseScheme.StateDb: return(new RelationalDbStorage(AdoNetInvariants.InvariantNameMySqlConnector, connectionStrings.StateDb)); default: throw new ArgumentOutOfRangeException(nameof(scheme), scheme, null); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { switchMode(); GetDatabases(DatabaseHandler.DatabaseName); if (mode == Mode.COMPLETE) { AnnoList annoList = AnnoTierStatic.Selected.AnnoList; DatabaseScheme scheme = ((List <DatabaseScheme>)SchemesBox.ItemsSource).Find(s => s.Name == annoList.Scheme.Name); if (scheme != null) { SchemesBox.SelectedItem = scheme; SchemesBox.ScrollIntoView(scheme); } DatabaseRole role = ((List <DatabaseRole>)RolesBox.ItemsSource).Find(r => r.Name == annoList.Meta.Role); if (role != null) { RolesBox.SelectedItem = role; RolesBox.ScrollIntoView(role); } DatabaseAnnotator annotator = ((List <DatabaseAnnotator>)AnnotatorsBox.ItemsSource).Find(a => a.Name == Properties.Settings.Default.MongoDBUser); if (annotator != null) { AnnotatorsBox.SelectedItem = annotator; AnnotatorsBox.ScrollIntoView(annotator); } DatabaseSession session = ((List <DatabaseSession>)SessionsBox.ItemsSource).Find(s => s.Name == DatabaseHandler.SessionName); if (session != null) { SessionsBox.SelectedItem = session; SessionsBox.ScrollIntoView(session); } Update(); } ApplyButton.Focus(); handleSelectionChanged = true; }
public void GetSessions() { if (SchemesBox.SelectedItem == null || RolesBox.SelectedItem == null || AnnotatorsBox.SelectedItem == null) { return; } if (mode == Mode.TRAIN || mode == Mode.EVALUATE) { // show user sessions only List <DatabaseSession> sessions = new List <DatabaseSession>(); DatabaseAnnotator annotator = (DatabaseAnnotator)AnnotatorsBox.SelectedItem; DatabaseScheme scheme = (DatabaseScheme)SchemesBox.SelectedItem; foreach (DatabaseRole role in RolesBox.SelectedItems) { List <DatabaseAnnotation> annotations = DatabaseHandler.GetAnnotations(scheme, role, annotator); foreach (DatabaseAnnotation annotation in annotations) { DatabaseSession session = DatabaseHandler.Sessions.Find(s => s.Name == annotation.Session); if (session != null) { if (!sessions.Contains(session)) { sessions.Add(session); } } } } SessionsBox.ItemsSource = sessions.OrderBy(s => s.Name).ToList(); } else { SessionsBox.ItemsSource = DatabaseHandler.Sessions; } }
public SqlLiteAdoSession(DatabaseScheme scheme) { _ConnectionString = CreateDBPathString(scheme); _Connection = new SQLiteConnection(_ConnectionString); }
private void Apply_Click(object sender, RoutedEventArgs e) { bool force = ForceCheckBox.IsChecked.Value; string database = DatabaseHandler.DatabaseName; string[] sessions = new string[SessionsBox.SelectedItems.Count]; int i = 0; foreach (DatabaseSession item in SessionsBox.SelectedItems) { sessions[i] = item.Name; i++; } string[] schemes = new string[SchemeandAnnotatorBox.Items.Count]; int s = 0; foreach (SchemeAnnotatorPair item in SchemeandAnnotatorBox.Items) { schemes[s] = item.Name + ":" + item.Annotator; s++; } string rolesList = ""; var roles = RolesBox.SelectedItems; foreach (string role in roles) { if (rolesList == "") { rolesList += role; } else { rolesList += ";" + role; } } Properties.Settings.Default.SettingCMLDefaultBN = NetworkBox.SelectedItem.ToString(); if (RolesBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultRole = RolesBox.SelectedItem.ToString(); } if (AnnotatorInputBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultAnnotator = AnnotatorInputBox.SelectedItem.ToString(); } if (SchemeOutputBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultScheme = SchemeOutputBox.SelectedItem.ToString(); } Properties.Settings.Default.CMLDefaultAnnotatorPrediction = AnnotatorsBox.SelectedItem.ToString(); Properties.Settings.Default.Save(); logTextBox.Text = ""; string outputscheme = SchemeOutputBox.SelectedItem.ToString(); string annotator = DatabaseHandler.Annotators.Find(n => n.FullName == Properties.Settings.Default.CMLDefaultAnnotatorPrediction).Name; string roleout = Outrole.SelectedItem.ToString(); bool tocontinuous = false; DatabaseScheme outscheme = DatabaseHandler.Schemes.Find(n => n.Name == outputscheme); if (outscheme.Type == AnnoScheme.TYPE.CONTINUOUS) { tocontinuous = true; } string cmlfolderpath = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\"; string netpath = cmlfolderpath + NetworkBox.SelectedItem.ToString(); string schemespath = cmlfolderpath + "schemes.set"; string sessionsspath = cmlfolderpath + "sessions.set"; System.IO.File.WriteAllLines(schemespath, schemes); System.IO.File.WriteAllLines(sessionsspath, sessions); float filter = -1.0f; if (smoothcheckbox.IsChecked == true) { float.TryParse(WindowSmoothBox.Text, out filter); } logTextBox.Text += handler.CMLPredictBayesFusion(roleout, sessionsspath, schemespath, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), Properties.Settings.Default.DatabaseDirectory, database, outputscheme, rolesList, annotator, tocontinuous, netpath, filter); }
private void Apply_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.SettingCMLDefaultBN = NetworkSelectionBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultAnnotator = AnnotatorsBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultRole = RolesBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultScheme = SchemesBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultTrainer = NetworkSelectionBox.SelectedItem.ToString(); Properties.Settings.Default.Save(); bool force = ForceCheckBox.IsChecked.Value; string database = DatabaseHandler.DatabaseName; var sessions = SessionsBox.SelectedItems; logTextBox.Text = ""; string networkrDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\" + NetworkSelectionBox.SelectedItem + ".xdsl"; string datasetDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\" + namebox.Text; double chunksizeinMS; double.TryParse(chunksizebox.Text, out chunksizeinMS); int tempsteps; int.TryParse(timestepsbox.Text, out tempsteps); bool isdynamic = tempsteps > 0 ? true : false; if (File.Exists(datasetDir) && ForceCheckBox.IsChecked == false) { // logTextBox.Text = "dataset exists, skip.\n"; logTextBox.Text += "\nData sheet exits, check force to overwrite"; // logTextBox.Text += handler.CMLTrainBayesianNetwork(networkrDir, datasetDir, isdynamic); return; } File.Delete(datasetDir); bool ishead = true; foreach (DatabaseSession session in SessionsBox.SelectedItems) { List <AnnoList> annoLists = new List <AnnoList>(); foreach (SchemeRoleAnnotator item in AnnotationSelectionBox.Items) { DatabaseRole role = DatabaseHandler.Roles.Find(r => r.Name == item.Role); DatabaseScheme scheme = DatabaseHandler.Schemes.Find(m => m.Name == item.Name); ObjectId annotatorID = DatabaseHandler.Annotators.Find(a => a.FullName == item.Annotator).Id; var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("scheme_id", scheme.Id) & builder.Eq("annotator_id", annotatorID) & builder.Eq("role_id", role.Id) & builder.Eq("session_id", session.Id); List <DatabaseAnnotation> list = DatabaseHandler.GetAnnotations(filter); foreach (DatabaseAnnotation anno in list) { AnnoList annolist = DatabaseHandler.LoadAnnoList(anno.Id); if (annolist.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { for (int i = 0; i < item.Classes; i++) { annolist.Scheme.Labels.Add(new AnnoScheme.Label("s" + (i + 1).ToString(), System.Windows.Media.Colors.Black)) ; } } annoLists.Add(annolist); logTextBox.Text = logTextBox.Text + "Session: " + session.Name + " Role: " + annolist.Meta.Role + " Scheme: " + annolist.Scheme.Name + "\n"; logTextBox.Focus(); logTextBox.CaretIndex = logTextBox.Text.Length; logTextBox.ScrollToEnd(); } } logTextBox.Text = logTextBox.Text + "----------------------------------\n"; if (rolecheckbox.IsChecked == true) { ExportFrameWiseAnnotations(chunksizeinMS, ';', "REST", datasetDir, annoLists, ishead, session.Name, tempsteps); } else { ExportFrameWiseAnnotationsRolesSeperated(chunksizeinMS, ';', "REST", datasetDir, annoLists, ishead, session.Name, tempsteps); } if (ishead) { ishead = false; } } string[] pairs = new string[AnnotationSelectionBox.Items.Count]; int s = 0; foreach (SchemeRoleAnnotator item in AnnotationSelectionBox.Items) { pairs[s] = item.Name + ":" + item.Annotator + ":" + item.Role + ":" + item.Classes; s++; } string cmlfolderpath = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\"; string trainingsetpath = cmlfolderpath + "training.set"; System.IO.File.WriteAllLines(trainingsetpath, pairs); logTextBox.Text += "\nCreating Data sheet successful\nHit train to train the network or use it in GenIE"; }
private List <Trainer> getTrainer(DatabaseStream stream, DatabaseScheme scheme, bool isTemplate) { List <Trainer> trainers = new List <Trainer>(); if (scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { if (stream.SampleRate != scheme.SampleRate) { return(trainers); } } string streamName = ""; string[] streamParts = stream.Name.Split('.'); if (streamParts.Length <= 1) { streamName = stream.Name; } else { streamName = streamParts[1]; for (int i = 2; i < streamParts.Length; i++) { streamName += "." + streamParts[i]; } } string trainerDir = null; if (isTemplate) { trainerDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.ModelsFolderName + "\\" + Defaults.CML.ModelsTemplatesFolderName + "\\" + scheme.Type.ToString().ToLower() + "\\" + stream.Type; } else { trainerDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.ModelsFolderName + "\\" + Defaults.CML.ModelsTrainerFolderName + "\\" + scheme.Type.ToString().ToLower() + "\\" + scheme.Name + "\\" + stream.Type + "{" + streamName + "}\\"; } if (Directory.Exists(trainerDir)) { string[] searchDirs = Directory.GetDirectories(trainerDir); foreach (string searchDir in searchDirs) { string[] trainerFiles = Directory.GetFiles(searchDir, "*." + Defaults.CML.TrainerFileExtension); foreach (string trainerFile in trainerFiles) { Trainer trainer = new Trainer() { Path = trainerFile }; if (parseTrainerFile(ref trainer, isTemplate)) { trainers.Add(trainer); } } } } return(trainers); }
private void GetTrainers() { if (RolesBox.SelectedItem == null || AnnotatorsBox.SelectedItem == null || SchemesBox.SelectedItem == null) { return; } TrainerPathComboBox.ItemsSource = null; if (StreamsBox.SelectedItem != null) { DatabaseStream stream = (DatabaseStream)StreamsBox.SelectedItem; DatabaseScheme scheme = (DatabaseScheme)SchemesBox.SelectedItem; if (scheme != null) { bool isDiscrete = scheme.Type == AnnoScheme.TYPE.DISCRETE; FillGapCheckBox.IsEnabled = isDiscrete; FillGapTextBox.IsEnabled = isDiscrete; RemoveLabelCheckBox.IsEnabled = isDiscrete; RemoveLabelTextBox.IsEnabled = isDiscrete; bool template = mode == Mode.TRAIN || mode == Mode.COMPLETE; List <Trainer> trainers = getTrainer(stream, scheme, template); if (trainers.Count > 0) { TrainerPathComboBox.ItemsSource = trainers; } } } if (TrainerPathComboBox.Items.Count > 0) { Trainer trainer = ((List <Trainer>)TrainerPathComboBox.ItemsSource).Find(t => t.Name == Properties.Settings.Default.CMLDefaultTrainer); if (trainer != null) { TrainerPathComboBox.SelectedItem = trainer; } else { TrainerPathComboBox.SelectedIndex = 0; } } if (TrainerPathComboBox.SelectedItem != null) { Trainer trainer = (Trainer)TrainerPathComboBox.SelectedItem; LeftContextTextBox.Text = trainer.LeftContext; RightContextTextBox.Text = trainer.RightContext; BalanceComboBox.SelectedIndex = 0; if (trainer.Balance.ToLower() == "under") { BalanceComboBox.SelectedIndex = 1; } else if (trainer.Balance.ToLower() == "over") { BalanceComboBox.SelectedIndex = 2; } string database = ""; if (DatabasesBox.SelectedItem != null) { database = DatabasesBox.SelectedItem.ToString(); } TrainerNameTextBox.Text = mode == Mode.COMPLETE ? Path.GetFileName(tempTrainerPath) : database; TrainerPathLabel.Content = trainer.Path; } }
private void Apply_Click(object sender, RoutedEventArgs e) { Trainer trainer = (Trainer)TrainerPathComboBox.SelectedItem; bool force = mode == Mode.COMPLETE || ForceCheckBox.IsChecked.Value; if (!File.Exists(trainer.Path)) { MessageTools.Warning("file does not exist '" + trainer.Path + "'"); return; } string database = DatabaseHandler.DatabaseName; DatabaseStream stream = (DatabaseStream)StreamsBox.SelectedItem; string sessionList = ""; var sessions = SessionsBox.SelectedItems; foreach (DatabaseSession session in sessions) { if (sessionList == "") { sessionList += session.Name; } else { sessionList += ";" + session.Name; } } DatabaseScheme scheme = (DatabaseScheme)SchemesBox.SelectedItem; string rolesList = ""; var roles = RolesBox.SelectedItems; foreach (DatabaseRole role in roles) { if (rolesList == "") { rolesList += role.Name; } else { rolesList += ";" + role.Name; } } DatabaseAnnotator annotator = (DatabaseAnnotator)AnnotatorsBox.SelectedItem; string trainerLeftContext = LeftContextTextBox.Text; string trainerRightContext = RightContextTextBox.Text; string trainerBalance = ((ComboBoxItem)BalanceComboBox.SelectedItem).Content.ToString(); logTextBox.Text = ""; if (mode == Mode.TRAIN || mode == Mode.COMPLETE) { string streamName = ""; string[] streamParts = stream.Name.Split('.'); if (streamParts.Length <= 1) { streamName = stream.Name; } else { streamName = streamParts[1]; for (int i = 2; i < streamParts.Length; i++) { streamName += "." + streamParts[i]; } } string trainerDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.ModelsFolderName + "\\" + Defaults.CML.ModelsTrainerFolderName + "\\" + scheme.Type.ToString().ToLower() + "\\" + scheme.Name + "\\" + stream.Type + "{" + streamName + "}\\" + trainer.Name + "\\"; Directory.CreateDirectory(trainerDir); string trainerName = TrainerNameTextBox.Text == "" ? trainer.Name : TrainerNameTextBox.Text; string trainerOutPath = mode == Mode.COMPLETE ? tempTrainerPath : trainerDir + trainerName; if (force || !File.Exists(trainerOutPath + ".trainer")) { try { logTextBox.Text += handler.CMLTrainModel(trainer.Path, trainerOutPath, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, trainerLeftContext, trainerRightContext, trainerBalance, mode == Mode.COMPLETE); } catch (Exception ex) { logTextBox.Text += ex; } } else { logTextBox.Text += "skip " + trainerOutPath + "\n"; } } if (mode == Mode.PREDICT || mode == Mode.COMPLETE) { if (true || force) { double confidence = -1.0; if (ConfidenceCheckBox.IsChecked == true && ConfidenceTextBox.IsEnabled) { double.TryParse(ConfidenceTextBox.Text, out confidence); Properties.Settings.Default.CMLDefaultConf = confidence; } double minGap = 0.0; if (FillGapCheckBox.IsChecked == true && FillGapTextBox.IsEnabled) { double.TryParse(FillGapTextBox.Text, out minGap); Properties.Settings.Default.CMLDefaultGap = minGap; } double minDur = 0.0; if (RemoveLabelCheckBox.IsChecked == true && RemoveLabelTextBox.IsEnabled) { double.TryParse(RemoveLabelTextBox.Text, out minDur); Properties.Settings.Default.CMLDefaultMinDur = minDur; } Properties.Settings.Default.Save(); try { logTextBox.Text += handler.CMLPredictAnnos(mode == Mode.COMPLETE ? tempTrainerPath : trainer.Path, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, trainerLeftContext, trainerRightContext, confidence, minGap, minDur, mode == Mode.COMPLETE); } catch (Exception ex) { logTextBox.Text += ex; } } } if (mode == Mode.EVALUATE) { string evalOutPath = Properties.Settings.Default.CMLDirectory + "\\" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); try { logTextBox.Text += handler.CMLEvaluateModel(evalOutPath, trainer.Path, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, LosoCheckBox.IsChecked.Value); if (File.Exists(evalOutPath)) { ConfmatWindow confmat = new ConfmatWindow(evalOutPath); confmat.ShowDialog(); File.Delete(evalOutPath); } } catch (Exception ex) { logTextBox.Text += ex; } } if (mode == Mode.COMPLETE) { handler.ReloadAnnoTierFromDatabase(AnnoTierStatic.Selected, false); var dir = new DirectoryInfo(Path.GetDirectoryName(tempTrainerPath)); foreach (var file in dir.EnumerateFiles(Path.GetFileName(tempTrainerPath) + "*")) { file.Delete(); } Close(); } }