Esempio n. 1
0
 public Line(string internalId, bool unified = true, params Line[] lines)
 {
     Sanity.Requires(lines.Length > 0, "Merge lines requires at least one line(s).");
     CorpusName    = lines[0].CorpusName;
     SpeakerId     = unified ? lines[0].SpeakerId : "U";
     ScenarioId    = lines[0].ScenarioId;
     InternalId    = internalId;
     Transcription = string.Join(" ", lines.Select(x => x.Transcription));
 }
Esempio n. 2
0
 public TextGridItem(TextGridItem item)
 {
     Sanity.Requires(Type == item.Type, "The two TextGridItem are different.");
     TierIndex = item.TierIndex;
     Index     = item.Index;
     Name      = item.Name;
     IsSet     = item.IsSet;
     Text      = item.Text;
 }
Esempio n. 3
0
        public static string GetXmlAttribute(this XmlNode node, params string[] nameList)
        {
            Sanity.Requires(node != null, "The base node is null.");
            Sanity.Requires(nameList.Length > 1, "The name list has to be longer than 1.");
            XmlNode currentNode = node;

            foreach (string name in nameList.Take(nameList.Length - 1))
            {
                currentNode = currentNode[name];
                Sanity.Requires(currentNode != null, $"The node {name} does not exist.");
            }
            return(currentNode[nameList.Last()].Value);
        }
Esempio n. 4
0
        protected override void Set(string line)
        {
            var split = line.Split('\t');

            Sanity.RequiresLine(split.Length == 8, "TcLine");
            CorpusName    = split[0];
            SpeakerId     = split[1];
            ScenarioId    = split[2];
            InternalId    = split[3];
            StartTime     = double.Parse(split[4]);
            EndTime       = double.Parse(split[5]);
            Transcription = split[6];
            SrcAudioPath  = split[7];
        }
Esempio n. 5
0
        private IEnumerable <string> OutputTierHeader(double xmin, double xmax, List <TextGridItem> list, string tabOffset)
        {
            Sanity.Requires(list.Count > 0, "The tier is empty.");
            var    first = list[0];
            string classLine, sizeLine;

            switch (first.Type)
            {
            case TextGridItemType.Interval:
                classLine = $"{tabOffset}\tclass = \"IntervalTier\"";
                sizeLine  = $"{tabOffset}\tintervals: size = {list.Count}";
                break;

            case TextGridItemType.Point:
                classLine = $"{tabOffset}\tclass = \"TextTier\"";
                sizeLine  = $"{tabOffset}\tpoints: size = {list.Count}";
                break;

            default:
                throw new TangInfrastructureException("Invalid text grid type: " + first.Type.ToString());
            }
            yield return($"{tabOffset}item [{first.TierIndex}]:");

            yield return(classLine);

            yield return($"{tabOffset}\tname = \"{first.Name}\"");

            yield return($"{tabOffset}\txmin = {xmin}");

            yield return($"{tabOffset}\txmax = {xmax}");

            yield return(sizeLine);

            var outputList = list.SelectMany(x => x.ToTextGrid(tabOffset + "\t"));

            foreach (string line in outputList)
            {
                yield return(line);
            }
        }
Esempio n. 6
0
 public static void ArrayPlace <T>(this T[] bigArray, T[] smallArray, int index)
 {
     Sanity.Requires(index >= 0, "Index cannot be less than 0.");
     Sanity.Requires(smallArray.Length + index <= bigArray.Length, "Index out of range.");
     Array.Copy(smallArray, 0, bigArray, index, smallArray.Length);
 }
Esempio n. 7
0
        private IEnumerable <TextGridItem> Parse(IEnumerable <string> list)
        {
            TextGridItem     currentItem     = new TextGridItem();
            TextGridInterval currentInterval = new TextGridInterval();
            TextGridPoint    currentText     = new TextGridPoint();
            int    currentTier = 0;
            string currentName = string.Empty;
            bool   inInterval  = false;
            bool   inHeader    = true;

            foreach (string line in list)
            {
                if (InItemListReg.IsMatch(line))
                {
                    currentTier           = int.Parse(InItemListReg.Match(line).Groups[1].Value);
                    currentItem.TierIndex = currentTier;
                    inHeader = false;
                    continue;
                }
                if (inHeader)
                {
                    Header.Add(line);
                }
                if (NameReg.IsMatch(line))
                {
                    currentName      = NameReg.Match(line).Groups[1].Value;
                    currentItem.Name = currentName;
                    continue;
                }

                if (IntervalReg.IsMatch(line))
                {
                    inInterval            = true;
                    currentItem.Index     = int.Parse(IntervalReg.Match(line).Groups[1].Value);
                    currentInterval       = new TextGridInterval(currentItem);
                    currentInterval.IsSet = true;
                    currentItem           = new TextGridItem {
                        Name = currentName, TierIndex = currentTier
                    };
                    continue;
                }
                if (line.Trim().StartsWith("xmin") && inInterval)
                {
                    Sanity.Requires(currentInterval.IsSet, "Invalid format.");
                    currentInterval.XMin = double.Parse(line.Split('=')[1].Trim());
                    continue;
                }
                if (line.Trim().StartsWith("xmax") && inInterval)
                {
                    Sanity.Requires(currentInterval.IsSet, "Invalid format.");
                    currentInterval.XMax = double.Parse(line.Split('=')[1].Trim());
                    continue;
                }
                if (line.Trim().StartsWith("text"))
                {
                    Sanity.Requires(currentInterval.IsSet, "Invalid format.");
                    currentInterval.Text = line.Split('=')[1].Trim(Trims);
                    inInterval           = false;
                    yield return(currentInterval);

                    continue;
                }

                if (PointReg.IsMatch(line))
                {
                    currentItem.Index = int.Parse(PointReg.Match(line).Groups[1].Value);
                    currentText       = new TextGridPoint(currentItem);
                    currentText.IsSet = true;
                    currentItem       = new TextGridItem {
                        Name = currentName, TierIndex = currentTier
                    };
                }
                if (line.Trim().StartsWith("number"))
                {
                    Sanity.Requires(currentText.IsSet, "Invalid format");
                    currentText.Point = double.Parse(line.Split('=')[1].Trim(Trims));
                    continue;
                }
                if (line.Trim().StartsWith("mark"))
                {
                    Sanity.Requires(currentText.IsSet, "Invalid format");
                    currentText.Text = line.Split('=')[1].Trim(Trims);
                    yield return(currentText);

                    continue;
                }
            }
        }