Example #1
0
        protected override void LoadParser(ref XmlDocument model, XmlDocument template)
        {
            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.
            foreach (var affix in m_cache.ServiceLocator.GetInstance <IMoAffixAllomorphRepository>().AllInstances())
            {
                string form = affix.Form.VernacularDefaultWritingSystem.Text;
                if (string.IsNullOrEmpty(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))
                {
                    string msg = string.Format(ParserCoreStrings.ksHermitCrabReduplicationProblem, form,
                                               validator.ErrorMessage);
                    m_cache.ThreadHelper.Invoke(() =>                     // We may be running in a background thread
                    {
                        MessageBox.Show(Form.ActiveForm, msg, ParserCoreStrings.ksBadAffixForm,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                    m_loader.Reset();           // make sure nothing thinks it is in a useful state
                    return;                     // We can't load the parser, hopefully our caller will realize we failed.
                }
            }

            var transformer = new M3ToHCTransformer(m_projectName, m_taskUpdateHandler);

            transformer.MakeHCFiles(ref model);

            m_patr.LoadGrammarFile(HcGrammarPath);
            m_loader.Load(hcPath);

            XmlNode delReappsNode = model.SelectSingleNode("/M3Dump/ParserParameters/HC/DelReapps");

            if (delReappsNode != null)
            {
                m_loader.CurrentMorpher.DelReapplications = Convert.ToInt32(delReappsNode.InnerText);
            }
        }
Example #2
0
        protected override void LoadParser(ref XmlDocument model, XmlDocument template, TaskReport task, ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            try
            {
                M3ToHCTransformer transformer = new M3ToHCTransformer(m_database);
                transformer.MakeHCFiles(ref model, task, eNeedsUpdate);
            }
            catch (Exception error)
            {
                if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
                    error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
                {
                    throw error;
                }

                task.EncounteredError(null);                    // Don't want to show message box in addition to yellow crash box!
                throw new ApplicationException("Error while generating files for the Parser.", error);
            }

            try
            {
                string gramPath = Path.Combine(m_outputDirectory, m_database + "gram.txt");
                m_patr.LoadGrammarFile(gramPath);
                string hcPath = Path.Combine(m_outputDirectory, m_database + "HCInput.xml");
                m_loader.Load(hcPath);

                XmlNode delReappsNode = model.SelectSingleNode("/M3Dump/ParserParameters/HC/DelReapps");
                if (delReappsNode != null)
                {
                    m_loader.CurrentMorpher.DelReapplications = Convert.ToInt32(delReappsNode.InnerText);
                }
            }
            catch (Exception error)
            {
                if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
                    error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
                {
                    throw error;
                }
                ApplicationException e = new ApplicationException("Error while loading the Parser.", error);
                task.EncounteredError(null);                    // Don't want to show message box in addition to yellow crash box!
                throw e;
            }
        }
Example #3
0
		protected override void LoadParser(ref XmlDocument model, XmlDocument template, TaskReport task, ParserScheduler.NeedsUpdate eNeedsUpdate)
		{
			try
			{
				M3ToHCTransformer transformer = new M3ToHCTransformer(m_database);
				transformer.MakeHCFiles(ref model, task, eNeedsUpdate);
			}
			catch (Exception error)
			{
				if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
					error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
				{
					throw error;
				}

				task.EncounteredError(null);	// Don't want to show message box in addition to yellow crash box!
				throw new ApplicationException("Error while generating files for the Parser.", error);
			}

			try
			{
				string gramPath = Path.Combine(m_outputDirectory, m_database + "gram.txt");
				m_patr.LoadGrammarFile(gramPath);
				string hcPath = Path.Combine(m_outputDirectory, m_database + "HCInput.xml");
				m_loader.Load(hcPath);

				XmlNode delReappsNode = model.SelectSingleNode("/M3Dump/ParserParameters/HC/DelReapps");
				if (delReappsNode != null)
					m_loader.CurrentMorpher.DelReapplications = Convert.ToInt32(delReappsNode.InnerText);
			}
			catch (Exception error)
			{
				if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
					error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
				{
					throw error;
				}
				ApplicationException e = new ApplicationException("Error while loading the Parser.", error);
				task.EncounteredError(null);	// Don't want to show message box in addition to yellow crash box!
				throw e;
			}
		}