public void LoadLexiconFile() { using (var parser = new PatrParser()) { parser.CommentChar = '|'; parser.CodePage = Encoding.UTF8.CodePage; Assert.NotNull(parser); parser.LoadLexiconFile(LexiconFileName, 1); } }
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); } }
protected PatrParser CreateAndSetupTestParser() { PatrParser parser = null; try { parser = new PatrParser { CommentChar = '|', CodePage = Encoding.UTF8.CodePage }; Assert.NotNull(parser); parser.LoadGrammarFile(GrammarFileName); parser.LoadLexiconFile(LexiconFileName, 1); return(parser); } catch (Exception) { if (parser != null) { parser.Dispose(); } throw; } }
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); } }