Given an XML file representing an instance of a M3 grammar model, transforms it into the format needed by XAmple.
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 XAmpleParser(FdoCache cache, string dataDir)
		{
			m_cache = cache;
			m_xample = new XAmpleWrapper();
			m_xample.Init();
			m_dataDir = dataDir;
			m_retriever = new M3ParserModelRetriever(m_cache);
			m_database = ParserHelper.ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
			m_transformer = new M3ToXAmpleTransformer(m_database);
		}
Exemplo n.º 4
0
 public XAmpleParser(FdoCache cache, string dataDir)
 {
     m_cache  = cache;
     m_xample = new XAmpleWrapper();
     m_xample.Init();
     m_dataDir        = dataDir;
     m_changeListener = new ParserModelChangeListener(m_cache);
     m_database       = ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
     m_transformer    = new M3ToXAmpleTransformer(m_database);
     m_forceUpdate    = true;
 }
Exemplo n.º 5
0
		public XAmpleParser(FdoCache cache, string dataDir)
		{
			m_cache = cache;
			m_xample = new XAmpleWrapper();
			m_xample.Init();
			m_dataDir = dataDir;
			m_changeListener = new ParserModelChangeListener(m_cache);
			m_database = ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
			m_transformer = new M3ToXAmpleTransformer(m_database);
			m_forceUpdate = true;
		}
Exemplo n.º 6
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);
		}