Пример #1
0
        private void SetDescriptionAndFxtFile(ParserScheduler.NeedsUpdate eNeedsUpdate, out string sDescription, out string sFxtFile)
        {
            const string ksFXTPath = @"Language Explorer\Configuration\Grammar\FXTs";

            switch (eNeedsUpdate)
            {
            case ParserScheduler.NeedsUpdate.GrammarAndLexicon:
                sDescription = ParserCoreStrings.ksRetrievingGrammarAndLexicon;
                sFxtFile     = Path.Combine(ksFXTPath, "M3Parser.fxt");
                break;

            case ParserScheduler.NeedsUpdate.GrammarOnly:
                sDescription = ParserCoreStrings.ksRetrievingGrammar;
                sFxtFile     = Path.Combine(ksFXTPath, "M3ParserGrammarOnly.fxt");
                break;

            case ParserScheduler.NeedsUpdate.LexiconOnly:
                sDescription = ParserCoreStrings.ksRetrievingLexicon;
                sFxtFile     = Path.Combine(ksFXTPath, "M3ParserLexiconOnly.fxt");
                break;

            case ParserScheduler.NeedsUpdate.HaveChangedData:
                sDescription = ParserCoreStrings.ksUpdatingGrammarAndLexicon;
                sFxtFile     = Path.Combine(ksFXTPath, "M3Parser.fxt");
                break;

            default:
                throw new ApplicationException("M3ModelRetriever.RetrieveModel() invoked without reason");
            }
        }
Пример #2
0
        internal void MakeHCFiles(ref XmlDocument model, TaskReport parentTask, ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            using (m_topLevelTask = parentTask.AddSubTask(ParserCoreStrings.ksMakingXAmpleFiles))
            {
                if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.LexiconOnly ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.HaveChangedData)
                {
                    DateTime startTime = DateTime.Now;
                    TransformDomToFile("FxtM3ParserToHCInput.xsl", model, m_database + "HCInput.xml");
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "Lex XSLT took : " + ttlTicks.ToString());
                }

                if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarOnly ||
                    eNeedsUpdate == ParserScheduler.NeedsUpdate.HaveChangedData)
                {
                    DateTime startTime = DateTime.Now;
                    TransformDomToFile("FxtM3ParserToToXAmpleGrammar.xsl", model, m_database + "gram.txt");
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "Grammar XSLTs took : " + ttlTicks.ToString());
                    // TODO: Putting this here is not necessarily efficient because it happens every time
                    //       the parser is run.  It would be more efficient to run this only when the user
                    //       is trying a word.  But we need the "model" to apply this transform an it is
                    //       available here, so we're doing this for now.
                    startTime = DateTime.Now;
                    string sName = m_database + "XAmpleWordGrammarDebugger.xsl";
                    TransformDomToFile("FxtM3ParserToXAmpleWordGrammarDebuggingXSLT.xsl", model, sName);
                    ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "WordGrammarDebugger XSLT took : " + ttlTicks.ToString());
                }
            }
        }
Пример #3
0
        protected static string SetDescription(ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            string sDescription;

            switch (eNeedsUpdate)
            {
            case ParserScheduler.NeedsUpdate.GrammarAndLexicon:
                sDescription = ParserCoreStrings.ksLoadGrammarAndLexicon;
                break;

            case ParserScheduler.NeedsUpdate.GrammarOnly:
                sDescription = ParserCoreStrings.ksLoadGrammar;
                break;

            case ParserScheduler.NeedsUpdate.LexiconOnly:
                sDescription = ParserCoreStrings.ksLoadLexicon;
                break;

            case ParserScheduler.NeedsUpdate.HaveChangedData:
                sDescription = ParserCoreStrings.ksUpdatingGrammarAndLexicon;
                break;

            default:
                sDescription = ParserCoreStrings.ksNotDoingAnything;
                break;
            }
            return(sDescription);
        }
Пример #4
0
 public new TimeStamp LoadGrammarAndLexicon(ParserScheduler.NeedsUpdate eNeedsUpdate)
 {
     using (new TaskReport("Load Grammar", m_taskUpdateHandler))
     {
         Delay(10000000);
         return(new TimeStamp(m_connection));               //DateTime.Now;
     }
 }
Пример #5
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);
        }
Пример #6
0
 private void DoDump(ParserScheduler.NeedsUpdate eNeedsUpdate, FdoCache cache, string sFxtPath)
 {
     using (XDumper fxtDumper = new XDumper(cache))
     {
         //Trace.WriteLine("Retriever.DoDump");
         // N.B. It is crucial to include the ConstraintFilterStrategy here
         //      Without it, we end up passing ill-formed environments to the parser - a very bad thing
         //      See LT-6827 An invalid environment is being passed on to the parser and it should not.
         fxtDumper.Go(cache.LangProject as CmObject, sFxtPath, File.CreateText(m_sFxtOutputPath),
                      new IFilterStrategy[] { new ConstraintFilterStrategy() });
         if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon ||
             eNeedsUpdate == ParserScheduler.NeedsUpdate.LexiconOnly)
         {
             StartSubTask(ParserCoreStrings.ksRetrievingTemplateInformation);
             using (XDumper fxtDumperInner = new XDumper(cache))
             {
                 m_sFxtTemplateOutputPath = Path.Combine(m_outputDirectory, m_database + "GAFAWSFxtResult.xml");
                 fxtDumperInner.Go(cache.LangProject as CmObject, m_sGafawsFxtPath, File.CreateText(m_sFxtTemplateOutputPath));
             }
             EndSubTask();
         }
     }
 }
Пример #7
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);
        }
Пример #8
0
 protected abstract void LoadParser(ref XmlDocument model, XmlDocument template, TaskReport task, ParserScheduler.NeedsUpdate eNeedsUpdate);
Пример #9
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;
            }
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        internal TimeStamp RetrieveModel(SqlConnection connection, string LangProject, TaskReport parentTask, ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            TimeStamp began = new TimeStamp(connection);

            using (FdoCache cache = FdoCache.Create(connection.DataSource, connection.Database, null))
            {
                BaseVirtualHandler.InstallVirtuals(@"Language Explorer\Configuration\Main.xml",
                                                   new string[] { "SIL.FieldWorks.FDO.", "SIL.FieldWorks.IText." }, cache, true);

                string sDescription;
                string sFxtFile;
                SetDescriptionAndFxtFile(eNeedsUpdate, out sDescription, out sFxtFile);
                using (m_topLevelTask = parentTask.AddSubTask(sDescription))
                {
                    m_taskStack.Push(m_topLevelTask);
                    string sFxtPath = Path.Combine(DirectoryFinder.FWCodeDirectory, sFxtFile);
                    m_sFxtOutputPath = Path.Combine(m_outputDirectory, m_database + "ParserFxtResult.xml");
                    if ((eNeedsUpdate == ParserScheduler.NeedsUpdate.HaveChangedData) &&
                        File.Exists(m_sFxtTemplateOutputPath))
                    {
                        try
                        {
                            DoUpdate(cache, sFxtPath, ref m_modelDom);
                            DoUpdate(cache, m_sGafawsFxtPath, ref m_templateDom);
                        }
                        // (SteveMiller): Unremarked, the following often causes an error:
                        // Warning as Error: The variable 'e' is declared but never used
                        catch (XUpdaterException)
                        {
                            //Trace.WriteLine("XUpdater exception caught: " + e.Message);
                            // do something useful for the user
                            DoDump(eNeedsUpdate, cache, sFxtPath);
                        }
                    }
                    else
                    {
                        DoDump(eNeedsUpdate, cache, sFxtPath);
                    }
                }
            }
            m_topLevelTask = null;
            return(began);
        }