예제 #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
		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
		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
			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
		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);
			}
		}