public void AddMorphData(string word, Dictionary <string, string> gramDic, string lemma = null) { if (lemma == null) { lemma = word; } var gDic = new ReadOnlyDictionary <string, string>(gramDic); var mi = new MorphInfo(lemma, new ReadOnlyDictionary <string, string>(gDic)); _morphDict[word.ToLower()] = new[] { mi }; }
private bool GetMorphs(Word ws, out List<MorphInfo> result) { var morphs = new Dictionary<Morpheme, MorphInfo>(); result = new List<MorphInfo>(); foreach (Annotation<ShapeNode> morph in ws.Morphs) { Allomorph allomorph = ws.GetAllomorph(morph); var formID = (int?) allomorph.Properties["ID"] ?? 0; if (formID == 0) continue; var formID2 = (int?) allomorph.Properties["ID2"] ?? 0; string formStr = ws.Shape.GetNodes(morph.Span).ToString(ws.Stratum.SymbolTable, false); int curFormID; MorphInfo morphInfo; if (!morphs.TryGetValue(allomorph.Morpheme, out morphInfo)) { curFormID = formID; } else if (formID2 > 0) { // circumfix curFormID = formID2; } else { morphInfo.String += formStr; continue; } IMoForm form; if (!m_cache.ServiceLocator.GetInstance<IMoFormRepository>().TryGetObject(curFormID, out form)) { result = null; return false; } var msaID = (int) allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance<IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { result = null; return false; } var lexEntryRefID = (int?) allomorph.Morpheme.Properties["LexEntryRefID"] ?? 0; ILexEntryRef lexEntryRef = null; if (lexEntryRefID > 0 && !m_cache.ServiceLocator.GetInstance<ILexEntryRefRepository>().TryGetObject(lexEntryRefID, out lexEntryRef)) { result = null; return false; } morphInfo = new MorphInfo { Form = form, String = formStr, Msa = msa, LexEntryRef = lexEntryRef, IsCircumfix = formID2 > 0 }; morphs[allomorph.Morpheme] = morphInfo; switch (form.MorphTypeRA.Guid.ToString()) { case MoMorphTypeTags.kMorphInfix: case MoMorphTypeTags.kMorphInfixingInterfix: if (result.Count == 0) result.Add(morphInfo); else result.Insert(result.Count - 1, morphInfo); break; default: result.Add(morphInfo); break; } } return true; }
private bool GetMorphs(Word ws, out List <MorphInfo> result) { var morphs = new Dictionary <Morpheme, MorphInfo>(); result = new List <MorphInfo>(); foreach (Annotation <ShapeNode> morph in ws.Morphs) { Allomorph allomorph = ws.GetAllomorph(morph); var formID = (int?)allomorph.Properties["ID"] ?? 0; if (formID == 0) { continue; } var formID2 = (int?)allomorph.Properties["ID2"] ?? 0; string formStr = ws.Shape.GetNodes(morph.Span).ToString(ws.Stratum.CharacterDefinitionTable, false); int curFormID; MorphInfo morphInfo; if (!morphs.TryGetValue(allomorph.Morpheme, out morphInfo)) { curFormID = formID; } else if (formID2 > 0) { // circumfix curFormID = formID2; } else { morphInfo.String += formStr; continue; } IMoForm form; if (!m_cache.ServiceLocator.GetInstance <IMoFormRepository>().TryGetObject(curFormID, out form)) { result = null; return(false); } var msaID = (int)allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { result = null; return(false); } var inflTypeID = (int?)allomorph.Morpheme.Properties["InflTypeID"] ?? 0; ILexEntryInflType inflType = null; if (inflTypeID > 0 && !m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) { result = null; return(false); } morphInfo = new MorphInfo { Form = form, String = formStr, Msa = msa, InflType = inflType, IsCircumfix = formID2 > 0 }; morphs[allomorph.Morpheme] = morphInfo; switch ((form.MorphTypeRA == null ? Guid.Empty : form.MorphTypeRA.Guid).ToString()) { case MoMorphTypeTags.kMorphInfix: case MoMorphTypeTags.kMorphInfixingInterfix: if (result.Count == 0) { result.Add(morphInfo); } else { result.Insert(result.Count - 1, morphInfo); } break; default: result.Add(morphInfo); break; } } return(true); }