コード例 #1
0
        public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
        {
            m_xmlWriter.WriteStartElement("MorphAndLookupWord");
            m_xmlWriter.WriteElementString("Input", word);
            WordAnalysisTrace trace;

            try
            {
                ICollection <WordSynthesis> results = morpher.MorphAndLookupWord(word, out trace);
                m_xmlWriter.WriteStartElement("Output");
                foreach (WordSynthesis ws in results)
                {
                    Write(ws, prettyPrint);
                }
                m_xmlWriter.WriteEndElement();

                if (morpher.IsTracing)
                {
                    Write(trace, prettyPrint, printTraceInputs);
                }
            }
            catch (MorphException me)
            {
                Write(me);
            }
            m_xmlWriter.WriteEndElement();
        }
コード例 #2
0
        public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
        {
            m_out.WriteLine("Morph and Lookup: " + word);
            WordAnalysisTrace           trace;
            ICollection <WordSynthesis> results = morpher.MorphAndLookupWord(word, out trace);

            m_out.WriteLine("*Results*");
            if (results.Count == 0)
            {
                m_out.WriteLine("None found");
                m_out.WriteLine();
            }
            else
            {
                foreach (WordSynthesis ws in results)
                {
                    Write(ws, prettyPrint);
                }
            }

            if (prettyPrint && morpher.IsTracing)
            {
                m_out.WriteLine("*Trace*");
                Write(trace, prettyPrint, printTraceInputs);
                m_out.WriteLine();
            }
        }
コード例 #3
0
ファイル: XmlOutput.cs プロジェクト: bbriggs/FieldWorks
		public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
		{
			m_xmlWriter.WriteStartElement("MorphAndLookupWord");
			m_xmlWriter.WriteElementString("Input", word);
			try
			{
				m_trace.WriteInputs = printTraceInputs;
				ICollection<WordSynthesis> results = morpher.MorphAndLookupWord(word, m_trace);
				m_xmlWriter.WriteStartElement("Output");
				foreach (WordSynthesis ws in results)
					Write(ws, prettyPrint);
				m_xmlWriter.WriteEndElement();

				if (m_trace.IsTracing)
					WriteTrace();
				m_trace.Reset();
			}
			catch (MorphException me)
			{
				Write(me);
			}
			m_xmlWriter.WriteEndElement();
		}
コード例 #4
0
ファイル: DefaultOutput.cs プロジェクト: bbriggs/FieldWorks
		public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
		{
			m_out.WriteLine("Morph and Lookup: " + word);
			ICollection<WordSynthesis> results = morpher.MorphAndLookupWord(word, m_trace);
			m_out.WriteLine("*Results*");
			if (results.Count == 0)
			{
				m_out.WriteLine("None found");
				m_out.WriteLine();
			}
			else
			{
				foreach (WordSynthesis ws in results)
					Write(ws, prettyPrint);
			}

			if (prettyPrint && m_trace.IsTracing)
			{
				m_out.WriteLine("*Trace*");
				WriteTrace(printTraceInputs);
				m_out.WriteLine();
			}
			m_trace.Reset();
		}
コード例 #5
0
ファイル: HCWorker.cs プロジェクト: sillsdev/WorldPad
			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);
				}
			}
コード例 #6
0
ファイル: HCParser.cs プロジェクト: bbriggs/FieldWorks
		private void MorphAndLookupWord(XmlWriter writer, Morpher morpher, string word, bool printTraceInputs, string[] selectTraceMorphs, string patrlexPath, bool doTrace)
		{
			try
			{
				ICollection<WordGrammarTrace> wordGrammarTraces = null;
				if (doTrace)
					wordGrammarTraces = new HashSet<WordGrammarTrace>();
				var traceManager = new FwXmlTraceManager(m_cache) { WriteInputs = printTraceInputs, TraceAll = doTrace };
				ICollection<WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, traceManager, selectTraceMorphs);

				IEnumerable<PatrResult> patrResults = ProcessPatr(synthesisRecs, patrlexPath, doTrace);
				foreach (PatrResult patrResult in patrResults)
				{
					if (patrResult.PassedPatr)
						BuildXmlOutput(writer, patrResult.Morphs);
					if (wordGrammarTraces != null)
						wordGrammarTraces.Add(patrResult.WordGrammarTrace);
				}

				if (doTrace)
				{
					WriteTrace(writer, traceManager);
					ConvertWordGrammarTraceToXml(writer, wordGrammarTraces);
				}
				traceManager.Reset();
			}
			catch (MorphException exc)
			{
				Write(writer, exc);
			}
		}