PrepareTemplatesForXAmpleFiles() public method

public PrepareTemplatesForXAmpleFiles ( XDocument domModel, XDocument domTemplate ) : void
domModel XDocument
domTemplate XDocument
return void
Exemplo n.º 1
0
        /// <summary>
        /// Loads the parser.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="template">The template.</param>
        protected override void LoadParser(ref XmlDocument model, XmlDocument template)
        {
            var transformer = new M3ToXAmpleTransformer(m_projectName, m_taskUpdateHandler);
            var startTime   = DateTime.Now;

            // PrepareTemplatesForXAmpleFiles adds orderclass elements to MoInflAffixSlot elements
            transformer.PrepareTemplatesForXAmpleFiles(ref model, template);
            var ttlTicks = DateTime.Now.Ticks - startTime.Ticks;

            Trace.WriteLineIf(m_tracingSwitch.TraceInfo, "GAFAWS prep took : " + ttlTicks);

            transformer.MakeAmpleFiles(model);

            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;
                }
            }

            m_xample.SetParameter("MaxAnalysesToReturn", maxAnalCount.ToString());

            string tempPath = Path.GetTempPath();

            m_xample.LoadFiles(DirectoryFinder.FWCodeDirectory + @"/Language Explorer/Configuration/Grammar",
                               tempPath, m_projectName);
        }
Exemplo n.º 2
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.º 3
0
        public void Update()
        {
            CheckDisposed();

            if (m_changeListener.Reset() || m_forceUpdate)
            {
                XDocument model, template;
                // According to the fxt template files, GAFAWS is NFC, all others are NFD.
                using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance <IWorkerThreadReadHandler>()))
                {
                    ILangProject lp = m_cache.LanguageProject;
                    // 1. Export lexicon and/or grammar.
                    model = M3ModelExportServices.ExportGrammarAndLexicon(lp);

                    // 2. Export GAFAWS data.
                    template = M3ModelExportServices.ExportGafaws(lp.PartsOfSpeechOA.PossibilitiesOS);
                }

                // PrepareTemplatesForXAmpleFiles adds orderclass elements to MoInflAffixSlot elements
                m_transformer.PrepareTemplatesForXAmpleFiles(model, template);

                m_transformer.MakeAmpleFiles(model);

                int      maxAnalCount     = 20;
                XElement maxAnalCountElem = model.Elements("M3Dump").Elements("ParserParameters").Elements("XAmple").Elements("MaxAnalysesToReturn").FirstOrDefault();
                if (maxAnalCountElem != null)
                {
                    maxAnalCount = (int)maxAnalCountElem;
                    if (maxAnalCount < 1)
                    {
                        maxAnalCount = -1;
                    }
                }

                m_xample.SetParameter("MaxAnalysesToReturn", maxAnalCount.ToString(CultureInfo.InvariantCulture));

                m_xample.LoadFiles(Path.Combine(m_dataDir, "Configuration", "Grammar"), Path.GetTempPath(), m_database);
                m_forceUpdate = false;
            }
        }
Exemplo n.º 4
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);
		}