Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This will build a list of ambiguous sequences that's in order of their length and
        /// will include the tone letters as well. The order is longest to shortest with those
        /// with the same lengths, staying in the order in which the user entered them in the
        /// Phone Inventory view.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void BuildSortedAmbiguousSequencesList()
        {
            _sortedAmbiguousSeqList = new AmbiguousSequences();

            // Copy the references from the specified list to our own.
            if (_unsortedAmbiguousSeqList != null)
            {
                foreach (var seq in _unsortedAmbiguousSeqList)
                {
                    _sortedAmbiguousSeqList.Add(seq);
                }
            }

            // Go through the tone letters collection and add them to the ambiguous list.
            // Tone letters are special in that they're the only IPA characters in the
            // cache that are made up of multiple code points. When it comes to parsing a
            // phonetic string into its phones, tone letters need to be treated as
            // ambiguous sequences.
            if (App.IPASymbolCache.ToneLetters != null)
            {
                foreach (var info in App.IPASymbolCache.ToneLetters.Values.Where(info =>
                                                                                 !_sortedAmbiguousSeqList.ContainsSeq(info.Literal, true)))
                {
                    _sortedAmbiguousSeqList.Add(new AmbiguousSeq(info.Literal));
                }
            }

            // Now order the items in the list based on the length
            // of the ambiguous sequence -- longest to shortest.
            _sortedAmbiguousSeqList.SortByUnitLength();
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructs a new phone information object for the specified phone.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public PhoneInfo(AmbiguousSequences ambiguousSequences, string phone, bool isUndefined)
        {
            _ambiguousSequences  = ambiguousSequences;
            SiblingUncertainties = new List <string>();
            CharType             = IPASymbolType.notApplicable;
            Phone       = phone;
            IsUndefined = isUndefined;

            if (!string.IsNullOrEmpty(phone))
            {
                InitializeBaseChar(phone);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Saves the list of ambiguous sequences to a project-specific xml file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Save(string pathPrefix)
        {
            var tmpList = new AmbiguousSequences(this);

            // Before saving, make sure there are no empty or null units
            // and get rid of those sequences that were added automatically.
            for (int i = tmpList.Count - 1; i >= 0; i--)
            {
                string unit = tmpList[i].Literal;
                if (unit == null || unit.Trim().Length == 0)
                {
                    tmpList.RemoveAt(i);
                }
            }

            XmlSerializationHelper.SerializeToFile(pathPrefix + kFileName, tmpList);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Constructs a new phone information object for the specified phone.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public PhoneInfo(AmbiguousSequences ambiguousSequences, string phone)
     : this(ambiguousSequences, phone, false)
 {
 }
Example #5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Use this only for tests.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void ResetAmbiguousSequencesForTests()
 {
     _sortedAmbiguousSeqList = null;
 }
Example #6
0
 /// ------------------------------------------------------------------------------------
 public PhoneticParser(AmbiguousSequences ambigSeqs, TranscriptionChanges transChanges)
 {
     _unsortedAmbiguousSeqList = ambigSeqs ?? new AmbiguousSequences();
     BuildSortedAmbiguousSequencesList();
     _transcriptionChanges = transChanges;
 }