Exemplo n.º 1
0
        protected override void LoadParser(ref XmlDocument model, XmlDocument template, TaskReport task, ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            try
            {
                M3ToXAmpleTransformer transformer = new M3ToXAmpleTransformer(m_database);
                if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.LexiconOnly ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.HaveChangedData)
                {                 // even though POS is part of Grammar, this is only used by the lexicon
                    DateTime startTime = DateTime.Now;
                    // PrepareTemplatesForXAmpleFiles adds orderclass elements to MoInflAffixSlot elements
                    transformer.PrepareTemplatesForXAmpleFiles(ref model, template, task);
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "GAFAWS prep took : " + ttlTicks.ToString());
                }
                transformer.MakeAmpleFiles(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);
            }

            int     maxAnalCount     = 20;
            XmlNode maxAnalCountNode = model.SelectSingleNode("/M3Dump/ParserParameters/XAmple/MaxAnalysesToReturn");

            if (maxAnalCountNode != null)
            {
                maxAnalCount = Convert.ToInt16(maxAnalCountNode.FirstChild.Value);
                if (maxAnalCount < 1)
                {
                    maxAnalCount = -1;
                }
            }

            try
            {
                m_xample.SetParameter("MaxAnalysesToReturn", maxAnalCount.ToString());
            }
            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 setting Parser parameters.", error);
                task.EncounteredError(null);                    // Don't want to show message box in addition to yellow crash box!
                throw e;
            }

            LoadXAmpleFiles(task);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Try parsing a wordform, optionally getting a trace of the parse
        /// </summary>
        /// <param name="sForm">the word form to parse</param>
        /// <param name="fDoTrace">whether or not to trace the parse</param>
        /// <param name="sSelectTraceMorphs">list of msa hvos to limit trace to </param>
        internal void TryAWord(string sForm, bool fDoTrace, string sSelectTraceMorphs)
        {
            CheckDisposed();

            if (sForm == null)
            {
                throw new ArgumentNullException("sForm", "TryAWord cannot trace a Null string.");
            }
            if (sForm == String.Empty)
            {
                throw new ArgumentException("Can't try a word with no content.", "sForm");
            }

            using (TaskReport task = new TaskReport(
                       String.Format(ParserCoreStrings.ksTraceWordformX, sForm),
                       m_taskUpdateHandler))
            {
                try
                {
                    string normForm = Icu.Normalize(sForm, Icu.UNormalizationMode.UNORM_NFD);
                    string result   = null;
                    if (fDoTrace)
                    {
                        //Debug.WriteLine("Begin tracing wordform " + sForm);
                        result = TraceWord(normForm, sSelectTraceMorphs);
                        //Debug.WriteLine("After tacing wordform " + sForm);
                        //Debug.WriteLine("Result of trace: " + task.Details);
                    }
                    else
                    {
                        result = ParseWord(normForm, 0);
                    }
                    task.Details = Icu.Normalize(result, Icu.UNormalizationMode.UNORM_NFD);
                    return;
                }
                catch (Exception error)
                {
                    Trace.WriteLineIf(tracingSwitch.TraceError, "The word '"
                                      + sForm
                                      + "' failed to parse. error was: "
                                      + error.Message);
                    task.EncounteredError(null);                        // Don't want to show message box in addition to yellow crash box!
                    //might as well keep going.
                    //TODO: create an problem object since we could not parse this word.
                    throw new ApplicationException("Error while parsing '" + sForm + "'.", error);
                }
            }
        }
Exemplo n.º 4
0
        internal TimeStamp LoadGrammarAndLexicon(ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            CheckDisposed();
            Trace.WriteLineIf(tracingSwitch.TraceInfo, "Worker.LoadGrammarAndLexicon: eNeedsUpdate = " + eNeedsUpdate);
            string     sDescription = SetDescription(eNeedsUpdate);
            TaskReport task         = new TaskReport(sDescription, m_taskUpdateHandler);

            // no longer need this pop-up; was only for debugging
            // task.NotificationMessage = "Loading Parser";

            if (m_retriever == null)
            {
                m_retriever = new M3ParserModelRetriever(m_database);
            }
            TimeStamp stamp;

            using (task)
            {
                XmlDocument fxtResult;
                XmlDocument gafawsFxtResult;
                try
                {
                    DateTime startTime = DateTime.Now;
                    stamp = m_retriever.RetrieveModel(m_connection, m_LangProject, task, eNeedsUpdate);
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "FXT took : " + ttlTicks.ToString());
                    fxtResult       = m_retriever.ModelDom;
                    gafawsFxtResult = m_retriever.TemplateDom;
                }
                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 retrieving model for the Parser.", error);
                }

                LoadParser(ref fxtResult, gafawsFxtResult, task, eNeedsUpdate);
            }
            return(stamp);
        }
Exemplo n.º 5
0
 private void LoadXAmpleFiles(TaskReport task)
 {
     try
     {
         EnsureXampleSupportFilesExist();
         string tempPath = System.IO.Path.GetTempPath();
         string xPath    = XAmpleFixedFilesPath;
         m_xample.LoadFiles(xPath, tempPath, m_database);
         m_XAmpleHasBeenLoaded = true;
     }
     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;
     }
 }
Exemplo n.º 6
0
		internal TimeStamp LoadGrammarAndLexicon(ParserScheduler.NeedsUpdate eNeedsUpdate)
		{
			CheckDisposed();
			Trace.WriteLineIf(tracingSwitch.TraceInfo, "Worker.LoadGrammarAndLexicon: eNeedsUpdate = " + eNeedsUpdate);
			string sDescription = SetDescription(eNeedsUpdate);
			TaskReport task = new TaskReport(sDescription, m_taskUpdateHandler);
			// no longer need this pop-up; was only for debugging
			// task.NotificationMessage = "Loading Parser";

			if (m_retriever == null)
				m_retriever = new M3ParserModelRetriever(m_database);
			TimeStamp stamp;
			using (task)
			{
				XmlDocument fxtResult;
				XmlDocument gafawsFxtResult;
				try
				{
					DateTime startTime = DateTime.Now;
					stamp = m_retriever.RetrieveModel(m_connection, m_LangProject, task, eNeedsUpdate);
					long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
					Trace.WriteLineIf(tracingSwitch.TraceInfo, "FXT took : " + ttlTicks.ToString());
					fxtResult = m_retriever.ModelDom;
					gafawsFxtResult = m_retriever.TemplateDom;
				}
				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 retrieving model for the Parser.", error);
				}

				LoadParser(ref fxtResult, gafawsFxtResult, task, eNeedsUpdate);

			}
			return stamp;
		}
Exemplo n.º 7
0
		/// <summary>
		/// Try parsing a wordform, optionally getting a trace of the parse
		/// </summary>
		/// <param name="sForm">the word form to parse</param>
		/// <param name="fDoTrace">whether or not to trace the parse</param>
		/// <param name="sSelectTraceMorphs">list of msa hvos to limit trace to </param>
		internal void TryAWord(string sForm, bool fDoTrace, string sSelectTraceMorphs)
		{
			CheckDisposed();

			if (sForm == null)
				throw new ArgumentNullException("sForm", "TryAWord cannot trace a Null string.");
			if (sForm == String.Empty)
				throw new ArgumentException("Can't try a word with no content.", "sForm");

			using (TaskReport task = new TaskReport(
				String.Format(ParserCoreStrings.ksTraceWordformX, sForm),
				m_taskUpdateHandler))
			{
				try
				{
					string normForm = Icu.Normalize(sForm, Icu.UNormalizationMode.UNORM_NFD);
					string result = null;
					if (fDoTrace)
					{
						//Debug.WriteLine("Begin tracing wordform " + sForm);
						result = TraceWord(normForm, sSelectTraceMorphs);
						//Debug.WriteLine("After tacing wordform " + sForm);
						//Debug.WriteLine("Result of trace: " + task.Details);
					}
					else
						result = ParseWord(normForm, 0);
					task.Details = Icu.Normalize(result, Icu.UNormalizationMode.UNORM_NFD);
					return;
				}
				catch (Exception error)
				{
					Trace.WriteLineIf(tracingSwitch.TraceError, "The word '"
						+ sForm
						+ "' failed to parse. error was: "
						+ error.Message);
					task.EncounteredError(null);	// Don't want to show message box in addition to yellow crash box!
					//might as well keep going.
					//TODO: create an problem object since we could not parse this word.
					throw new ApplicationException("Error while parsing '" + sForm + "'.",error);
				}
			}
		}
Exemplo n.º 8
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;
			}
		}
Exemplo n.º 9
0
		private void LoadXAmpleFiles(TaskReport task)
		{
			try
			{
				EnsureXampleSupportFilesExist();
				string tempPath = System.IO.Path.GetTempPath();
				string xPath = XAmpleFixedFilesPath;
				m_xample.LoadFiles(xPath, tempPath, m_database);
				m_XAmpleHasBeenLoaded = true;
			}
			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;
			}
		}
Exemplo n.º 10
0
		protected override void LoadParser(ref XmlDocument model, XmlDocument template, TaskReport task, ParserScheduler.NeedsUpdate eNeedsUpdate)
		{
			try
			{
				M3ToXAmpleTransformer transformer = new M3ToXAmpleTransformer(m_database);
				if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon ||
					eNeedsUpdate == ParserScheduler.NeedsUpdate.LexiconOnly ||
					eNeedsUpdate == ParserScheduler.NeedsUpdate.HaveChangedData)
				{ // even though POS is part of Grammar, this is only used by the lexicon
					DateTime startTime = DateTime.Now;
					// PrepareTemplatesForXAmpleFiles adds orderclass elements to MoInflAffixSlot elements
					transformer.PrepareTemplatesForXAmpleFiles(ref model, template, task);
					long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
					Trace.WriteLineIf(tracingSwitch.TraceInfo, "GAFAWS prep took : " + ttlTicks.ToString());
				}
				transformer.MakeAmpleFiles(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);
			}

			int maxAnalCount = 20;
			XmlNode maxAnalCountNode = model.SelectSingleNode("/M3Dump/ParserParameters/XAmple/MaxAnalysesToReturn");
			if (maxAnalCountNode != null)
			{
				maxAnalCount = Convert.ToInt16(maxAnalCountNode.FirstChild.Value);
				if (maxAnalCount < 1)
					maxAnalCount = -1;
			}

			try
			{
				m_xample.SetParameter("MaxAnalysesToReturn", maxAnalCount.ToString());
			}
			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 setting Parser parameters.", error);
				task.EncounteredError(null);	// Don't want to show message box in addition to yellow crash box!
				throw e;
			}

			LoadXAmpleFiles(task);
		}