Example #1
0
        private void ResampleScheme_Click(object sender, RoutedEventArgs e)
        {
            if (SchemesBox.SelectedItem != null)
            {
                string     name      = (string)SchemesBox.SelectedItem;
                AnnoScheme oldScheme = DatabaseHandler.GetAnnotationScheme(name);
                AnnoScheme newScheme = DatabaseHandler.GetAnnotationScheme(name);
                if (newScheme.Type != AnnoScheme.TYPE.CONTINUOUS)
                {
                    MessageBox.Show("Only continuous annotations can be resampled");
                    return;
                }



                newScheme.Name = newScheme.Name + "_resampled";
                AnnoTierNewContinuousSchemeWindow window = new AnnoTierNewContinuousSchemeWindow(ref newScheme);
                window.ShowDialog();

                if (window.DialogResult == true)
                {
                    if (DatabaseHandler.AddScheme(newScheme))
                    {
                        List <DatabaseAnnotation> existingAnnos = DatabaseHandler.GetAnnotations(oldScheme);

                        if (existingAnnos.Count > 0)
                        {
                            AnnoList al_t   = DatabaseHandler.LoadAnnoList(existingAnnos[0].Id);
                            double   old_sr = al_t.Scheme.SampleRate;
                            double   factor = 0;

                            if (old_sr > newScheme.SampleRate)
                            {
                                factor = old_sr / newScheme.SampleRate;
                            }
                            else if (old_sr < newScheme.SampleRate)
                            {
                                factor = newScheme.SampleRate / old_sr;
                            }

                            else
                            {
                                factor = 1;
                            }


                            if (factor % 1 != 0)
                            {
                                MessageBox.Show("New samplerate must be a number divisible by old samplerate.");
                                return;
                            }


                            foreach (DatabaseAnnotation anno in existingAnnos)
                            {
                                AnnoList al = DatabaseHandler.LoadAnnoList(anno.Id);
                                DatabaseHandler.resampleAnnotationtoNewScheme(al, newScheme, al_t.Scheme);
                            }

                            GetSchemes();
                        }
                        else
                        {
                            MessageBox.Show("Scheme created, but no existing Annotations found, nothing was converted.");
                        }
                    }
                }
            }
        }
Example #2
0
        public static AnnoScheme GetAnnotationScheme(string annoName, AnnoScheme.TYPE annoType)
        {
            MongoClient    mongo    = new MongoClient(ServerConnectionString);
            IMongoDatabase database = mongo.GetDatabase(Properties.Settings.Default.DatabaseName);

            AnnoScheme scheme = new AnnoScheme();

            scheme.Type = annoType;

            var annoSchemes = database.GetCollection <BsonDocument>(DatabaseDefinitionCollections.Schemes);
            var builder     = Builders <BsonDocument> .Filter;

            FilterDefinition <BsonDocument> annoSchemeFilter = builder.Eq("name", annoName) & builder.Eq("type", annoType.ToString());
            BsonDocument annoSchemeDocument = null;

            try
            {
                annoSchemeDocument = annoSchemes.Find(annoSchemeFilter).Single();
                if (annoSchemeDocument["type"].ToString() == annoType.ToString())
                {
                    scheme.Name = annoSchemeDocument["name"].ToString();
                    if (scheme.Type == AnnoScheme.TYPE.CONTINUOUS)
                    {
                        scheme.MinScore       = annoSchemeDocument["min"].ToDouble();
                        scheme.MaxScore       = annoSchemeDocument["max"].ToDouble();
                        scheme.SampleRate     = annoSchemeDocument["sr"].ToDouble();
                        scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annoSchemeDocument["min_color"].ToString());
                        scheme.MaxOrForeColor = (Color)ColorConverter.ConvertFromString(annoSchemeDocument["max_color"].ToString());
                    }
                    else if (scheme.Type == AnnoScheme.TYPE.DISCRETE)
                    {
                        scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annoSchemeDocument["color"].ToString());
                        BsonArray schemeLabelsArray = annoSchemeDocument["labels"].AsBsonArray;
                        string    SchemeLabel       = "";
                        string    SchemeColor       = "#000000";
                        for (int j = 0; j < schemeLabelsArray.Count; j++)
                        {
                            try
                            {
                                if (schemeLabelsArray[j]["isValid"].AsBoolean == true)
                                {
                                    SchemeLabel = schemeLabelsArray[j]["name"].ToString();
                                    SchemeColor = schemeLabelsArray[j]["color"].ToString();
                                    AnnoScheme.Label lcp = new AnnoScheme.Label(schemeLabelsArray[j]["name"].ToString(), (Color)ColorConverter.ConvertFromString(schemeLabelsArray[j]["color"].ToString()));
                                    scheme.Labels.Add(lcp);
                                }
                            }
                            catch
                            {
                                SchemeLabel = schemeLabelsArray[j]["name"].ToString();
                                SchemeColor = schemeLabelsArray[j]["color"].ToString();
                                AnnoScheme.Label lcp = new AnnoScheme.Label(schemeLabelsArray[j]["name"].ToString(), (Color)ColorConverter.ConvertFromString(schemeLabelsArray[j]["color"].ToString()));
                                scheme.Labels.Add(lcp);
                            }
                        }
                    }
                    else if (scheme.Type == AnnoScheme.TYPE.FREE)
                    {
                        scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annoSchemeDocument["color"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageTools.Warning(ex.ToString());
            }

            return(scheme);
        }
Example #3
0
        public static List <AnnoList> LoadfromElanFile(String filepath)
        {
            List <AnnoList> list = new List <AnnoList>();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filepath);


                //Get time order references

                XmlNode time_order = doc.SelectSingleNode("//TIME_ORDER");
                List <KeyValuePair <string, string> > time_order_list = new List <KeyValuePair <string, string> >();
                foreach (XmlNode node in time_order.ChildNodes)
                {
                    time_order_list.Add(new KeyValuePair <string, string>(node.Attributes[0].Value.ToString(), node.Attributes[1].Value.ToString()));
                }


                //Get number of tiers

                int i = 0;
                foreach (XmlNode tier in doc.SelectNodes("//TIER"))
                {
                    AnnoList   al     = new AnnoList();
                    AnnoScheme scheme = new AnnoScheme();


                    scheme.Type = AnnoScheme.TYPE.FREE;


                    string tierid = tier.Attributes.GetNamedItem("TIER_ID").Value.ToString();

                    string role = "";
                    try
                    {
                        role = tier.Attributes.GetNamedItem("PARTICIPANT").Value.ToString();
                    }
                    catch { }


                    al = new AnnoList();
                    al.Source.File.Path = filepath;

                    foreach (XmlNode annotation in tier.ChildNodes)
                    {
                        string  label                = null;
                        string  starttmp             = "";
                        string  endtmp               = "";
                        double  start                = -1;
                        double  end                  = -1;
                        double  duration             = -1;
                        XmlNode alignable_annotation = annotation.FirstChild;

                        starttmp = (from kvp in time_order_list where kvp.Key == alignable_annotation.Attributes.GetNamedItem("TIME_SLOT_REF1").Value.ToString() select kvp.Value).ToList()[0];
                        start    = double.Parse(starttmp, CultureInfo.InvariantCulture) / 1000;
                        endtmp   = (from kvp in time_order_list where kvp.Key == alignable_annotation.Attributes.GetNamedItem("TIME_SLOT_REF2").Value.ToString() select kvp.Value).ToList()[0];
                        end      = double.Parse(endtmp, CultureInfo.InvariantCulture) / 1000;
                        label    = alignable_annotation.FirstChild.InnerText;
                        AnnoScheme.Label l = new AnnoScheme.Label(label, Colors.Black);


                        if (scheme.Type == AnnoScheme.TYPE.DISCRETE && scheme.Labels.Find(x => x.Name == label) == null)
                        {
                            scheme.Labels.Add(l);
                        }


                        duration = end - start;
                        al.AddSorted(new AnnoListItem(start, duration, label, "", Colors.Black));


                        //The tier is used as metainformation as well. Might be changed if thats relevant in the future
                    }
                    i++;

                    al.Scheme      = scheme;
                    al.Meta.Role   = role;
                    al.Scheme.Name = tierid;

                    list.Add(al);
                }
            }
            catch (Exception ex)
            {
                MessageTools.Error(ex.ToString());
            }

            return(list);
        }
Example #4
0
        private void navigatorNewAnno_Click(object sender, RoutedEventArgs e)
        {
            if (Time.TotalDuration > 0)
            {
                AnnoTierNewSchemeWindow dialog = new AnnoTierNewSchemeWindow();
                dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                dialog.ShowDialog();

                if (dialog.DialogResult == true)
                {
                    AnnoScheme.TYPE annoType = dialog.Result();

                    if (DatabaseLoaded)
                    {
                        databaseAddNewAnnotation(annoType);
                    }
                    else
                    {
                        if (annoType == AnnoScheme.TYPE.FREE)
                        {
                            AnnoTierNewFreeSchemeWindow dialog2 = new AnnoTierNewFreeSchemeWindow();
                            dialog2.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            dialog2.ShowDialog();

                            if (dialog2.DialogResult == true)
                            {
                                AnnoScheme annoScheme = dialog2.Result;
                                AnnoList   annoList   = new AnnoList()
                                {
                                    Scheme = annoScheme
                                };
                                addAnnoTier(annoList);
                            }
                        }
                        else if (annoType == AnnoScheme.TYPE.DISCRETE)
                        {
                            AnnoTierNewDiscreteSchemeWindow dialog2 = new AnnoTierNewDiscreteSchemeWindow();
                            dialog2.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            dialog2.ShowDialog();

                            if (dialog2.DialogResult == true)
                            {
                                AnnoList annoList = dialog2.GetAnnoList();
                                addAnnoTier(annoList);
                            }
                        }
                        else if (annoType == AnnoScheme.TYPE.CONTINUOUS)
                        {
                            double defaultSr = 25.0;

                            foreach (IMedia m in mediaList.Medias)
                            {
                                if (m.IsVideo())
                                {
                                    defaultSr = m.GetSampleRate();
                                    break;
                                }
                            }

                            AnnoTierNewContinuousSchemeWindow.Input input = new AnnoTierNewContinuousSchemeWindow.Input()
                            {
                                SampleRate = defaultSr, MinScore = 0.0, MaxScore = 1.0, MinColor = Colors.LightBlue, MaxColor = Colors.Red
                            };
                            AnnoTierNewContinuousSchemeWindow dialog2 = new AnnoTierNewContinuousSchemeWindow(input);
                            dialog2.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            dialog2.ShowDialog();
                            if (dialog2.DialogResult == true)
                            {
                                AnnoScheme annoScheme = dialog2.Result;
                                AnnoList   annoList   = new AnnoList()
                                {
                                    Scheme = annoScheme
                                };
                                addAnnoTier(annoList);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageTools.Warning("Nothing to annotate, load some data first.");
            }
        }