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); } } } } }
public DatabaseAdminAnnotatorWindow(ref DatabaseAnnotator annotator, List <string> names = null) { InitializeComponent(); this.annotator = annotator; if (names == null) { NameBox.Items.Add(annotator.Name); NameBox.SelectedIndex = 0; NameBox.IsEnabled = false; foreach (var item in RoleBox.Items) { if (item.ToString().Contains(annotator.Role)) { RoleBox.SelectedItem = item; } } } else { NameBox.ItemsSource = names; } }
private void AddAnnotator_Click(object sender, RoutedEventArgs e) { List <string> users = DatabaseHandler.GetUsers(); if (users.Count > 0) { DatabaseAnnotator annotator = new DatabaseAnnotator(); List <string> names = DatabaseHandler.GetUsers(); foreach (string name in AnnotatorsBox.Items) { names.RemoveAll(s => s == name); } DatabaseAdminAnnotatorWindow dialog = new DatabaseAdminAnnotatorWindow(ref annotator, names); dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.ShowDialog(); if (dialog.DialogResult == true) { if (DatabaseHandler.AddOrUpdateAnnotator(annotator)) { GetAnnotators(annotator.Name); } } } }
public void GetAnnotators() { AnnotatorsBox.ItemsSource = DatabaseHandler.Annotators; if (AnnotatorsBox.Items.Count > 0) { string annotatorName = Properties.Settings.Default.CMLDefaultAnnotator; AnnotatorsBox.IsEnabled = mode != Mode.COMPLETE; if (mode == Mode.PREDICT) { if (DatabaseHandler.CheckAuthentication() <= DatabaseAuthentication.READWRITE) { annotatorName = Properties.Settings.Default.MongoDBUser; AnnotatorsBox.IsEnabled = false; } else { annotatorName = Properties.Settings.Default.CMLDefaultAnnotatorPrediction; } } else if (DatabaseHandler.CheckAuthentication() > DatabaseAuthentication.READWRITE) { annotatorName = Properties.Settings.Default.CMLDefaultAnnotator; } // check for last user DatabaseAnnotator annotator = ((List <DatabaseAnnotator>)AnnotatorsBox.ItemsSource).Find(a => a.Name == annotatorName); if (annotator != null) { AnnotatorsBox.SelectedItem = annotator; } // check for gold if (AnnotatorsBox.SelectedItem == null) { annotator = ((List <DatabaseAnnotator>)AnnotatorsBox.ItemsSource).Find(a => a.Name == Defaults.CML.GoldStandardName); if (annotator != null) { AnnotatorsBox.SelectedItem = annotator; } } // select first if (AnnotatorsBox.SelectedItem == null) { AnnotatorsBox.SelectedIndex = 0; } AnnotatorsBox.ScrollIntoView(AnnotatorsBox.SelectedItem); } }
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; }
private void EditAnnotator_Click(object sender, RoutedEventArgs e) { if (AnnotatorsBox.SelectedItem != null) { string user = (string)AnnotatorsBox.SelectedItem; DatabaseAnnotator annotator = new DatabaseAnnotator { Name = user }; if (DatabaseHandler.GetAnnotator(ref annotator)) { DatabaseAdminAnnotatorWindow dialog = new DatabaseAdminAnnotatorWindow(ref annotator); dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.ShowDialog(); if (dialog.DialogResult == true) { DatabaseHandler.AddOrUpdateAnnotator(annotator); GetAnnotators(); } } } }
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; } }
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(); } }