コード例 #1
0
        private void AddStream_Click(object sender, RoutedEventArgs e)
        {
            Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();

            input["name"] = new UserInputWindow.Input()
            {
                Label = "Name", DefaultValue = ""
            };
            input["fileExt"] = new UserInputWindow.Input()
            {
                Label = "File extension", DefaultValue = ""
            };
            input["type"] = new UserInputWindow.Input()
            {
                Label = "Type", DefaultValue = ""
            };
            input["sr"] = new UserInputWindow.Input()
            {
                Label = "Sample rate", DefaultValue = ""
            };
            UserInputWindow dialog = new UserInputWindow("Add new stream type", input);

            dialog.ShowDialog();
            if (dialog.DialogResult == true)
            {
                string name    = dialog.Result("name");
                string fileExt = dialog.Result("fileExt");
                string type    = dialog.Result("type");
                double sr      = 25.0;
                double.TryParse(dialog.Result("sr"), out sr);
                DatabaseStream streamType = new DatabaseStream()
                {
                    Name = name, FileExt = fileExt, Type = type, SampleRate = sr
                };
                if (DatabaseHandler.AddStream(streamType))
                {
                    GetStreamTypes(dialog.Result("name"));
                }
            }
        }
コード例 #2
0
        private void Extract()
        {
            if (ChainsBox.SelectedItem == null)
            {
                MessageTools.Warning("select a chain first");
                return;
            }

            string featureName = FeatureNameTextBox.Text;

            if (featureName == "" || featureName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                MessageTools.Warning("not a valid feature name");
                return;
            }

            Chain chain = (Chain)ChainsBox.SelectedItem;
            bool  force = ForceCheckBox.IsChecked.Value;

            if (!File.Exists(chain.Path))
            {
                MessageTools.Warning("file does not exist '" + chain.Path + "'");
                return;
            }

            string         database = DatabaseHandler.DatabaseName;
            var            sessions = SessionsBox.SelectedItems;
            var            roles    = RolesBox.SelectedItems;
            DatabaseStream stream   = (DatabaseStream)StreamsBox.SelectedItem;

            string leftContext  = LeftContextTextBox.Text;
            string frameStep    = FrameStepTextBox.Text;
            string rightContext = RightContextTextBox.Text;

            int nParallel = 1;

            int.TryParse(NParallelTextBox.Text, out nParallel);

            logTextBox.Text = "";

            // prepare lists

            int nFiles = 0;

            using (StreamWriter fileListIn = new StreamWriter(tempInListPath))
            {
                using (StreamWriter fileListOut = new StreamWriter(tempOutListPath))
                {
                    foreach (DatabaseSession session in sessions)
                    {
                        foreach (DatabaseRole role in roles)
                        {
                            string fromPath = Properties.Settings.Default.DatabaseDirectory + "\\"
                                              + database + "\\"
                                              + session.Name + "\\"
                                              + role.Name + "." + stream.Name + "." + stream.FileExt;

                            string toPath = Path.GetDirectoryName(fromPath) + "\\"
                                            + role.Name + "." + featureName + ".stream";

                            if (force || !File.Exists(toPath))
                            {
                                nFiles++;
                                fileListIn.WriteLine(fromPath);
                                fileListOut.WriteLine(toPath);
                            }
                            else
                            {
                                logTextBox.Text += "skip " + fromPath + "\n";
                            }
                        }
                    }
                }
            }

            // start feature extraction

            Chain          selectedChain  = (Chain)ChainsBox.SelectedItem;
            DatabaseStream selectedStream = (DatabaseStream)StreamsBox.SelectedItem;

            if (nFiles > 0)
            {
                string type = Defaults.CML.StreamTypeNameFeature;
                string name = featureName;
                string ext  = "stream";

                double sr = frameStepToSampleRate(frameStep, stream.SampleRate);

                DatabaseStream streamType = new DatabaseStream()
                {
                    Name = name, Type = type, FileExt = ext, SampleRate = sr
                };
                DatabaseHandler.AddStream(streamType);
                try
                {
                    logTextBox.Text += handler.CMLExtractFeature(chain.Path, nParallel, tempInListPath, tempOutListPath, frameStep, leftContext, rightContext);
                }
                catch (Exception e) { MessageBox.Show("There was an error in the feature extaction pipeline: " + e); }
            }

            File.Delete(tempInListPath);
            File.Delete(tempOutListPath);

            GetStreams(selectedStream);
            foreach (Chain item in ChainsBox.Items)
            {
                if (item.Name == selectedChain.Name)
                {
                    ChainsBox.SelectedItem = item;
                    break;
                }
            }
        }
コード例 #3
0
        private void Merge()
        {
            string featureName = FeatureNameTextBox.Text;

            if (featureName == "" || featureName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                MessageTools.Warning("not a valid feature name");
                return;
            }

            string database = (string)DatabasesBox.SelectedItem;

            var  sessions = SessionsBox.SelectedItems;
            var  roles    = RolesBox.SelectedItems;
            var  streams  = StreamsBox.SelectedItems;
            bool force    = ForceCheckBox.IsChecked.Value;

            string sessionList = "";

            foreach (DatabaseSession session in sessions)
            {
                if (sessionList == "")
                {
                    sessionList = session.Name;
                }
                else
                {
                    sessionList += ";" + session.Name;
                }
            }

            string roleList = "";

            foreach (var role in roles)
            {
                if (roleList == "")
                {
                    roleList = ((DatabaseRole)role).Name;
                }
                else
                {
                    roleList += ";" + ((DatabaseRole)role).Name;
                }
            }

            string[] streamsNames = new string[streams.Count];
            int      i            = 0;

            foreach (DatabaseStream stream in streams)
            {
                streamsNames[i++] = stream.Name;
            }
            Array.Sort(streamsNames);

            string streamList = "";
            double sampleRate = ((DatabaseStream)streams[0]).SampleRate;

            foreach (string stream in streamsNames)
            {
                if (streamList == "")
                {
                    streamList = stream;
                }
                else
                {
                    streamList += ";" + stream;
                }
            }

            string rootDir = Properties.Settings.Default.DatabaseDirectory + "\\" + database;

            logTextBox.Text = handler.CMLMergeFeature(rootDir, sessionList, roleList, streamList, featureName, force);

            string type = Defaults.CML.StreamTypeNameFeature;
            string ext  = "stream";

            DatabaseStream streamType = new DatabaseStream()
            {
                Name = featureName, Type = type, FileExt = ext, SampleRate = sampleRate
            };

            DatabaseHandler.AddStream(streamType);

            GetStreams(streamType);
        }