Ejemplo n.º 1
0
        public void ValidatePhEnvironment_StringRepresentation()
        {
            // Add a character to the set of phoneme representations so that the environment below
            // will pass muster.
            IPhPhonemeSet phset = Cache.ServiceLocator.GetInstance <IPhPhonemeSetFactory>().Create();

            Cache.LanguageProject.PhonologicalDataOA.PhonemeSetsOS.Add(phset);
            AddPhone(phset, "a");
            AddPhone(phset, "b");
            AddPhone(phset, "c");
            AddPhone(phset, "d");
            AddPhone(phset, "e");

            ConstraintFailure failure = null;
            int            strRepFlid = PhEnvironmentTags.kflidStringRepresentation;
            IPhEnvironment env        = Cache.ServiceLocator.GetInstance <IPhEnvironmentFactory>().Create();

            Cache.LangProject.PhonologicalDataOA.EnvironmentsOS.Add(env);
            IEnumerable <ICmBaseAnnotation> os = GetAnnotationsForObject(env);

            Assert.AreEqual(0, os.Count(), "Wrong starting count of annotations.");

            env.StringRepresentation = Cache.TsStrFactory.MakeString(@"/ [BADCLASS] _", Cache.DefaultAnalWs);
            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNotNull(failure, "Didn't get an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(1, os.Count(), "Wrong invalid count of annotations.");

            env.StringRepresentation = Cache.TsStrFactory.MakeString(@"/ d _", Cache.DefaultAnalWs);
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNull(failure, "Got an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(0, os.Count(), "Wrong valid count of annotations.");
        }
Ejemplo n.º 2
0
		private void AddPhone(IPhPhonemeSet phset, string sCode)
		{
			IPhPhoneme phone = Cache.ServiceLocator.GetInstance<IPhPhonemeFactory>().Create();
			phset.PhonemesOC.Add(phone);
			IPhCode code;
			if (phone.CodesOS.Count == 0)
			{
				code = Cache.ServiceLocator.GetInstance<IPhCodeFactory>().Create();
				phone.CodesOS.Add(code);
			}
			else
			{
				code = phone.CodesOS[0];
			}
			code.Representation.set_String(Cache.DefaultVernWs, sCode);
		}
Ejemplo n.º 3
0
        public void ValidatePhEnvironment_StringRepresentation()
        {
            // Add a character to the set of phoneme representations so that the environment below
            // will pass muster.
            IPhPhonemeSet phset = Cache.ServiceLocator.GetInstance <IPhPhonemeSetFactory>().Create();

            Cache.LanguageProject.PhonologicalDataOA.PhonemeSetsOS.Add(phset);
            AddPhone(phset, "a");
            AddPhone(phset, "b");
            AddPhone(phset, "c");
            AddPhone(phset, "d");
            AddPhone(phset, "e");

            ConstraintFailure failure = null;
            int            strRepFlid = PhEnvironmentTags.kflidStringRepresentation;
            IPhEnvironment env        = Cache.ServiceLocator.GetInstance <IPhEnvironmentFactory>().Create();

            Cache.LangProject.PhonologicalDataOA.EnvironmentsOS.Add(env);
            IEnumerable <ICmBaseAnnotation> os = GetAnnotationsForObject(env);

            Assert.AreEqual(0, os.Count(), "Wrong starting count of annotations.");

            env.StringRepresentation = TsStringUtils.MakeString(@"/ [BADCLASS] _", Cache.DefaultAnalWs);

            m_actionHandler.EndUndoTask();             // so we can verify it makes its own as needed, and doesn't do unnecessary ones.

            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNotNull(failure, "Didn't get an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(1, os.Count(), "Wrong invalid count of annotations.");

            int cUndoTasks = m_actionHandler.UndoableActionCount;

            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.That(m_actionHandler.UndoableActionCount, Is.EqualTo(cUndoTasks), "should not make database changes when situation is unchanged");

            NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
                                           env.StringRepresentation = TsStringUtils.MakeString(@"/ d _", Cache.DefaultAnalWs));
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNull(failure, "Got an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(0, os.Count(), "Wrong valid count of annotations.");

            cUndoTasks = m_actionHandler.UndoableActionCount;
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.That(m_actionHandler.UndoableActionCount, Is.EqualTo(cUndoTasks), "should not make database changes when situation is unchanged");
        }
Ejemplo n.º 4
0
        private void AddPhone(IPhPhonemeSet phset, string sCode)
        {
            IPhPhoneme phone = Cache.ServiceLocator.GetInstance <IPhPhonemeFactory>().Create();

            phset.PhonemesOC.Add(phone);
            IPhCode code;

            if (phone.CodesOS.Count == 0)
            {
                code = Cache.ServiceLocator.GetInstance <IPhCodeFactory>().Create();
                phone.CodesOS.Add(code);
            }
            else
            {
                code = phone.CodesOS[0];
            }
            code.Representation.set_String(Cache.DefaultVernWs, sCode);
        }
Ejemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Assign the Vernacular writing system to all default PhCodes and PhPhoneme Names.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void AssignVernacularWritingSystemToDefaultPhPhonemes(FdoCache cache)
        {
            // For all PhCodes in the default phoneme set, change the writing system from "en" to icuLocale
            IPhPhonemeSet phSet = cache.LangProject.PhonologicalDataOA.PhonemeSetsOS[0];

            foreach (IPhPhoneme phone in phSet.PhonemesOC)
            {
                foreach (IPhCode code in phone.CodesOS)
                {
                    code.Representation.VernacularDefaultWritingSystem = code.Representation.UserDefaultWritingSystem;
                }
                phone.Name.VernacularDefaultWritingSystem = phone.Name.UserDefaultWritingSystem;
            }
            foreach (IPhBdryMarker mrkr in phSet.BoundaryMarkersOC)
            {
                foreach (IPhCode code in mrkr.CodesOS)
                {
                    code.Representation.VernacularDefaultWritingSystem = code.Representation.UserDefaultWritingSystem;
                }
                mrkr.Name.VernacularDefaultWritingSystem = mrkr.Name.UserDefaultWritingSystem;
            }
        }
Ejemplo n.º 6
0
		private static XElement ExportPhonemeSet(IPhPhonemeSet phonemeSet, Icu.UNormalizationMode mode)
		{
			return new XElement("PhPhonemeSet",
								new XAttribute("Id", phonemeSet.Hvo),
								ExportBestAnalysis(phonemeSet.Name, "Name", mode),
								ExportBestAnalysis(phonemeSet.Description, "Description", mode),
								new XElement("Phonemes", from phoneme in phonemeSet.PhonemesOC
														  select ExportPhoneme(phoneme, mode)),
								new XElement("BoundaryMarkers", from marker in phonemeSet.BoundaryMarkersOC
																 select ExportBoundaryMarker(marker, mode)));
		}
Ejemplo n.º 7
0
		IPhBdryMarker IPhBdryMarkerFactory.Create(Guid guid, IPhPhonemeSet owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			int hvo = ((IDataReader) m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();
			int flid = m_cache.MetaDataCache.GetFieldId("PhPhonemeSet", "BoundaryMarkers", false);

			var retval = new PhBdryMarker(m_cache, hvo, guid);
			owner.BoundaryMarkersOC.Add(retval);
			return retval;
		}