Exemplo n.º 1
0
            public override void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
            {
                try
                {
                    ICollection <WordGrammarTrace> wordGrammarTraces = null;
                    if (m_fDotrace)
                    {
                        wordGrammarTraces = new Set <WordGrammarTrace>();
                    }
                    morpher.TraceAll = m_fDotrace;
                    WordAnalysisTrace           trace;
                    ICollection <WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, out trace);
                    foreach (WordSynthesis ws in synthesisRecs)
                    {
                        WordGrammarTrace          wordGrammarTrace = null;
                        IEnumerable <PcPatrMorph> morphs           = GetMorphs(ws);
                        if (m_fDotrace)
                        {
                            wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(), morphs);
                            wordGrammarTraces.Add(wordGrammarTrace);
                        }

                        WritePcPatrLexiconFile(m_patrlexPath, morphs);
                        m_patr.LoadLexiconFile(m_patrlexPath, 0);
                        string sentence = BuildPcPatrInputSentence(morphs);
                        try
                        {
                            if (m_patr.ParseString(sentence) != null)
                            {
                                BuildXmlOutput(morphs);
                                if (m_fDotrace)
                                {
                                    wordGrammarTrace.Success = true;
                                }
                            }
                            else if (m_fDotrace)
                            {
                                wordGrammarTrace.Success = false;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    if (m_fDotrace)
                    {
                        Write(trace, prettyPrint, printTraceInputs);
                        ConvertWordGrammarTraceToXml(wordGrammarTraces);
                    }
                }
                catch (MorphException exc)
                {
                    Write(exc);
                }
            }
Exemplo n.º 2
0
 public void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs, string[] selectTraceMorphs)
 {
     try
     {
         ICollection <WordGrammarTrace> wordGrammarTraces = null;
         if (m_fDotrace)
         {
             wordGrammarTraces = new HashSet <WordGrammarTrace>();
         }
         morpher.TraceAll = m_fDotrace;
         WordAnalysisTrace           trace;
         ICollection <WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, out trace, selectTraceMorphs);
         foreach (WordSynthesis ws in synthesisRecs)
         {
             WordGrammarTrace          wordGrammarTrace = null;
             IEnumerable <PcPatrMorph> morphs           = GetMorphs(ws);
             if (wordGrammarTraces != null)
             {
                 wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(), morphs, m_cache);
                 wordGrammarTraces.Add(wordGrammarTrace);
             }
             if (morphs.Count() == 1)
             {
                 var morph     = morphs.First();
                 var formid    = morph.formId;
                 var forms     = m_cache.LanguageProject.LexDbOA.AllAllomorphs.Where(a => a.Hvo.ToString() == formid);
                 var form      = forms.First();
                 var morphtype = form.MorphTypeRA;
                 if (morphtype.IsBoundType)
                 {
                     if (wordGrammarTrace != null)
                     {
                         wordGrammarTrace.Success = false;                                     // this is not really true; what other options are there?
                     }
                     continue;
                 }
             }
             WritePcPatrLexiconFile(m_patrlexPath, morphs);
             m_patr.LoadLexiconFile(m_patrlexPath, 0);
             string sentence = BuildPcPatrInputSentence(morphs);
             try
             {
                 if (m_patr.ParseString(sentence) != null)
                 {
                     BuildXmlOutput(morphs);
                     if (wordGrammarTrace != null)
                     {
                         wordGrammarTrace.Success = true;
                     }
                 }
                 else if (wordGrammarTrace != null)
                 {
                     wordGrammarTrace.Success = false;
                 }
             }
             catch (Exception)
             {
             }
         }
         if (m_fDotrace)
         {
             Write(trace, prettyPrint, printTraceInputs);
             ConvertWordGrammarTraceToXml(wordGrammarTraces);
         }
     }
     catch (MorphException exc)
     {
         Write(exc);
     }
 }
Exemplo n.º 3
0
			public override void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
			{
				try
				{
					ICollection<WordGrammarTrace> wordGrammarTraces = null;
					if (m_fDotrace)
						wordGrammarTraces = new Set<WordGrammarTrace>();
					morpher.TraceAll = m_fDotrace;
					WordAnalysisTrace trace;
					ICollection<WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, out trace);
					foreach (WordSynthesis ws in synthesisRecs)
					{
						WordGrammarTrace wordGrammarTrace = null;
						IEnumerable<PcPatrMorph> morphs = GetMorphs(ws);
						if (m_fDotrace)
						{
							wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(), morphs);
							wordGrammarTraces.Add(wordGrammarTrace);
						}

						WritePcPatrLexiconFile(m_patrlexPath, morphs);
						m_patr.LoadLexiconFile(m_patrlexPath, 0);
						string sentence = BuildPcPatrInputSentence(morphs);
						try
						{
							if (m_patr.ParseString(sentence) != null)
							{
								BuildXmlOutput(morphs);
								if (m_fDotrace)
									wordGrammarTrace.Success = true;
							}
							else if (m_fDotrace)
							{
								wordGrammarTrace.Success = false;
							}
						}
						catch (Exception)
						{
						}
					}
					if (m_fDotrace)
					{
						Write(trace, prettyPrint, printTraceInputs);
						ConvertWordGrammarTraceToXml(wordGrammarTraces);
					}
				}
				catch (MorphException exc)
				{
					Write(exc);
				}
			}
Exemplo n.º 4
0
		private IEnumerable<PatrResult> ProcessPatr(IEnumerable<WordSynthesis> synthesisRecs, string patrlexPath, bool trace)
		{
			IList<PatrResult> patrResults = new List<PatrResult>();
			bool passedPatr = false;
			foreach (WordSynthesis ws in synthesisRecs)
			{
				WordGrammarTrace wordGrammarTrace = null;
				List<PcPatrMorph> morphs = GetMorphs(ws);
				if (trace)
					wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(CultureInfo.InvariantCulture), morphs, m_cache);
				if (morphs.Count == 1)
				{
					PcPatrMorph morph = morphs[0];
					string formid = morph.formId;
					IMoForm form = m_cache.ServiceLocator.GetInstance<IMoFormRepository>().GetObject(Int32.Parse(formid));
					var morphtype = form.MorphTypeRA;
					if (morphtype.IsBoundType)
					{
						if (wordGrammarTrace != null)
							wordGrammarTrace.Success = false; // this is not really true; what other options are there?
						continue;
					}
				}
				WritePcPatrLexiconFile(patrlexPath, morphs);
				m_patr.LoadLexiconFile(patrlexPath, 0);
				string sentence = BuildPcPatrInputSentence(morphs);
				try
				{
					if (m_patr.ParseString(sentence) != null)
					{
						passedPatr = true;
						if (wordGrammarTrace != null)
							wordGrammarTrace.Success = true;
					}
					else if (wordGrammarTrace != null)
					{
						wordGrammarTrace.Success = false;
					}
				}
				catch (Exception)
				{
				}
				patrResults.Add(new PatrResult { Morphs = morphs, WordGrammarTrace = wordGrammarTrace, PassedPatr = passedPatr });
			}
			return patrResults;
		}