private void RemoveFeatureStructureFromMSA() { if (m_obj != null) { switch (m_obj.ClassID) { case FDO.Ling.MoStemMsa.kclsidMoStemMsa: IMoStemMsa stem = m_obj as IMoStemMsa; stem.MsFeaturesOA = null; break; case FDO.Ling.MoInflAffMsa.kclsidMoInflAffMsa: IMoInflAffMsa infl = m_obj as IMoInflAffMsa; infl.InflFeatsOA = null; break; case FDO.Ling.MoDerivAffMsa.kclsidMoDerivAffMsa: IMoDerivAffMsa derv = m_obj as IMoDerivAffMsa; if (m_flid == (int)FDO.Ling.MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures) { derv.FromMsFeaturesOA = null; } else { // assume it's the to features derv.ToMsFeaturesOA = null; } break; } } }
private void RemoveFeatureStructureFromMSA() { if (m_obj != null) { NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ServiceLocator.GetInstance <IActionHandler>(), () => { switch (m_obj.ClassID) { case MoStemMsaTags.kClassId: IMoStemMsa stem = m_obj as IMoStemMsa; stem.MsFeaturesOA = null; break; case MoInflAffMsaTags.kClassId: IMoInflAffMsa infl = m_obj as IMoInflAffMsa; infl.InflFeatsOA = null; break; case MoDerivAffMsaTags.kClassId: IMoDerivAffMsa derv = m_obj as IMoDerivAffMsa; if (m_flid == MoDerivAffMsaTags.kflidFromMsFeatures) { derv.FromMsFeaturesOA = null; } else { // assume it's the to features derv.ToMsFeaturesOA = null; } break; } }); } }
/// <summary> /// Given a (potentially) owning object, and the flid in which is does/will own /// the feature structure, find the relevant POS. /// </summary> /// <param name="cobj"></param> /// <param name="owningFlid"></param> /// <returns></returns> private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid) { IPartOfSpeech pos = null; switch (cobj.ClassID) { case MoInflAffMsa.kclsidMoInflAffMsa: IMoInflAffMsa infl = cobj as IMoInflAffMsa; if (infl != null) { pos = infl.PartOfSpeechRA; } break; case MoDerivAffMsa.kclsidMoDerivAffMsa: IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa; if (deriv != null) { if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures) { pos = deriv.FromPartOfSpeechRA; } else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures) { pos = deriv.ToPartOfSpeechRA; } } break; case MoStemMsa.kclsidMoStemMsa: IMoStemMsa stem = cobj as IMoStemMsa; if (stem != null) { pos = stem.PartOfSpeechRA; } break; case MoStemName.kclsidMoStemName: IMoStemName sn = cobj as IMoStemName; pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO); break; case MoAffixAllomorph.kclsidMoAffixAllomorph: // get entry of the allomorph and then get the msa of first sense and return its (from) POS ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO); if (entry == null) { return(pos); } ILexSense sense = entry.SensesOS.FirstItem; if (sense == null) { return(pos); } IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA; pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures); break; } return(pos); }
public void TwoAnalyses() { IWfiWordform catsTest = CheckAnalysisSize("catsTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Noun ILexEntry catN = m_entryFactory.Create(); IMoStemAllomorph catNForm = m_stemAlloFactory.Create(); catN.AlternateFormsOS.Add(catNForm); catNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("catNTEST", m_vernacularWS.Handle); IMoStemMsa catNMsa = m_stemMsaFactory.Create(); catN.MorphoSyntaxAnalysesOC.Add(catNMsa); ILexEntry sPl = m_entryFactory.Create(); IMoAffixAllomorph sPlForm = m_afxAlloFactory.Create(); sPl.AlternateFormsOS.Add(sPlForm); sPlForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sPLTEST", m_vernacularWS.Handle); IMoInflAffMsa sPlMsa = m_inflAffMsaFactory.Create(); sPl.MorphoSyntaxAnalysesOC.Add(sPlMsa); // Verb ILexEntry catV = m_entryFactory.Create(); IMoStemAllomorph catVForm = m_stemAlloFactory.Create(); catV.AlternateFormsOS.Add(catVForm); catVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("catVTEST", m_vernacularWS.Handle); IMoStemMsa catVMsa = m_stemMsaFactory.Create(); catV.MorphoSyntaxAnalysesOC.Add(catVMsa); ILexEntry sAgr = m_entryFactory.Create(); IMoAffixAllomorph sAgrForm = m_afxAlloFactory.Create(); sAgr.AlternateFormsOS.Add(sAgrForm); sAgrForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sAGRTEST", m_vernacularWS.Handle); IMoInflAffMsa sAgrMsa = m_inflAffMsaFactory.Create(); sAgr.MorphoSyntaxAnalysesOC.Add(sAgrMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(catNForm, catNMsa), new ParseMorph(sPlForm, sPlMsa) }), new ParseAnalysis(new[] { new ParseMorph(catVForm, catVMsa), new ParseMorph(sAgrForm, sAgrMsa) }) }); }); m_filer.ProcessParse(catsTest, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("catsTEST", 2, false); }
private static void WriteInflMsaXmlElement(XmlWriter writer, IMoInflAffMsa inflMsa, string type) { writer.WriteStartElement("inflMsa"); WritePosXmlAttribute(writer, inflMsa.PartOfSpeechRA, "cat"); // handle any slot HandleSlotInfoForInflectionalMsa(writer, inflMsa, type); WriteFeatureStructureNodes(writer, inflMsa.InflFeatsOA, inflMsa.Hvo); WriteProductivityRestrictionNodes(writer, inflMsa.FromProdRestrictRC, "fromProductivityRestriction"); writer.WriteEndElement(); //inflMsa }
protected void CreateInflMsaXmlElement(XmlDocument doc, XmlNode morphNode, IMoInflAffMsa inflMsa) { XmlNode inflMsaNode = CreateXmlElement(doc, "inflMsa", morphNode); CreatePOSXmlAttribute(doc, inflMsaNode, inflMsa.PartOfSpeechRA, "cat"); // handle any slot HandleSlotInfoForInflectionalMsa(inflMsa, doc, inflMsaNode, morphNode); CreateFeatureStructureNodes(doc, inflMsaNode, inflMsa.InflFeatsOA, inflMsa.Hvo); CreateProductivityRestrictionNodes(doc, inflMsaNode, inflMsa.FromProdRestrictRC, "fromProductivityRestriction"); }
protected void HandleSlotInfoForInflectionalMsa(IMoInflAffMsa inflMsa, XmlDocument doc, XmlNode inflMsaNode, XmlNode morphNode) { int slotHvo = 0; int iCount = inflMsa.SlotsRC.Count; if (iCount > 0) { if (iCount > 1) { // have a circumfix; assume only two slots and assume that the first is prefix and second is suffix // TODO: ideally would figure out if the slots are prefix or suffix slots and then align the // o and 1 indices to the appropriate slot. Will just do this for now (hab 2005.08.04). XmlNode attrType = morphNode.SelectSingleNode("@type"); if (attrType != null && attrType.InnerText != "sfx") { slotHvo = inflMsa.SlotsRC.HvoArray[0]; } else { slotHvo = inflMsa.SlotsRC.HvoArray[1]; } } else { slotHvo = inflMsa.SlotsRC.HvoArray[0]; } } CreateXmlAttribute(doc, "slot", slotHvo.ToString(), inflMsaNode); string sSlotOptional = "false"; string sSlotAbbr = "??"; if (slotHvo > 0) { MoInflAffixSlot slot = (MoInflAffixSlot)CmObject.CreateFromDBObject(this.m_cache, slotHvo); if (slot != null) { sSlotAbbr = slot.Name.BestAnalysisAlternative.Text; if (slot.Optional) { sSlotOptional = "true"; } } } CreateXmlAttribute(doc, "slotAbbr", sSlotAbbr, inflMsaNode); CreateXmlAttribute(doc, "slotOptional", sSlotOptional, inflMsaNode); }
private static void HandleSlotInfoForInflectionalMsa(XmlWriter writer, IMoInflAffMsa inflMsa, string type) { int slotHvo = 0; int iCount = inflMsa.SlotsRC.Count; if (iCount > 0) { if (iCount > 1) { // have a circumfix; assume only two slots and assume that the first is prefix and second is suffix // TODO: ideally would figure out if the slots are prefix or suffix slots and then align the // o and 1 indices to the appropriate slot. Will just do this for now (hab 2005.08.04). if (type != null && type != "sfx") { slotHvo = inflMsa.SlotsRC.ToHvoArray()[0]; } else { slotHvo = inflMsa.SlotsRC.ToHvoArray()[1]; } } else { slotHvo = inflMsa.SlotsRC.ToHvoArray()[0]; } } writer.WriteAttributeString("slot", slotHvo.ToString(CultureInfo.InvariantCulture)); string sSlotOptional = "false"; string sSlotAbbr = "??"; if (Convert.ToInt32(slotHvo) > 0) { var slot = inflMsa.Services.GetInstance <IMoInflAffixSlotRepository>().GetObject(Convert.ToInt32(slotHvo)); if (slot != null) { sSlotAbbr = slot.Name.BestAnalysisAlternative.Text; if (slot.Optional) { sSlotOptional = "true"; } } } writer.WriteAttributeString("slotAbbr", sSlotAbbr); writer.WriteAttributeString("slotOptional", sSlotOptional); }
protected void CreateMsaXmlElement(XmlNode node, XmlDocument doc, XmlNode morphNode, string sHvo) { XmlNode attr; // morphname contains the hvo of the msa attr = node.SelectSingleNode(sHvo); if (attr != null) { ICmObject obj = CmObject.CreateFromDBObject(m_cache, Convert.ToInt32(attr.Value)); switch (obj.GetType().Name) { default: throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name)); case "MoStemMsa": IMoStemMsa stemMsa = obj as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); break; case "MoInflAffMsa": IMoInflAffMsa inflMsa = obj as IMoInflAffMsa; CreateInflectionClasses(doc, morphNode); CreateInflMsaXmlElement(doc, morphNode, inflMsa); break; case "MoDerivAffMsa": IMoDerivAffMsa derivMsa = obj as IMoDerivAffMsa; CreateDerivMsaXmlElement(doc, morphNode, derivMsa); break; case "MoUnclassifiedAffixMsa": IMoUnclassifiedAffixMsa unclassMsa = obj as IMoUnclassifiedAffixMsa; CreateUnclassifedMsaXmlElement(doc, morphNode, unclassMsa); break; } } }
/// <summary> /// /// </summary> /// <param name="inflMsa"></param> /// <returns></returns> protected bool HasSameSlots(IMoInflAffMsa inflMsa) { if (SlotsRC.Count != inflMsa.SlotsRC.Count) return false; var otherSlots = new List<ICmObject>(inflMsa.SlotsRC.Objects); foreach (var mySlot in SlotsRC.Objects) { if (!otherSlots.Contains(mySlot)) return false; otherSlots.Remove(mySlot); // ensure unique matches. } return true; }
///<summary> /// Copies attributes associated with the current POS, such as inflection features and classes, that /// are valid from the specified MSA to this MSA. If the attribute is not valid, it is removed from /// this MSA. ///</summary> ///<param name="srcMsa">the source MSA</param> public void CopyAttributesIfValid(IMoInflAffMsa srcMsa) { // inflection features if (srcMsa.InflFeatsOA == null) { InflFeatsOA = null; } else { if (InflFeatsOA != srcMsa.InflFeatsOA) CopyObject<IFsFeatStruc>.CloneFdoObject(srcMsa.InflFeatsOA, newMsa => InflFeatsOA = newMsa); RemoveInvalidFeatureSpecs(PartOfSpeechRA, InflFeatsOA); if (InflFeatsOA.IsEmpty) InflFeatsOA = null; } }
private void WriteMoInflAffMsa(TextWriter w, IMoInflAffMsa msa) { if (String.IsNullOrEmpty(msa.PosFieldName)) w.WriteLine("<grammatical-info value=\"\">"); else w.WriteLine("<grammatical-info value=\"{0}\">", MakeSafeAndNormalizedAttribute(msa.PosFieldName)); w.WriteLine("<trait name=\"type\" value=\"inflAffix\"/>"); foreach (var slot in msa.SlotsRC) { w.Write("<trait name=\"{0}-slot\" value=\"{1}\"/>", MakeSafeAndNormalizedAttribute(slot.Owner.ShortName), BestAlternative(slot.Name, m_wsEn)); } if (msa.InflFeatsOA != null && !msa.InflFeatsOA.IsEmpty) w.WriteLine("<trait name=\"{0}\" value=\"{1}\"/>", RangeNames.sMSAinflectionFeature, MakeSafeAndNormalizedAttribute(msa.InflFeatsOA.LiftName)); foreach (var restrict in msa.FromProdRestrictRC) WriteTrait(w, RangeNames.sProdRestrictOA, restrict.Name, m_wsBestAnalVern); WriteLiftResidue(w, msa); w.WriteLine("</grammatical-info>"); }
protected void HandleSlotInfoForInflectionalMsa(IMoInflAffMsa inflMsa, XmlDocument doc, XmlNode inflMsaNode, XmlNode morphNode) { int slotHvo = 0; int iCount = inflMsa.SlotsRC.Count; if (iCount > 0) { if (iCount > 1) { // have a circumfix; assume only two slots and assume that the first is prefix and second is suffix // TODO: ideally would figure out if the slots are prefix or suffix slots and then align the // o and 1 indices to the appropriate slot. Will just do this for now (hab 2005.08.04). XmlNode attrType = morphNode.SelectSingleNode("@type"); if (attrType != null && attrType.InnerText != "sfx") slotHvo = inflMsa.SlotsRC.HvoArray[0]; else slotHvo = inflMsa.SlotsRC.HvoArray[1]; } else slotHvo = inflMsa.SlotsRC.HvoArray[0]; } CreateXmlAttribute(doc, "slot", slotHvo.ToString(), inflMsaNode); string sSlotOptional = "false"; string sSlotAbbr = "??"; if (slotHvo > 0) { MoInflAffixSlot slot = (MoInflAffixSlot)CmObject.CreateFromDBObject(this.m_cache, slotHvo); if (slot != null) { sSlotAbbr = slot.Name.BestAnalysisAlternative.Text; if (slot.Optional) sSlotOptional = "true"; } } CreateXmlAttribute(doc, "slotAbbr", sSlotAbbr, inflMsaNode); CreateXmlAttribute(doc, "slotOptional", sSlotOptional, inflMsaNode); }
private void EnsureNewMsaHasSense(ILexEntry lex, IMoInflAffMsa newMsa) { // if no lexsense has this msa, copy first sense and have it refer to this msa bool fASenseHasMsa = false; foreach (ILexSense sense in lex.AllSenses) { if (sense.MorphoSyntaxAnalysisRAHvo == newMsa.Hvo) { fASenseHasMsa = true; break; } } if (!fASenseHasMsa) { ILexSense newSense = new FDO.Ling.LexSense(); lex.SensesOS.Append(newSense); ILexSense firstSense = lex.SensesOS.FirstItem; // only copying gloss for now and only copying default analysis ws //newSense.Definition.AnalysisDefaultWritingSystem.Text = firstSense.Definition.AnalysisDefaultWritingSystem.Text; newSense.Gloss.AnalysisDefaultWritingSystem = firstSense.Gloss.AnalysisDefaultWritingSystem; //newSense.GrammarNote.AnalysisDefaultWritingSystem.Text = firstSense.GrammarNote.AnalysisDefaultWritingSystem.Text; //newSense.SemanticsNote.AnalysisDefaultWritingSystem.Text = firstSense.SemanticsNote.AnalysisDefaultWritingSystem.Text; newSense.MorphoSyntaxAnalysisRA = newMsa; } }
protected void CreateMsaXmlElement(XmlNode node, XmlDocument doc, XmlNode morphNode, string sHvo) { XmlNode attr; // morphname contains the hvo of the msa attr = node.SelectSingleNode(sHvo); if (attr != null) { string sObjHvo = attr.Value; // Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef var indexOfPeriod = ParseFiler.IndexOfPeriodInMsaHvo(ref sObjHvo); ICmObject obj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(Convert.ToInt32(sObjHvo)); switch (obj.GetType().Name) { default: throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name)); case "MoStemMsa": IMoStemMsa stemMsa = obj as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); break; case "MoInflAffMsa": IMoInflAffMsa inflMsa = obj as IMoInflAffMsa; CreateInflectionClasses(doc, morphNode); CreateInflMsaXmlElement(doc, morphNode, inflMsa); break; case "MoDerivAffMsa": IMoDerivAffMsa derivMsa = obj as IMoDerivAffMsa; CreateDerivMsaXmlElement(doc, morphNode, derivMsa); break; case "MoUnclassifiedAffixMsa": IMoUnclassifiedAffixMsa unclassMsa = obj as IMoUnclassifiedAffixMsa; CreateUnclassifedMsaXmlElement(doc, morphNode, unclassMsa); break; case "LexEntry": // is an irregularly inflected form // get the MoStemMsa of its variant var entry = obj as ILexEntry; if (entry.EntryRefsOS.Count > 0) { var index = ParseFiler.IndexOfLexEntryRef(attr.Value, indexOfPeriod); var lexEntryRef = entry.EntryRefsOS[index]; var sense = FDO.DomainServices.MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef); stemMsa = sense.MorphoSyntaxAnalysisRA as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); } break; case "LexEntryInflType": // This is one of the null allomorphs we create when building the // input for the parser in order to still get the Word Grammar to have something in any // required slots in affix templates. CreateInflMsaForLexEntryInflType(doc, morphNode, obj as ILexEntryInflType); break; } } }
private bool OtherInflAffixMsasExist(ILexEntry lex, IMoInflAffMsa inflMsa) { bool fOtherInflAffixMsasExist = false; // assume we won't find an existing infl affix msa foreach (var msa in lex.MorphoSyntaxAnalysesOC) { if (msa.ClassID == MoInflAffMsaTags.kClassId) { // is an inflectional affix msa if (msa != inflMsa) { // it's not the one the user requested to remove fOtherInflAffixMsasExist = true; break; } } } return fOtherInflAffixMsasExist; }
public void LexEntryInflTypeTwoAnalyses() { IWfiWordform creb = CheckAnalysisSize("crebTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb creb which is a past tense, plural irregularly inflected form of 'believe' and also 'seek' // with automatically generated null Tense slot and an automatically generated null Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType pastTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); ILexEntryInflType pluralTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pastTenseLexEntryInflType); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pluralTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("believeVTEST", m_vernacularWS.Handle); IMoStemMsa believeVMsa = m_stemMsaFactory.Create(); believeV.MorphoSyntaxAnalysesOC.Add(believeVMsa); ILexSense believeVSense = m_senseFactory.Create(); believeV.SensesOS.Add(believeVSense); believeVSense.MorphoSyntaxAnalysisRA = believeVMsa; ILexEntry seekV = m_entryFactory.Create(); IMoStemAllomorph seekVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(seekVForm); seekVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("seekVTEST", m_vernacularWS.Handle); IMoStemMsa seekVMsa = m_stemMsaFactory.Create(); seekV.MorphoSyntaxAnalysesOC.Add(seekVMsa); ILexSense seekVSense = m_senseFactory.Create(); seekV.SensesOS.Add(seekVSense); seekVSense.MorphoSyntaxAnalysisRA = seekVMsa; ILexEntry crebV = m_entryFactory.Create(); IMoStemAllomorph crebVForm = m_stemAlloFactory.Create(); crebV.AlternateFormsOS.Add(crebVForm); crebVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("crebVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(seekV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); ILexEntry nullPast = m_entryFactory.Create(); IMoAffixAllomorph nullPastForm = m_afxAlloFactory.Create(); nullPast.AlternateFormsOS.Add(nullPastForm); nullPastForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPASTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPastMsa = m_inflAffMsaFactory.Create(); nullPast.MorphoSyntaxAnalysesOC.Add(nullPastMsa); ILexEntry nullPlural = m_entryFactory.Create(); IMoAffixAllomorph nullPluralForm = m_afxAlloFactory.Create(); nullPlural.AlternateFormsOS.Add(nullPluralForm); nullPluralForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPluralMsa = m_inflAffMsaFactory.Create(); nullPlural.MorphoSyntaxAnalysesOC.Add(nullPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[1]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[1].VariantEntryTypesRS[0]) }), new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[0].VariantEntryTypesRS[0]) }) }); }); m_filer.ProcessParse(creb, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("crebTEST", 2, false); foreach (var analysis in creb.AnalysesOC) { Assert.AreEqual(1, analysis.MorphBundlesOS.Count, "Expected only 1 morph in the analysis"); var morphBundle = analysis.MorphBundlesOS.ElementAt(0); Assert.IsNotNull(morphBundle.Form, "First bundle: form is not null"); Assert.IsNotNull(morphBundle.MsaRA, "First bundle: msa is not null"); Assert.IsNotNull(morphBundle.InflTypeRA, "First bundle: infl type is not null"); } }
/// <summary> /// Constructor. /// </summary> private DummyGenericMSA(IMoInflAffMsa inflMsa) { m_type = MsaType.kInfl; m_mainPOS = inflMsa.PartOfSpeechRAHvo; //m_slot = inflMsa.SlotsRC; }
/// <summary> /// /// </summary> /// <param name="inflMsa"></param> /// <returns></returns> protected bool HasSameSlots(IMoInflAffMsa inflMsa) { if (SlotsRC.Count != inflMsa.SlotsRC.Count) return false; List<int> inflMsaSlots = new List<int>(inflMsa.SlotsRC.HvoArray); for (int ihvo = 0; ihvo < SlotsRC.Count; ihvo++) { if (!inflMsaSlots.Contains(SlotsRC.HvoArray[ihvo])) return false; inflMsaSlots.Remove(SlotsRC.HvoArray[ihvo]); // ensure unique matches. } return true; }
public void TwoAnalyses() { int hvoBearTEST = CheckAnalysisSize("bearsTEST", 0, true); string xmlFragment = ""; using (FdoCache cache = FdoCache.Create("TestLangProj")) { ILexDb ldb = cache.LangProject.LexDbOA; // Noun ILexEntry bearN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearN.Hvo); IMoStemAllomorph bearNForm = (IMoStemAllomorph)bearN.AlternateFormsOS.Append(new MoStemAllomorph()); bearNForm.Form.VernacularDefaultWritingSystem = "bearNTEST"; IMoStemMsa bearNMSA = (IMoStemMsa)bearN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexEntry sPL = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(sPL.Hvo); IMoAffixAllomorph sPLForm = (IMoAffixAllomorph)sPL.AlternateFormsOS.Append(new MoAffixAllomorph()); sPLForm.Form.VernacularDefaultWritingSystem = "sPLTEST"; IMoInflAffMsa sPLMSA = (IMoInflAffMsa)sPL.MorphoSyntaxAnalysesOC.Add(new MoInflAffMsa()); // Verb ILexEntry bearV = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearV.Hvo); IMoStemAllomorph bearVForm = (IMoStemAllomorph)bearV.AlternateFormsOS.Append(new MoStemAllomorph()); bearVForm.Form.VernacularDefaultWritingSystem = "bearVTEST"; IMoStemMsa bearVMSA = (IMoStemMsa)bearV.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexEntry sAGR = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(sAGR.Hvo); IMoAffixAllomorph sAGRForm = (IMoAffixAllomorph)sAGR.AlternateFormsOS.Append(new MoAffixAllomorph()); sAGRForm.Form.VernacularDefaultWritingSystem = "sAGRTEST"; IMoInflAffMsa sAGRMSA = (IMoInflAffMsa)sAGR.MorphoSyntaxAnalysesOC.Add(new MoInflAffMsa()); xmlFragment = "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearsTEST'>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n" + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "<Morph>\n" + "<MoForm DbRef='" + sPLForm.Hvo.ToString() + "' Label='sPLTEST'/>\n" + "<MSI DbRef='" + sPLMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearVForm.Hvo.ToString() + "' Label='bearVTEST'/>\n" + "<MSI DbRef='" + bearVMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "<Morph>\n" + "<MoForm DbRef='" + sAGRForm.Hvo.ToString() + "' Label='sAGRTEST'/>\n" + "<MSI DbRef='" + sAGRMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "</Wordform>\n"; } m_filer.ProcessParse(MakeXML(xmlFragment, true)); CheckAnalysisSize("bearsTEST", 2, false); }
private ITsString TsSlotNameOfMsa(IMoInflAffMsa msa) { ITsString tssResult = null; IMoInflAffixSlot slot = null; #if !MaybeSomeDayToTryAndGetRemoveMsaCorrectForCircumfixes if (msa.SlotsRC.Count > 0) { slot = msa.SlotsRC.First(); } tssResult = TsSlotName(slot); m_slot = slot; #else slot = (FDO.Ling.MoInflAffixSlot)CmObject.CreateFromDBObject(this.Cache, m_hvoSlot); sResult = TsSlotName(slot); #endif return tssResult; }
private void EnsureNewMsaHasSense(ILexEntry lex, IMoInflAffMsa newMsa) { // if no lexsense has this msa, copy first sense and have it refer to this msa bool fASenseHasMsa = false; foreach (var sense in lex.AllSenses) { if (sense.MorphoSyntaxAnalysisRA == newMsa) { fASenseHasMsa = true; break; } } if (!fASenseHasMsa) { var newSense = Cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(); lex.SensesOS.Add(newSense); var firstSense = lex.SensesOS[0]; // only copying gloss for now and only copying default analysis ws //newSense.Definition.AnalysisDefaultWritingSystem.Text = firstSense.Definition.AnalysisDefaultWritingSystem.Text; newSense.Gloss.AnalysisDefaultWritingSystem = firstSense.Gloss.AnalysisDefaultWritingSystem; //newSense.GrammarNote.AnalysisDefaultWritingSystem.Text = firstSense.GrammarNote.AnalysisDefaultWritingSystem.Text; //newSense.SemanticsNote.AnalysisDefaultWritingSystem.Text = firstSense.SemanticsNote.AnalysisDefaultWritingSystem.Text; newSense.MorphoSyntaxAnalysisRA = newMsa; } }
public void LexEntryInflTypeAnalysisWithNullForSlotFiller() { IWfiWordform brubs = CheckAnalysisSize("brubsTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb brub which is a present tense irregularly inflected form of 'believe' // with automatically generated null Tense slot and an -s Plural Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType presentTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(presentTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("believeVTEST", m_vernacularWS.Handle); IMoStemMsa believeVMsa = m_stemMsaFactory.Create(); believeV.MorphoSyntaxAnalysesOC.Add(believeVMsa); ILexSense believeVSense = m_senseFactory.Create(); believeV.SensesOS.Add(believeVSense); believeVSense.MorphoSyntaxAnalysisRA = believeVMsa; ILexEntry brubV = m_entryFactory.Create(); IMoStemAllomorph brubVForm = m_stemAlloFactory.Create(); brubV.AlternateFormsOS.Add(brubVForm); brubVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("brubVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); brubV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(presentTenseLexEntryInflType); ILexEntry nullPresent = m_entryFactory.Create(); IMoAffixAllomorph nullPresentForm = m_afxAlloFactory.Create(); nullPresent.AlternateFormsOS.Add(nullPresentForm); nullPresentForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("nullPRESENTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPresentMsa = m_inflAffMsaFactory.Create(); nullPresent.MorphoSyntaxAnalysesOC.Add(nullPresentMsa); ILexEntry sPlural = m_entryFactory.Create(); IMoAffixAllomorph sPluralForm = m_afxAlloFactory.Create(); sPlural.AlternateFormsOS.Add(sPluralForm); sPluralForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa sPluralMsa = m_inflAffMsaFactory.Create(); sPlural.MorphoSyntaxAnalysesOC.Add(sPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(brubVForm, MorphServices.GetMainOrFirstSenseOfVariant(brubV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)brubV.EntryRefsOS[0].VariantEntryTypesRS[0]), new ParseMorph(sPluralForm, sPluralMsa) }) }); }); m_filer.ProcessParse(brubs, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("brubsTEST", 1, false); var analysis = brubs.AnalysesOC.ElementAt(0); Assert.AreEqual(2, analysis.MorphBundlesOS.Count, "Expected only 2 morphs in the analysis"); var morphBundle = analysis.MorphBundlesOS.ElementAt(0); Assert.IsNotNull(morphBundle.Form, "First bundle: form is not null"); Assert.IsNotNull(morphBundle.MsaRA, "First bundle: msa is not null"); Assert.IsNotNull(morphBundle.InflTypeRA, "First bundle: infl type is not null"); }
private bool CheckForAffixDataLoss(IMoAffixForm affix, List <IMoMorphSynAnalysis> rgmsaAffix) { bool fLoseInflCls = affix.InflectionClassesRC.Count > 0; bool fLoseInfixLoc = false; bool fLoseGramInfo = false; bool fLoseRule = false; switch (affix.ClassID) { case MoAffixProcess.kclsidMoAffixProcess: fLoseRule = true; break; case MoAffixAllomorph.kclsidMoAffixAllomorph: IMoAffixAllomorph allo = affix as IMoAffixAllomorph; fLoseInfixLoc = allo.PositionRS.Count > 0; fLoseGramInfo = allo.MsEnvPartOfSpeechRAHvo != 0 || allo.MsEnvFeaturesOAHvo != 0; break; } for (int i = 0; !fLoseGramInfo && i < rgmsaAffix.Count; ++i) { IMoInflAffMsa msaInfl = rgmsaAffix[i] as IMoInflAffMsa; if (msaInfl != null) { if (msaInfl.AffixCategoryRAHvo != 0 || msaInfl.FromProdRestrictRC.Count > 0 || msaInfl.SlotsRC.Count > 0 || msaInfl.InflFeatsOAHvo != 0) { fLoseGramInfo = true; } continue; } IMoDerivAffMsa msaDeriv = rgmsaAffix[i] as IMoDerivAffMsa; if (msaDeriv != null) { if (msaDeriv.AffixCategoryRAHvo != 0 || msaDeriv.FromInflectionClassRAHvo != 0 || msaDeriv.FromPartOfSpeechRAHvo != 0 || msaDeriv.FromProdRestrictRC.Count > 0 || msaDeriv.FromStemNameRAHvo != 0 || msaDeriv.StratumRAHvo != 0 || msaDeriv.ToInflectionClassRAHvo != 0 || msaDeriv.ToProdRestrictRC.Count > 0 || msaDeriv.FromMsFeaturesOAHvo != 0 || msaDeriv.ToMsFeaturesOAHvo != 0) { fLoseGramInfo = true; } continue; } IMoDerivStepMsa msaStep = rgmsaAffix[i] as IMoDerivStepMsa; if (msaStep != null) { if (msaStep.InflectionClassRAHvo != 0 || msaStep.ProdRestrictRC.Count > 0 || msaStep.InflFeatsOAHvo != 0 || msaStep.MsFeaturesOAHvo != 0) { fLoseGramInfo = true; } continue; } } if (fLoseInflCls || fLoseInfixLoc || fLoseGramInfo || fLoseRule) { string sMsg; if (fLoseInflCls && fLoseInfixLoc && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsInfixLocGramInfo", m_ksPath); } else if (fLoseRule && fLoseInflCls && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRuleInflClsGramInfo", m_ksPath); } else if (fLoseInflCls && fLoseInfixLoc) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsInfixLoc", m_ksPath); } else if (fLoseInflCls && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsGramInfo", m_ksPath); } else if (fLoseInfixLoc && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInfixLocGramInfo", m_ksPath); } else if (fLoseRule && fLoseInflCls) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRuleInflCls", m_ksPath); } else if (fLoseRule) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRule", m_ksPath); } else if (fLoseInflCls) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflCls", m_ksPath); } else if (fLoseInfixLoc) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInfixLoc", m_ksPath); } else { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseGramInfo", m_ksPath); } string sCaption = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeCaption", m_ksPath); DialogResult result = MessageBox.Show(sMsg, sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return(true); } } return(false); }
private static void HandleSlotInfoForInflectionalMsa(XmlWriter writer, IMoInflAffMsa inflMsa, string type) { int slotHvo = 0; int iCount = inflMsa.SlotsRC.Count; if (iCount > 0) { if (iCount > 1) { // have a circumfix; assume only two slots and assume that the first is prefix and second is suffix // TODO: ideally would figure out if the slots are prefix or suffix slots and then align the // o and 1 indices to the appropriate slot. Will just do this for now (hab 2005.08.04). if (type != null && type != "sfx") slotHvo = inflMsa.SlotsRC.ToHvoArray()[0]; else slotHvo = inflMsa.SlotsRC.ToHvoArray()[1]; } else slotHvo = inflMsa.SlotsRC.ToHvoArray()[0]; } writer.WriteAttributeString("slot", slotHvo.ToString(CultureInfo.InvariantCulture)); string sSlotOptional = "false"; string sSlotAbbr = "??"; if (Convert.ToInt32(slotHvo) > 0) { var slot = inflMsa.Services.GetInstance<IMoInflAffixSlotRepository>().GetObject(Convert.ToInt32(slotHvo)); if (slot != null) { sSlotAbbr = slot.Name.BestAnalysisAlternative.Text; if (slot.Optional) sSlotOptional = "true"; } } writer.WriteAttributeString("slotAbbr", sSlotAbbr); writer.WriteAttributeString("slotOptional", sSlotOptional); }
private ITsString TsSlotNameOfMsa(IMoInflAffMsa msa) { ITsString tssResult = null; IMoInflAffixSlot slot = null; #if !MaybeSomeDayToTryAndGetRemoveMsaCorrectForCircumfixes int[] hvos = msa.SlotsRC.HvoArray; if (hvos.Length > 0) { int hvo = hvos[0]; slot = MoInflAffixSlot.CreateFromDBObject(this.Cache, hvo); } tssResult = TsSlotName(slot); m_hvoSlot = slot.Hvo; #else slot = (FDO.Ling.MoInflAffixSlot)CmObject.CreateFromDBObject(this.Cache, m_hvoSlot); sResult = TsSlotName(slot); #endif return tssResult; }