Exemplo n.º 1
0
        public static bool Import(Stream input, Transcription storage)
        {
            XDocument doc = XDocument.Load(input);
            var root = doc.Element("NanovoidSegmentation");

            var mediums = root.Elements("Medium").ToArray();

            XElement medium = null;
            if (mediums.Length > 1)
            {
                SelectFile sf = new SelectFile(mediums.Select(m => m.Attribute("url") != null ? Path.GetFileName(m.Attribute("url").Value) : "name not specified").ToList());
                sf.Title = "Select Medium";
                if (sf.ShowDialog() == true)
                {
                    medium = mediums[sf.SelectedIndex];
                }
                else return false;
            }
            else
                medium = mediums.First();

            var segmentations = medium.Elements("Segmentation").ToArray();

            XElement segmentation = null;
            if (segmentations.Length > 1)
            {
                var lst = segmentations.Select(s => string.Join(" ", s.Attributes().Select(a => a.Name + ":" + a.Value))).ToList();
                SelectFile sf = new SelectFile(lst);
                sf.Title = "Select segmentation";
                if (sf.ShowDialog() == true)
                {
                    segmentation = segmentations[sf.SelectedIndex];
                }
                else return false;
            }
            else
                segmentation = segmentations.First();

            TimeSpan unitlen = new TimeSpan((long)(TimeSpan.FromSeconds(1).Ticks * XmlConvert.ToDouble(segmentation.Attribute("tres").Value)));
            //segmentations.Elements("Segment");

            Transcription tr = storage;
            TranscriptionChapter ch = new TranscriptionChapter();
            ch.Text = segmentation.Attribute("type").Value;

            TranscriptionSection sec = new TranscriptionSection();
            sec.Text = segmentation.Attribute("label").Value;

            tr.MediaURI = medium.Attribute("url")!=null?medium.Attribute("url").Value:"";

            var idss = segmentation.Element("Identities");
            if (idss != null)
            {
                var ids = idss.Elements("Id");
                if (ids != null && ids.Count() > 0)
                {
                    var speakers = ids.Select(i => new Speaker() { ID = XmlConvert.ToInt32(i.Attribute("id").Value), Surname = i.Attribute("label").Value });
                    tr.Speakers = new SpeakerCollection(speakers);
                }
            }

            var segments = segmentation.Element("Segments").Elements("Segment");

            var paragraphs = MakeParagraphs(segments, unitlen);

            foreach (var p in paragraphs)
                sec.Add(p);

            ch.Add(sec);
            tr.Add(ch);

               tr.AssingSpeakersByID(); //added in newer version

            return true;
        }
Exemplo n.º 2
0
        public static bool Import(Stream input, Transcription storage)
        {
            XDocument doc  = XDocument.Load(input);
            var       root = doc.Element("NanovoidSegmentation");

            var mediums = root.Elements("Medium").ToArray();

            XElement medium = null;

            if (mediums.Length > 1)
            {
                SelectFile sf = new SelectFile(mediums.Select(m => m.Attribute("url") != null ? Path.GetFileName(m.Attribute("url").Value) : "name not specified").ToList());
                sf.Title = "Select Medium";
                if (sf.ShowDialog() == true)
                {
                    medium = mediums[sf.SelectedIndex];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                medium = mediums.First();
            }

            var segmentations = medium.Elements("Segmentation").ToArray();

            XElement segmentation = null;

            if (segmentations.Length > 1)
            {
                var        lst = segmentations.Select(s => string.Join(" ", s.Attributes().Select(a => a.Name + ":" + a.Value))).ToList();
                SelectFile sf  = new SelectFile(lst);
                sf.Title = "Select segmentation";
                if (sf.ShowDialog() == true)
                {
                    segmentation = segmentations[sf.SelectedIndex];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                segmentation = segmentations.First();
            }

            TimeSpan unitlen = new TimeSpan((long)(TimeSpan.FromSeconds(1).Ticks *XmlConvert.ToDouble(segmentation.Attribute("tres").Value)));
            //segmentations.Elements("Segment");

            Transcription        tr = storage;
            TranscriptionChapter ch = new TranscriptionChapter();

            ch.Text = segmentation.Attribute("type").Value;

            TranscriptionSection sec = new TranscriptionSection();

            sec.Text = segmentation.Attribute("label").Value;

            tr.MediaURI = medium.Attribute("url") != null?medium.Attribute("url").Value : "";

            var idss = segmentation.Element("Identities");

            if (idss != null)
            {
                var ids = idss.Elements("Id");
                if (ids != null && ids.Count() > 0)
                {
                    var speakers = ids.Select(i => new Speaker()
                    {
                        ID = XmlConvert.ToInt32(i.Attribute("id").Value), Surname = i.Attribute("label").Value
                    });
                    tr.Speakers = new SpeakerCollection(speakers);
                }
            }

            var segments = segmentation.Element("Segments").Elements("Segment");

            var paragraphs = MakeParagraphs(segments, unitlen);

            foreach (var p in paragraphs)
            {
                sec.Add(p);
            }

            ch.Add(sec);
            tr.Add(ch);


            tr.AssingSpeakersByID(); //added in newer version



            return(true);
        }