Ejemplo n.º 1
0
		public void ResetValidator()
		{
			CheckDisposed();
			m_validator = new PhonEnvRecognizer(PhPhoneme.PhonemeRepresentations(m_fdoCache),
				PhNaturalClass.ClassAbbreviations(m_fdoCache));
		}
Ejemplo n.º 2
0
		public virtual void FixtureSetUp()
		{
			m_per = new PhonEnvRecognizer(m_saSegments, m_saNaturalClasses);
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			base.Dispose(disposing);

			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
				if (m_PhoneEnvReferenceVc != null)
					m_PhoneEnvReferenceVc.Dispose();
			}
			m_validator = null; // TODO: Make m_validator disposable?
			m_realEnvs.Clear();
			m_realEnvs = null;
			m_rootObj = null;
			if (m_tsf != null)
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_tsf);
			m_tsf = null;
			m_silCache = null;
			if (m_vwCache != null)
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_vwCache);
			m_vwCache = null;
			m_PhoneEnvReferenceVc = null;
		}
Ejemplo n.º 4
0
 public virtual void FixtureSetUp()
 {
     m_per = new PhonEnvRecognizer(m_saSegments, m_saNaturalClasses);
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Check the validity of the environemtn string, create a problem report, and
		/// if asked, adjust the string itself to show the validity
		/// </summary>
		/// <param name="flidToCheck">flid to check, or zero, for don't care about the flid.</param>
		/// <param name="failure">an explanation of what constraint failed, if any. Will be null if the method returns true.</param>
		/// <param name="fAdjustSquiggly">whether or not to adjust the string squiggly line</param>
		/// <returns>true, if StringRepresentation is valid, otherwise false.</returns>
		public bool CheckConstraints(int flidToCheck, out ConstraintFailure failure, bool fAdjustSquiggly)
		{
			failure = null;
			bool isValid = true;
			if (flidToCheck == 0
				|| flidToCheck == (int)PhEnvironment.PhEnvironmentTags.kflidStringRepresentation)
			{
				CmBaseAnnotation.RemoveErrorAnnotationsForObject(m_cache, Hvo);
				PhonEnvRecognizer rec = new PhonEnvRecognizer(PhPhoneme.PhonemeRepresentations(m_cache), PhNaturalClass.ClassAbbreviations(m_cache));
				TsStringAccessor strAcc = StringRepresentation;
				ITsString tss = strAcc.UnderlyingTsString;
				ITsStrBldr bldr = tss.GetBldr();
				string strRep = tss.Text;
				if (rec.Recognize(strRep))
				{
					if (fAdjustSquiggly)
					{
						// ClearSquigglyLine
						bldr.SetIntPropValues(0, tss.Length, (int)FwTextPropType.ktptUnderline,
							(int)FwTextPropVar.ktpvEnum, (int)FwUnderlineType.kuntNone);
					}
				}
				else
				{
					int pos;
					string sMessage;
					CreateErrorMessageFromXml(strRep, rec.ErrorMessage, out pos, out sMessage);

					failure = new ConstraintFailure(this, (int)PhEnvironment.PhEnvironmentTags.kflidStringRepresentation,
						sMessage);
					failure.XmlDescription = rec.ErrorMessage;
					if (fAdjustSquiggly)
					{
						// MakeSquigglyLine

						Color col = Color.Red;
						int len = tss.Length;
						bldr.SetIntPropValues(pos, len, (int)FwTextPropType.ktptUnderline,
							(int)FwTextPropVar.ktpvEnum, (int)FwUnderlineType.kuntSquiggle);
						bldr.SetIntPropValues(pos, len, (int)FwTextPropType.ktptUnderColor,
							(int)FwTextPropVar.ktpvDefault, col.R + (col.B * 256 + col.G) * 256);
					}
					isValid = false;
				}
				if (fAdjustSquiggly)
					strAcc.UnderlyingTsString = bldr.GetString();
			}
			return isValid;
		}
Ejemplo n.º 6
0
		/// <summary>
		/// </summary>
		//[Test]
		public void CheckEnvironmentMessages()
		{
			CheckDisposed();

			string[] saSegments = { "a", "ai", "b", "c", "d", "e", "f", "fl", "fr",
									"í",  // single combined Unicode acute i
									"H"
								};
			string[] saNaturalClasses = { "V", "Vowels", "C", "+son", "+lab, +vd", "+ant, -cor, -vd" };

			PhonEnvRecognizer rec = new PhonEnvRecognizer(saSegments, saNaturalClasses);
			string strRep;
			strRep = "/ _ q";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ q': The phoneme which begins 'q' was not found in the set of representations for any Phoneme.");
			strRep = "/ _ aqa";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ aqa': The phoneme which begins 'qa' was not found in the set of representations for any Phoneme.");
			strRep = "/ _ [COP]";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ [COP]': The abbreviation for the class 'COP' was not found in the set of Natural Classes.");
			strRep = "/ [C][V] _ [V][COP]";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ [C][V] _ [V][COP]': The abbreviation for the class 'COP' was not found in the set of Natural Classes.");
			strRep = "/ [C _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ [C _': There is a missing closing square bracket ']' somewhere around here: '_'.");
			strRep = "/ C] _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ C] _': There is a missing opening square bracket '[' somewhere around here: 'C] _'.");
			strRep = "/ (a _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ (a _': There is a missing closing parenthesis ')' somewhere around here: '_'.");
			strRep = "/ a) _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ a) _': There is a missing opening parenthesis '(' somewhere around here: 'a) _'.");
			strRep = " a _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string ' a _': There is some kind of error somewhere around here: ' _'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ a ";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ a ': There is some kind of error somewhere around here: ' a '.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ _ a _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ a _': There is some kind of error somewhere around here: '_'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ b # a _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ b # a _': There is some kind of error somewhere around here: ' a _'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ _ b # a";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ b # a': There is some kind of error somewhere around here: 'a'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ ## a _";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ ## a _': There is some kind of error somewhere around here: ' a _'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
			strRep = "/ _ a ##";
			CheckEnvironmentMessage(rec, strRep, "There is a problem with this environment string '/ _ a ##': There is some kind of error somewhere around here: '#'.  It may be a missing underscore _, two or more underscores, a missing slash /, something beyond a word boundary symbol #, or two or more word boundary symbols at the same edge.");
		}
Ejemplo n.º 7
0
		private static void CheckEnvironmentMessage(PhonEnvRecognizer rec, string strRep, string sExpected)
		{
			if (rec.Recognize(strRep))
				Assert.Fail("Environment '" + strRep + "' should fail, but did not");
			else
			{
				int pos;
				string sMessage;
				PhEnvironment.CreateErrorMessageFromXml(strRep, rec.ErrorMessage, out pos, out sMessage);
				Assert.AreEqual(sExpected, sMessage);
			}
		}
Ejemplo n.º 8
0
		private void LoadParser(XDocument model)
		{
			string hcPath = HcInputPath;
			File.Delete(hcPath); // In case we don't produce one successfully, don't keep an old one.
			// Check for errors that will prevent the transformations working.
			using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance<IWorkerThreadReadHandler>()))
			{
				foreach (var affix in m_cache.ServiceLocator.GetInstance<IMoAffixAllomorphRepository>().AllInstances())
				{
					string form = affix.Form.VernacularDefaultWritingSystem.Text;
					if (String.IsNullOrEmpty(form) || form == "[...]" || !form.Contains("["))
						continue;
					string environment = "/_" + form;
					// A form containing a reduplication expression should look like an environment
					var validator = new PhonEnvRecognizer(
						m_cache.LangProject.PhonologicalDataOA.AllPhonemes().ToArray(),
						m_cache.LangProject.PhonologicalDataOA.AllNaturalClassAbbrs().ToArray());
					if (!validator.Recognize(environment))
					{
						m_loader.Reset(); // make sure nothing thinks it is in a useful state
						throw new InvalidReduplicationEnvironmentException(validator.ErrorMessage, form);
					}
				}
			}

			m_transformer.MakeHCFiles(model);

			m_patr.LoadGrammarFile(HcGrammarPath);

			LoadHCInfo(hcPath);

			XElement delReappsElem = model.Elements("M3Dump").Elements("ParserParameters").Elements("HC").Elements("DelReapps").FirstOrDefault();
			if (delReappsElem != null)
				m_loader.CurrentMorpher.DelReapplications = (int) delReappsElem;
		}
			/// <summary>
			/// Clean up any resources being used.
			/// </summary>
			protected override void Dispose(bool disposing)
			{
				// Must not be run more than once.
				if (IsDisposed)
					return;

				base.Dispose(disposing);

				if (disposing)
				{
				}

				m_env = null;
				m_vc = null;
				m_validator = null; // TODO: Make m_validator disposable?
			}
			public void ResetValidator()
			{
				CheckDisposed();

				m_validator = new PhonEnvRecognizer(
					m_fdoCache.LangProject.PhonologicalDataOA.AllPhonemes().ToArray(),
					m_fdoCache.LangProject.PhonologicalDataOA.AllNaturalClassAbbrs().ToArray());
			}
Ejemplo n.º 11
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			base.Dispose(disposing);

			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			m_validator = null; // TODO: Make m_validator disposable?
			if (m_realEnvs != null)
			{
				m_realEnvs.Clear();
				m_realEnvs = null;
			}
			m_rootObj = null;
			m_tsf = null;
			m_sda = null;
			m_PhoneEnvReferenceVc = null;
		}
			/// <summary>
			/// Clean up any resources being used.
			/// </summary>
			protected override void Dispose(bool disposing)
			{
				//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
				// Must not be run more than once.
				if (IsDisposed)
					return;

				base.Dispose(disposing);

				if (disposing)
				{
					if (m_vc != null)
						m_vc.Dispose();
				}

				m_env = null;
				m_vc = null;
				m_validator = null; // TODO: Make m_validator disposable?
			}