public void Init(Mediator mediator, XmlNode configurationNode, ICmObject sourceObject)
		{
			CheckDisposed();

			m_cache = sourceObject.Cache;

			// Find the sense owning our LexExampleSentence
			if (sourceObject is LexExampleSentence)
			{
				m_les = sourceObject as LexExampleSentence;
				m_owningSense = LexSense.CreateFromDBObject(m_cache, m_les.OwnerHVO);
			}
			else if (sourceObject is LexSense)
			{
				m_owningSense = sourceObject as ILexSense;
			}
			else
			{
				throw new ArgumentException("Invalid object type for sourceObject.");
			}

			m_mediator = mediator;
			m_configurationNode = configurationNode;
			AddConfigurableControls();

			m_virtFlidReference = BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "CmBaseAnnotation", "Reference");
		}
		public void Init(Mediator mediator, XmlNode configurationNode, ICmObject sourceObject)
		{
			CheckDisposed();

			m_cache = sourceObject.Cache;

			// Find the sense we want examples for, which depends on the kind of source object.
			if (sourceObject is ILexExampleSentence)
			{
				m_les = sourceObject as ILexExampleSentence;
				m_owningSense = (ILexSense)m_les.Owner;
			}
			else if (sourceObject is ILexSense)
			{
				m_owningSense = sourceObject as ILexSense;
			}
			else
			{
				throw new ArgumentException("Invalid object type for sourceObject.");
			}

			m_mediator = mediator;
			m_configurationNode = configurationNode;

			helpProvider.SetHelpNavigator(this, HelpNavigator.Topic);
			helpProvider.SetShowHelp(this, true);
			if (m_mediator.HelpTopicProvider != null)
			{
				helpProvider.HelpNamespace = m_mediator.HelpTopicProvider.HelpFile;
				helpProvider.SetHelpKeyword(this, m_mediator.HelpTopicProvider.GetHelpString(m_helpTopic));
				btnHelp.Enabled = true;
			}

			AddConfigurableControls();
		}
		/// <summary>
		/// Takes the gloss, a short definition (if only one or two words), and reversal from a LexSense
		/// and uses those words as search keys to find Semantic Domains that have one of those words in
		/// their Name or Example Words fields.
		/// In addition, this method returns additional partial matches in the 'out' parameter where one
		/// of the search keys matches the beginning of one of the words in the domain's Name or Example
		/// Words fields.
		///
		/// N.B.: This method looks for matches in the AnalysisDefaultWritingSystem.
		/// This ought to help ensure that we are searching in the Semantic Domain fields in the same
		/// writing system as the one the search keys in the Sense came from.
		/// </summary>
		/// <param name="sense">A LexSense</param>
		/// <param name="partialMatches">extra partial matches</param>
		/// <returns></returns>
		public IEnumerable<ICmSemanticDomain> FindDomainsThatMatchWordsIn(ILexSense sense,
			out IEnumerable<ICmSemanticDomain> partialMatches)
		{
			var strategy = new SenseSearchStrategy(Cache, sense);
			new SemDomSearchEngine(Cache).WalkDomains(strategy);

			partialMatches = strategy.PartialMatches;

			return strategy.FindResults;
		}
Esempio n. 4
0
		/// ------------------------------------------------------------------------------------
		internal PaLexSense(ILexSense lxSense)
		{
			var svcloc = lxSense.Cache.ServiceLocator;

			xAnthropologyNote = PaMultiString.Create(lxSense.AnthroNote, svcloc);
			xBibliography = PaMultiString.Create(lxSense.Bibliography, svcloc);
			xDefinition = PaMultiString.Create(lxSense.Definition, svcloc);
			xDiscourseNote = PaMultiString.Create(lxSense.DiscourseNote, svcloc);
			xEncyclopedicInfo = PaMultiString.Create(lxSense.EncyclopedicInfo, svcloc);
			xGeneralNote = PaMultiString.Create(lxSense.GeneralNote, svcloc);
			xGloss = PaMultiString.Create(lxSense.Gloss, svcloc);
			xGrammarNote = PaMultiString.Create(lxSense.GrammarNote, svcloc);
			xPhonologyNote = PaMultiString.Create(lxSense.PhonologyNote, svcloc);
			xRestrictions = PaMultiString.Create(lxSense.Restrictions, svcloc);
			xSemanticsNote = PaMultiString.Create(lxSense.SemanticsNote, svcloc);
			xSociolinguisticsNote = PaMultiString.Create(lxSense.SocioLinguisticsNote, svcloc);
			xReversalEntries = lxSense.ReversalEntriesRC.Select(x => PaMultiString.Create(x.ReversalForm, svcloc)).ToList();
			xGuid = lxSense.Guid;

			ImportResidue = lxSense.ImportResidue.Text;
			Source = lxSense.Source.Text;
			ScientificName = lxSense.ScientificName.Text;

			xAnthroCodes = lxSense.AnthroCodesRC.Select(x => PaCmPossibility.Create(x)).ToList();
			xDomainTypes = lxSense.DomainTypesRC.Select(x => PaCmPossibility.Create(x)).ToList();
			xUsages = lxSense.UsageTypesRC.Select(x => PaCmPossibility.Create(x)).ToList();
			xSemanticDomains = lxSense.SemanticDomainsRC.Select(x => PaCmPossibility.Create(x)).ToList();
			xStatus = PaCmPossibility.Create(lxSense.StatusRA);
			xSenseType = PaCmPossibility.Create(lxSense.SenseTypeRA);

			ICmPossibility poss = null;
			var msa = lxSense.MorphoSyntaxAnalysisRA;
			if (msa is IMoDerivAffMsa)
				poss = ((IMoDerivAffMsa)msa).FromPartOfSpeechRA;
			else if (msa is IMoDerivStepMsa)
				poss = ((IMoDerivStepMsa)msa).PartOfSpeechRA;
			else if (msa is IMoInflAffMsa)
				poss = ((IMoInflAffMsa)msa).PartOfSpeechRA;
			else if (msa is IMoStemMsa)
				poss = ((IMoStemMsa)msa).PartOfSpeechRA;
			else if (msa is IMoUnclassifiedAffixMsa)
				poss = ((IMoUnclassifiedAffixMsa)msa).PartOfSpeechRA;

			if (poss != null)
				xPartOfSpeech = PaCmPossibility.Create(poss);
		}
		/// <summary>
		/// It's convenient to test pretty much all these functions with one set of data.
		/// </summary>
		///
		public override void FixtureSetup()
		{
			base.FixtureSetup();
			m_wsVern = Cache.DefaultVernWs;
			m_wsAnalysis = Cache.DefaultAnalWs;
			m_hc = Cache.ServiceLocator.GetInstance<HomographConfiguration>();
			UndoableUnitOfWorkHelper.Do("undoit", "redoit", m_actionHandler,
				() =>
					{
						m_kick = MakeEntry("kick", "strike with foot");
						m_kickS1 = m_kick.SensesOS[0];
						m_rightCorrect = MakeEntry("right", "correct");
						m_rightCorrectS2 = MakeSense(m_rightCorrect, "morally perfect");
						m_rightDirection = MakeEntry("right", "turn right");
						m_rightDirectionS1 = m_rightDirection.SensesOS[0];
					});
		}
Esempio n. 6
0
        private IWfiMorphBundle SetupMorphBundleForEntry(AnalysisOccurrence cba0_0, string gloss, ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, out IWfiWordform wf)
        {
            IWfiAnalysis analysis = SetupAnalysisForEntry(cba0_0, gloss, lexEntry1_Sense1, out wf);

            return(AppendMorphBundleToAnalysis(lexEntry1_Entry, lexEntry1_Sense1, analysis));
        }
        public void UndoRedoIncomingRefs()
        {
            var servLoc = Cache.ServiceLocator;

            var leFact = servLoc.GetInstance <ILexEntryFactory>();
            var le1    = leFact.Create();

            var lsFact = servLoc.GetInstance <ILexSenseFactory>();
            var ls1    = lsFact.Create();

            le1.SensesOS.Add(ls1);

            if (Cache.LangProject.StatusOA == null)
            {
                Cache.LangProject.StatusOA = servLoc.GetInstance <ICmPossibilityListFactory>().Create();
            }
            var possFact = servLoc.GetInstance <ICmPossibilityFactory>();
            var status1  = possFact.Create();

            Cache.LangProject.StatusOA.PossibilitiesOS.Add(status1);

            Cache.ActionHandlerAccessor.EndUndoTask();             // so we can have our own units of work to test Undo

            // Atomic
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => ls1.StatusRA = status1);
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();             // leave it Undone so it doesn't affect the ref collection test below.
            Assert.AreEqual(0, status1.ReferringObjects.Count);

            // Ref sequence
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => le1.MainEntriesOrSensesRS.Add(ls1));
            Assert.AreEqual(1, ls1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, ls1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, ls1.ReferringObjects.Count);
            m_actionHandler.Undo();             // cleanup
            Assert.AreEqual(0, ls1.ReferringObjects.Count);

            // Ref collection
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => ls1.DomainTypesRC.Add(status1));
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();             // cleanup
            Assert.AreEqual(0, status1.ReferringObjects.Count);

            ILexSense ls2 = null;

            // Now see if it happens properly when we Undo and Redo object creation and deletion.
            // Atomic
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () =>
            {
                ls2 = lsFact.Create();
                le1.SensesOS.Add(ls2);
                ls2.StatusRA = status1;
            });
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () => le1.SensesOS.Remove(ls2));
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(1, status1.ReferringObjects.Count, "incoming ref should come back on undoing delete");
            m_actionHandler.Redo();
            Assert.AreEqual(0, status1.ReferringObjects.Count, "incoming ref should go away on redoing delete");

            // collection
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () =>
            {
                ls2 = lsFact.Create();
                le1.SensesOS.Add(ls2);
                ls2.DomainTypesRC.Add(status1);
            });
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, status1.ReferringObjects.Count);
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () => le1.SensesOS.Remove(ls2));
            Assert.AreEqual(0, status1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(1, status1.ReferringObjects.Count, "incoming ref should come back on undoing delete");
            m_actionHandler.Redo();
            Assert.AreEqual(0, status1.ReferringObjects.Count, "incoming ref should go away on redoing delete");

            // sequence
            ILexEntry le2 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () =>
            {
                le2 = leFact.Create();
                le2.MainEntriesOrSensesRS.Add(ls1);
            });
            Assert.AreEqual(1, ls1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(0, ls1.ReferringObjects.Count);
            m_actionHandler.Redo();
            Assert.AreEqual(1, ls1.ReferringObjects.Count);
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () => le2.Delete());
            Assert.AreEqual(0, ls1.ReferringObjects.Count);
            m_actionHandler.Undo();
            Assert.AreEqual(1, ls1.ReferringObjects.Count, "incoming ref should come back on undoing delete");
            m_actionHandler.Redo();
            Assert.AreEqual(0, ls1.ReferringObjects.Count, "incoming ref should go away on redoing delete");

            // The base class for this group of tests expects to end an Undo task after the test is over.
            Cache.ActionHandlerAccessor.BeginUndoTask("undo something", "redo something");
        }
			public override void MakeRoot()
			{
				CheckDisposed();

				base.MakeRoot();

				if (m_fdoCache == null || DesignMode)
					return;

				// A crude way of making sure the property we want is loaded into the cache.
				m_sense = LexSense.CreateFromDBObject(m_fdoCache, m_hvoObj);
				// Review JohnT: why doesn't the base class do this??
				m_rootb = VwRootBoxClass.Create();
				m_rootb.SetSite(this);
				if (m_vwCache == null)
				{
					m_vwCache = VwCacheDaClass.Create();
					m_silCache = (ISilDataAccess)m_vwCache;
					m_silCache.WritingSystemFactory = m_fdoCache.LanguageWritingSystemFactoryAccessor;
				}

				LoadDummyCache(false);

				// And maybe this too, at least by default?
				m_rootb.DataAccess = m_silCache;
				m_vc = new ReversalIndexEntryVc(m_usedIndices, m_fdoCache);

				// arg4 could be used to supply a stylesheet.
				m_rootb.SetRootObject(m_hvoObj,
					m_vc,
					kFragMainObject,
					m_rootb.Stylesheet);
				m_heightView = m_rootb.Height;
			}
Esempio n. 9
0
        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 = 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 brubV            = m_entryFactory.Create();
                IMoStemAllomorph brubVForm = m_stemAlloFactory.Create();
                brubV.AlternateFormsOS.Add(brubVForm);
                brubVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.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 = TsStringUtils.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 = TsStringUtils.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");
        }
Esempio n. 10
0
		/// <summary>
		///
		/// </summary>
		/// <param name="ls"></param>
		public void MoveSenseToCopy(ILexSense ls)
		{
			m_cache.BeginUndoTask(Strings.ksUndoCreateEntry, Strings.ksRedoCreateEntry);
			// CreateObject creates the entry without a PropChanged.
			int entryHvo = m_cache.CreateObject(LexEntry.kClassId,
				m_cache.LangProject.LexDbOAHvo,
				(int)LexDb.LexDbTags.kflidEntries,
				0); // 0 is fine, since the entries prop is not a sequence.
			// Copy all the basic properties.
			ILexEntry leNew = LexEntry.CreateFromDBObject(m_cache, entryHvo);
			leNew.CitationForm.MergeAlternatives(this.CitationForm);
			leNew.Bibliography.MergeAlternatives(this.Bibliography);
			leNew.Comment.MergeAlternatives(this.Comment);
			leNew.DoNotUseForParsing = this.DoNotUseForParsing;
			leNew.ExcludeAsHeadword = this.ExcludeAsHeadword;
			leNew.LiteralMeaning.MergeAlternatives(this.LiteralMeaning);
			leNew.Restrictions.MergeAlternatives(this.Restrictions);
			leNew.SummaryDefinition.MergeAlternatives(this.SummaryDefinition);
			// Copy the reference attributes.

			// Copy the owned attributes carefully.
			if (this.LexemeFormOAHvo != 0)
				m_cache.CopyObject(this.LexemeFormOAHvo, leNew.Hvo, (int)LexEntryTags.kflidLexemeForm);

			m_cache.CopyOwningSequence(AlternateFormsOS, leNew.Hvo);
			m_cache.CopyOwningSequence(PronunciationsOS, leNew.Hvo);
			m_cache.CopyOwningSequence(EntryRefsOS, leNew.Hvo);

			if (this.EtymologyOAHvo != 0)
				m_cache.CopyObject(this.EtymologyOAHvo, leNew.Hvo, (int)LexEntryTags.kflidEtymology);

			Dictionary<int, int> msaHvos = new Dictionary<int, int>(4);
			(leNew as LexEntry).ReplaceMsasForSense(ls, msaHvos);
			leNew.SensesOS.Append(ls);
			// Delete any MSAs that were used only by the moved sense.  See LT-9952.
			DeleteUnusedMSAs();

			// Handle homograph number.
			leNew.HomographNumber = 0;
			// Not all "CollectHomographs" methods use the calling entry.
			// Make sure we use one that does in this case.
			List<ILexEntry> homographs = CollectHomographs(
				leNew.HomographForm, // This should not have the markers.
				0, // Ensures we get all of them, including this new one.
				GetHomographList(m_cache, leNew.HomographForm),
				leNew.MorphType);
			LexEntry.ValidateExistingHomographs(homographs);

			// CopyObject begins a transaction if one is not already open.
			// But (JohnT, see LT-5293), there @#$%^ well should be one open,
			// because we're in a BeginUndoTask/EndUndoTask block, and if we close it here,
			// EndUndoTask tries to close it again and crashes.
			//if (m_cache.DatabaseAccessor.IsTransactionOpen())
			//    m_cache.DatabaseAccessor.CommitTrans();

			m_cache.EndUndoTask();

			m_cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
				this.OwnerHVO, this.OwningFlid, this.OwnOrd, 1, 0);
		}
Esempio n. 11
0
		private IWfiMorphBundle MakeBundle(string wordform, ILexSense sense)
		{
			var wf = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create();
			wf.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString(wordform, Cache.DefaultVernWs);
			var wa = Cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create();
			wf.AnalysesOC.Add(wa);
			var mb = Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
			wa.MorphBundlesOS.Add(mb);
			mb.SenseRA = sense;
			return mb;
		}
Esempio n. 12
0
        internal static XElement CreateMorphemeElement(IMoMorphSynAnalysis msa, ILexEntryInflType inflType)
        {
            var msaElem = new XElement("Morpheme", new XAttribute("id", msa.Hvo));

            switch (msa.ClassID)
            {
            case MoStemMsaTags.kClassId:
                var stemMsa = (IMoStemMsa)msa;
                msaElem.Add(new XAttribute("type", "stem"));
                if (stemMsa.PartOfSpeechRA != null)
                {
                    msaElem.Add(new XElement("Category", stemMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                if (stemMsa.FromPartsOfSpeechRC.Count > 0)
                {
                    msaElem.Add(new XElement("FromCategories", stemMsa.FromPartsOfSpeechRC.Select(pos => new XElement("Category", pos.Abbreviation.BestAnalysisAlternative.Text))));
                }
                if (stemMsa.InflectionClassRA != null)
                {
                    msaElem.Add(new XElement("InflClass", stemMsa.InflectionClassRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                break;

            case MoDerivAffMsaTags.kClassId:
                var derivMsa = (IMoDerivAffMsa)msa;
                msaElem.Add(new XAttribute("type", "deriv"));
                if (derivMsa.FromPartOfSpeechRA != null)
                {
                    msaElem.Add(new XElement("FromCategory", derivMsa.FromPartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                if (derivMsa.ToPartOfSpeechRA != null)
                {
                    msaElem.Add(new XElement("ToCategory", derivMsa.ToPartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                if (derivMsa.ToInflectionClassRA != null)
                {
                    msaElem.Add(new XElement("ToInflClass", derivMsa.ToInflectionClassRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                break;

            case MoUnclassifiedAffixMsaTags.kClassId:
                var unclassMsa = (IMoUnclassifiedAffixMsa)msa;
                msaElem.Add(new XAttribute("type", "unclass"));
                if (unclassMsa.PartOfSpeechRA != null)
                {
                    msaElem.Add(new XElement("Category", unclassMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                break;

            case MoInflAffMsaTags.kClassId:
                var inflMsa = (IMoInflAffMsa)msa;
                msaElem.Add(new XAttribute("type", "infl"));
                if (inflMsa.PartOfSpeechRA != null)
                {
                    msaElem.Add(new XElement("Category", inflMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text));
                }
                if (inflMsa.SlotsRC.Count > 0)
                {
                    IMoInflAffixSlot slot = inflMsa.SlotsRC.First();
                    msaElem.Add(new XElement("Slot", new XAttribute("optional", slot.Optional), slot.Name.BestAnalysisAlternative.Text));
                }
                break;
            }

            msaElem.Add(new XElement("HeadWord", msa.OwnerOfClass <ILexEntry>().HeadWord.Text));

            var glossSB = new StringBuilder();

            if (inflType != null)
            {
                string prepend = inflType.GlossPrepend.BestAnalysisAlternative.Text;
                if (prepend != "***")
                {
                    glossSB.Append(prepend);
                }
            }
            ILexSense sense = msa.OwnerOfClass <ILexEntry>().SenseWithMsa(msa);

            glossSB.Append(sense == null ? ParserCoreStrings.ksQuestions : sense.Gloss.BestAnalysisAlternative.Text);
            if (inflType != null)
            {
                string append = inflType.GlossAppend.BestAnalysisAlternative.Text;
                if (append != "***")
                {
                    glossSB.Append(append);
                }
            }
            msaElem.Add(new XElement("Gloss", glossSB.ToString()));
            return(msaElem);
        }
			internal void CreateNewEntry(bool fCreateNow, out ILexEntry le, out IMoForm allomorph, out ILexSense sense)
			{
				CheckDisposed();

				le = null;
				allomorph = null;
				sense = null;
				FdoCache cache = m_caches.MainCache;
				int hvoMorph = m_caches.DataAccess.get_ObjectProp(m_hvoMorph, ktagSbMorphForm);
				ITsString tssForm = m_caches.DataAccess.get_MultiStringAlt(hvoMorph,
																		   ktagSbNamedObjName, m_sandbox.RawWordformWs);
				// If we don't have a form or it isn't in a current vernacular writing system, give up.
				if (tssForm == null || tssForm.Length == 0 ||
					!WritingSystemServices.GetAllWritingSystems(m_caches.MainCache, "all vernacular", null, 0, 0).Contains(
						 TsStringUtils.GetWsOfRun(tssForm, 0)))
				{
					return;
				}
				var entryComponents = BuildEntryComponents();
				bool fCreateAllomorph = false;
				bool fCreatedEntry = false;
				if (fCreateNow)
				{
				   // just create a new entry based on the given information.
				   le  = cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(entryComponents);
				}
				else
				{
					using (InsertEntryDlg dlg = InsertEntryNow.CreateInsertEntryDlg(fCreateNow))
					{
						dlg.SetDlgInfo(cache, m_sandbox.GetFullMorphForm(m_hvoMorph), m_sandbox.Mediator);
						dlg.TssGloss = entryComponents.GlossAlternatives.FirstOrDefault();
						foreach (ITsString tss in entryComponents.GlossAlternatives.Skip(1))
							dlg.SetInitialGloss(TsStringUtils.GetWsAtOffset(tss, 0), tss);
						dlg.ChangeUseSimilarToCreateAllomorph();

						if (fCreateNow)
						{
							// just create a new entry based on the given information.
							dlg.CreateNewEntry();
						}
						else
						{
							// bring up the dialog so the user can make further decisions.
							Form mainWnd = m_sandbox.FindForm();
							// Making the form active fixes LT-2344 & LT-2345.
							// I'm (RandyR) not sure what adverse impact might show up by doing this.
							mainWnd.Activate();
							// The combo should be automatically hidden by activating another window.
							// That works on Windows but not on Mono (reported as https://bugzilla.xamarin.com/show_bug.cgi?id=15848).
							// So to prevent the combo hanging around on Mono, we hide it explicitly here.
							HideCombo();
							dlg.SetHelpTopic("khtpInsertEntryFromInterlinear");
							if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
								fCreateAllomorph = true;
						}
						dlg.GetDialogInfo(out le, out fCreatedEntry);
						if (!fCreatedEntry && !fCreateAllomorph)
							return;
					}
				}
				if (fCreateAllomorph && le.SensesOS.Count > 0)
					sense = le.SensesOS[0];

				allomorph = MorphServices.FindMatchingAllomorph(le, tssForm);
				bool fCreatedAllomorph = false;
				if (allomorph == null)
				{
					using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper(
						cache.ServiceLocator.GetInstance<IActionHandler>(), ITextStrings.ksUndoAddAllomorphToSimilarEntry, ITextStrings.ksRedoAddAllomorphToSimilarEntry))
					{
						allomorph = MorphServices.MakeMorph(le, tssForm);
						fCreatedAllomorph = true;
						Debug.Assert(allomorph != null);
						undoHelper.RollBack = false;
					}
					if (fCreatedEntry)
					{
						// Making the entry and the allomorph should feel like one indivisible action to the end user.
						((IActionHandlerExtensions) cache.ActionHandlerAccessor).MergeLastTwoUnitsOfWork();
					}
				}
				var allomorph1 = allomorph;
				var le1 = le;
				var sense1 = sense;
				if (fCreatedEntry || fCreatedAllomorph)
				{
					// If we've created something, then updating the sandbox needs to be undone as a unit with it,
					// so the sandbox isn't left showing something uncreated.
					UndoableUnitOfWorkHelper.Do("join me up", "join me up", cache.ActionHandlerAccessor,
						() => UpdateMorphEntry(allomorph1, le1, sense1));
					((IActionHandlerExtensions)cache.ActionHandlerAccessor).MergeLastTwoUnitsOfWork();
				}
				else
				{
					// Updating the sandbox doesn't need to be undoable, no real data changes.
					UpdateMorphEntry(allomorph1, le1, sense1);
				}
			}
Esempio n. 14
0
        public MasterCategoryListChooserLauncher(Form popupMgrParent, Mediator mediator,
                                                 ICmPossibilityList possibilityList, string fieldName, ILexSense sense)
        {
            m_parentOfPopupMgr = popupMgrParent;
            m_mediator         = mediator;
            CategoryList       = possibilityList;
            m_sense            = sense;
            FieldName          = fieldName;
            Cache = m_sense.Cache;

            Application.Idle += new EventHandler(LaunchChooseFromMasterCategoryListOnIdle);
        }
Esempio n. 15
0
		private static bool TryCreateParseMorph(LcmCache cache, XElement morphElem, out ParseMorph morph)
		{
			XElement formElement = morphElem.Element("MoForm");
			Debug.Assert(formElement != null);
			var formHvo = (string) formElement.Attribute("DbRef");

			XElement msiElement = morphElem.Element("MSI");
			Debug.Assert(msiElement != null);
			var msaHvo = (string) msiElement.Attribute("DbRef");

			// Normally, the hvo for MoForm is a MoForm and the hvo for MSI is an MSA
			// There are four exceptions, though, when an irregularly inflected form is involved:
			// 1. <MoForm DbRef="x"... and x is an hvo for a 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.  The parser filer can ignore these.
			// 2. <MSI DbRef="y"... and y is an hvo for a 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.  The parser filer can ignore these.
			// 3. <MSI DbRef="y"... and y is an hvo for a LexEntry.
			//       The LexEntry is a variant form for the first set of LexEntryRefs.
			// 4. <MSI DbRef="y"... and y is an hvo for a LexEntry followed by a period and an index digit.
			//       The LexEntry is a variant form and the (non-zero) index indicates
			//       which set of LexEntryRefs it is for.
			ICmObject objForm;
			if (!cache.ServiceLocator.GetInstance<ICmObjectRepository>().TryGetObject(int.Parse(formHvo), out objForm))
			{
				morph = null;
				return false;
			}
			var form = objForm as IMoForm;
			if (form == null)
			{
				morph = null;
				return true;
			}

			// Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef
			Tuple<int, int> msaTuple = ProcessMsaHvo(msaHvo);
			ICmObject objMsa;
			if (!cache.ServiceLocator.GetInstance<ICmObjectRepository>().TryGetObject(msaTuple.Item1, out objMsa))
			{
				morph = null;
				return false;
			}
			var msa = objMsa as IMoMorphSynAnalysis;
			if (msa != null)
			{
				morph = new ParseMorph(form, msa);
				return true;
			}

			var msaAsLexEntry = objMsa as ILexEntry;
			if (msaAsLexEntry != null)
			{
				// is an irregularly inflected form
				// get the MoStemMsa of its variant
				if (msaAsLexEntry.EntryRefsOS.Count > 0)
				{
					ILexEntryRef lexEntryRef = msaAsLexEntry.EntryRefsOS[msaTuple.Item2];
					ILexSense sense = MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
					var inflType = lexEntryRef.VariantEntryTypesRS[0] as ILexEntryInflType;
					morph = new ParseMorph(form, sense.MorphoSyntaxAnalysisRA, inflType);
					return true;
				}
			}

			// if it is anything else, we ignore it
			morph = null;
			return true;
		}
Esempio n. 16
0
        private static IWfiMorphBundle AppendMorphBundleToAnalysis(ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, IWfiAnalysis analysis)
        {
            IWfiMorphBundle morphBundle = analysis.MorphBundlesOS.Append(new WfiMorphBundle());

            morphBundle.MorphRA = lexEntry1_Entry.LexemeFormOA;
            morphBundle.SenseRA = lexEntry1_Sense1;
            morphBundle.MsaRA   = lexEntry1_Sense1.MorphoSyntaxAnalysisRA;
            return(morphBundle);
        }
Esempio n. 17
0
        private void SetupLexEntryAndSense(string formLexEntry, string senseGloss, string partOfSpeech, out ILexEntry lexEntry1_Entry, out ILexSense lexEntry1_Sense1)
        {
            ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
            int       clsidForm;
            // create a sense with a matching gloss
            DummyGenericMSA dummyMsa       = new DummyGenericMSA();
            int             hvoSenseMsaPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, partOfSpeech);

            dummyMsa.MainPOS = hvoSenseMsaPos;
            lexEntry1_Entry  = LexEntry.CreateEntry(Cache,
                                                    MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
                                                    senseGloss, dummyMsa);
            lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0];
        }
Esempio n. 18
0
 public LexSenseLexiconSense(FdoLexicon lexicon, LexemeKey lexemeKey, ILexSense lexSense)
 {
     m_lexicon   = lexicon;
     m_lexemeKey = lexemeKey;
     m_lexSense  = lexSense;
 }
Esempio n. 19
0
		/// <summary>
		/// NOTE: this routine is ignorant of calling context, so caller must provide NoteDependency to the possibleVariant and the sense
		/// (e.g. vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidSense }, 1);
		///  vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidInflType }, 1);
		/// </summary>
		/// <param name="vwenv"></param>
		/// <param name="possibleVariant"></param>
		/// <param name="sense"></param>
		/// <param name="spec"></param>
		/// <param name="inflType"></param>
		/// <returns>true if there was anything to display </returns>
		internal bool DisplayLexGlossWithInflType(IVwEnv vwenv, ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec,
			ILexEntryInflType inflType)
		{
			int iLineChoice = m_lineChoices.IndexOf(spec);
			ILexEntryRef ler;
			if (possibleVariant.IsVariantOfSenseOrOwnerEntry(sense, out ler))
			{
				var wsPreferred = GetRealWsOrBestWsForContext(sense.Hvo, spec);
				var wsGloss = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred);
				var wsUser = Cache.ServiceLocator.WritingSystemManager.UserWritingSystem;
				var testGloss = sense.Gloss.get_String(wsPreferred);
				// don't bother adding anything for an empty gloss.
				if (testGloss.Text != null && testGloss.Text.Length >= 0)
				{
					vwenv.OpenParagraph();
					// see if we have an irregularly inflected form type reference
					var leitFirst =
						ler.VariantEntryTypesRS.Where(
							let => let.ClassID == LexEntryInflTypeTags.kClassId).FirstOrDefault();

					// add any GlossPrepend info
					if (leitFirst != null)
					{
						vwenv.OpenInnerPile();
						// TODO: add dependency to VariantType GlossPrepend/Append names
						vwenv.NoteDependency(new[] { ler.Hvo },
											 new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1);
						vwenv.OpenParagraph();
						ITsString tssPrepend = null;
						if (inflType != null)
						{
							tssPrepend = MorphServices.AddTssGlossAffix(null, inflType.GlossPrepend, wsGloss, wsUser);
						}
						else
						{
							ITsIncStrBldr sbPrepend;
							ITsIncStrBldr sbAppend;
							JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend,
															   out sbAppend);
							if (sbPrepend.Text != null)
								tssPrepend = sbPrepend.GetString();
						}
						if (tssPrepend != null)
							vwenv.AddString(tssPrepend);
						vwenv.CloseParagraph();
						vwenv.CloseInnerPile();
					}
					// add gloss of main entry or sense
					{
						vwenv.OpenInnerPile();
						// NOTE: remember to NoteDependency from OuterObject
						vwenv.AddObj(sense.Hvo, this, kfragLineChoices + iLineChoice);
						vwenv.CloseInnerPile();
					}
					// now add variant type info
					if (leitFirst != null)
					{
						vwenv.OpenInnerPile();
						// TODO: add dependency to VariantType GlossPrepend/Append names
						vwenv.NoteDependency(new[] { ler.Hvo },
											 new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1);
						vwenv.OpenParagraph();
						 ITsString tssAppend = null;
						 if (inflType != null)
						 {
							 tssAppend = MorphServices.AddTssGlossAffix(null, inflType.GlossAppend, wsGloss, wsUser);
						 }
						 else
						 {
							 ITsIncStrBldr sbPrepend;
							 ITsIncStrBldr sbAppend;
							 JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend,
																out sbAppend);
							 if (sbAppend.Text != null)
								 tssAppend = sbAppend.GetString();
						 }
						{
							// Use AddProp/DisplayVariant to store GlossAppend with m_tssPendingGlossAffix
							// this allows InterlinearExporter to know to export a glsAppend item
							try
							{
								if (tssAppend != null)
									m_tssPendingGlossAffix = tssAppend;
								else
									m_tssPendingGlossAffix = m_tssMissingGlossAppend;

								vwenv.AddProp(ktagGlossAppend, this, 0);
							}
							finally
							{
								m_tssPendingGlossAffix = null;
							}
						}
						vwenv.CloseParagraph();
						vwenv.CloseInnerPile();
					}
					vwenv.CloseParagraph();
					return true;
				}
			}
			return false;
		}
Esempio n. 20
0
 private ITsString GetSenseNumberTss(ILexSense sense)
 {
     return(Cache.TsStrFactory.MakeString(GetSenseNumber(sense),
                                          Cache.DefaultUserWs));
 }
			private void AddMorphItemToList(IMoForm mf, ILexEntryRef ler, ITsString tssSense, ILexSense sense,
											IWritingSystem wsAnalysis, ITsString tssName, int hvoLexEntry)
			{
				MorphItem mi;
				if (tssSense.Length == 0)
				{
					// If it doesn't have a gloss (e.g., from Categorised Entry), use the definition.
					tssSense = sense.Definition.get_String(wsAnalysis.Handle);
				}
				mi = GetMorphItem(mf, tssName, sense, tssSense, ler, hvoLexEntry, null);
				m_morphItems.Add(mi);
			}
Esempio n. 22
0
 private string GetSenseNumber(ILexSense sense)
 {
     return(Cache.GetOutlineNumber(sense, LexSenseTags.kflidSenses, false, true, this));
 }
Esempio n. 23
0
		/// <summary>
		/// Returns twfic annotations that have WfiMorphBundle reference(s) to this sense.
		/// Note: It's possible (though not probable) that we can return more than one instance
		/// to the same annotation, since a twfic can have multiple morphs pointing to the same sense.
		/// For now, we'll just let the client create a set of unique ids, if that's what they want.
		/// Otherwise, for duplicate ids, the client can have the option of looking into WfiAnalysis.MorphBundles
		/// for the relevant sense.
		/// </summary>
		/// <returns></returns>
		static public List<int> OccurrencesInTwfics(ILexSense ls)
		{
			string whereStmt = String.Format("where wmb.Sense = {0}", ls.Hvo);
			return OccurrencesInTwfics(ls.Cache, whereStmt);
		}
Esempio n. 24
0
        public void DuplicateAnalysesApproval()
        {
            int    hvoBearTEST = CheckAnalysisSize("bearTEST", 0, true);
            string xmlFragment = "";
            int    anal1Hvo;
            int    anal2Hvo;
            int    anal3Hvo;

            using (FdoCache cache = FdoCache.Create("TestLangProj"))
            {
                IWfiAnalysis anal = null;
                ILexDb       ldb  = cache.LangProject.LexDbOA;

                // Bear entry
                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());
                ILexSense  bearNLS  = (ILexSense)bearN.SensesOS.Append(new LexSense());;

                IWfiWordform wf = WfiWordform.CreateFromDBObject(cache, hvoBearTEST);
                // First of two duplicate analyses
                anal     = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal1Hvo = anal.Hvo;
                IWfiMorphBundle mb = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.MorphRA = bearNForm;
                mb.MsaRA   = bearNMSA;
                CheckEvaluationSize(anal1Hvo, 0, true, "anal1Hvo");

                // Non-duplicate, to make sure it does not get approved.
                anal       = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal2Hvo   = anal.Hvo;
                mb         = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.SenseRA = bearNLS;
                CheckEvaluationSize(anal2Hvo, 0, true, "anal2Hvo");

                // Second of two duplicate analyses
                anal       = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal3Hvo   = anal.Hvo;
                mb         = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.MorphRA = bearNForm;
                mb.MsaRA   = bearNMSA;
                CheckEvaluationSize(anal3Hvo, 0, true, "anal3Hvo");
                CheckAnalysisSize("bearTEST", 3, false);

                xmlFragment =
                    "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearTEST'>\n"
                    + "<WfiAnalysis>\n"
                    + "<Morphs>\n"
                    + "<Morph>\n"
                    + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n"
                    + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n"
                    + "</Morph>\n"
                    + "</Morphs>\n"
                    + "</WfiAnalysis>\n"
                    + "</Wordform>\n";
            }

            m_filer.ProcessParse(MakeXML(xmlFragment, true));
            CheckEvaluationSize(anal1Hvo, 1, false, "anal1Hvo");
            CheckEvaluationSize(anal2Hvo, 0, false, "anal2Hvo");
            CheckEvaluationSize(anal3Hvo, 1, false, "anal3Hvo");
        }
Esempio n. 25
0
		static private void SplitCircumfixIntoLeftAndRightAllomorphs(FdoCache cache,
			ILexEntry entry, ITsString tssLexemeForm, ILexSense sense)
		{
			string sLeftMember;
			string sRightMember;
			if (!GetCircumfixLeftAndRightParts(cache, tssLexemeForm, out sLeftMember, out sRightMember))
				return;
			// Create left and right allomorphs
			int wsVern = StringUtils.GetWsAtOffset(tssLexemeForm, 0);
			IMoMorphType mmtPrefix;
			IMoMorphType mmtSuffix;
			IMoMorphType mmtInfix;
			MoMorphType.GetMajorAffixMorphTypes(cache, out mmtPrefix, out mmtSuffix, out mmtInfix);
			int clsidForm;
			MoMorphTypeCollection mmtCol = new MoMorphTypeCollection(cache);
			IMoMorphType mmt = MoMorphType.FindMorphType(cache, mmtCol, ref sLeftMember, out clsidForm);
			if ((mmt.Hvo != mmtPrefix.Hvo) &&
				(mmt.Hvo != mmtInfix.Hvo))
				mmt = mmtPrefix; // force a prefix if it's neither a prefix nor an infix
			IMoForm allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
				StringUtils.MakeTss(sLeftMember, wsVern), mmt, false);
			mmt = MoMorphType.FindMorphType(cache, mmtCol, ref sRightMember, out clsidForm);
			if ((mmt.Hvo != mmtInfix.Hvo) &&
				(mmt.Hvo != mmtSuffix.Hvo))
				mmt = mmtSuffix; // force a suffix if it's neither a suffix nor an infix
			allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
				StringUtils.MakeTss(sRightMember, wsVern), mmt, false);
		}
Esempio n. 26
0
        /// <summary>
        /// Convert Lcm sense to LF sense.
        /// </summary>
        /// <returns>LF sense
        /// <param name="lcmSense">Lcm sense.</param>
        private LfSense LcmSenseToLfSense(ILexSense lcmSense)
        {
            var lfSense = new LfSense();

            ILgWritingSystem VernacularWritingSystem = ServiceLocator.LanguageProject.DefaultVernacularWritingSystem;
            ILgWritingSystem AnalysisWritingSystem   = ServiceLocator.LanguageProject.DefaultAnalysisWritingSystem;

            lfSense.Guid       = lcmSense.Guid;
            lfSense.Gloss      = ToMultiText(lcmSense.Gloss);
            lfSense.Definition = ToMultiText(lcmSense.Definition);

            // Fields below in alphabetical order by ILexSense property, except for Guid, Gloss and Definition
            lfSense.AcademicDomains        = ToStringArrayField(AcademicDomainListCode, lcmSense.DomainTypesRC);
            lfSense.AnthropologyCategories = ToStringArrayField(AnthroCodeListCode, lcmSense.AnthroCodesRC);
            lfSense.AnthropologyNote       = ToMultiText(lcmSense.AnthroNote);
            lfSense.DiscourseNote          = ToMultiText(lcmSense.DiscourseNote);
            lfSense.EncyclopedicNote       = ToMultiText(lcmSense.EncyclopedicInfo);
            if (lcmSense.ExamplesOS != null)
            {
                lfSense.Examples = new List <LfExample>(lcmSense.ExamplesOS.Select(LcmExampleToLfExample));
            }

            lfSense.GeneralNote = ToMultiText(lcmSense.GeneralNote);
            lfSense.GrammarNote = ToMultiText(lcmSense.GrammarNote);
            if (lcmSense.LIFTid == null)
            {
                lfSense.LiftId = null;
            }
            else
            {
                lfSense.LiftId = lcmSense.LIFTid.Normalize(System.Text.NormalizationForm.FormC);                  // Because LIFT files on disk are NFC and we need to make sure LiftIDs match those on disk
            }
            if (lcmSense.MorphoSyntaxAnalysisRA != null)
            {
                IPartOfSpeech secondaryPos = null;                 // Only used in derivational affixes
                IPartOfSpeech pos          = ConvertLcmToMongoPartsOfSpeech.FromMSA(lcmSense.MorphoSyntaxAnalysisRA, out secondaryPos);
                // Sometimes the part of speech can be null for legitimate reasons, so check the known class IDs before warning of an unknown MSA type
                if (pos == null && !ConvertLcmToMongoPartsOfSpeech.KnownMsaClassIds.Contains(lcmSense.MorphoSyntaxAnalysisRA.ClassID))
                {
                    Logger.Warning("Got MSA of unknown type {0} in sense {1} in project {2}",
                                   lcmSense.MorphoSyntaxAnalysisRA.GetType().Name,
                                   lcmSense.Guid,
                                   LfProject.ProjectCode);
                }
                else
                {
                    lfSense.PartOfSpeech          = ToStringField(GrammarListCode, pos);
                    lfSense.SecondaryPartOfSpeech = ToStringField(GrammarListCode, secondaryPos);                     // It's fine if secondaryPos is still null here
                }
            }
            lfSense.PhonologyNote = ToMultiText(lcmSense.PhonologyNote);
            if (lcmSense.PicturesOS != null)
            {
                lfSense.Pictures = new List <LfPicture>(lcmSense.PicturesOS.Select(LcmPictureToLfPicture));
                //Use the commented code for debugging into LcmPictureToLfPicture
                //
                //lfSense.Pictures = new List<LfPicture>();
                //foreach (var LcmPic in lcmSense.PicturesOS)
                //	lfSense.Pictures.Add(LcmPictureToLfPicture(LcmPic));
            }
            lfSense.SenseBibliography = ToMultiText(lcmSense.Bibliography);
            lfSense.SenseRestrictions = ToMultiText(lcmSense.Restrictions);

            if (lcmSense.ReferringReversalIndexEntries != null)
            {
                IEnumerable <string> reversalEntries = lcmSense.ReferringReversalIndexEntries.Select(lcmReversalEntry => lcmReversalEntry.LongName);
                lfSense.ReversalEntries = LfStringArrayField.FromStrings(reversalEntries);
            }
            lfSense.ScientificName = LfMultiText.FromSingleITsString(lcmSense.ScientificName, ServiceLocator.WritingSystemFactory);
            lfSense.SemanticDomain = ToStringArrayField(SemDomListCode, lcmSense.SemanticDomainsRC);
            lfSense.SemanticsNote  = ToMultiText(lcmSense.SemanticsNote);
            // lcmSense.SensesOS; // Not mapped because LF doesn't handle subsenses. TODO: When LF handles subsenses, map this one.
            lfSense.SenseType            = ToStringField(SenseTypeListCode, lcmSense.SenseTypeRA);
            lfSense.SociolinguisticsNote = ToMultiText(lcmSense.SocioLinguisticsNote);
            if (lcmSense.Source != null)
            {
                lfSense.Source = LfMultiText.FromSingleITsString(lcmSense.Source, ServiceLocator.WritingSystemFactory);
            }
            lfSense.Status = ToStringArrayField(StatusListCode, lcmSense.StatusRA);
            lfSense.Usages = ToStringArrayField(UsageTypeListCode, lcmSense.UsageTypesRC);


            /* Fields not mapped because it doesn't make sense to map them (e.g., Hvo, backreferences, etc):
             * lcmSense.AllOwnedObjects;
             * lcmSense.AllSenses;
             * lcmSense.Cache;
             * lcmSense.CanDelete;
             * lcmSense.ChooserNameTS;
             * lcmSense.ClassID;
             * lcmSense.ClassName;
             * lcmSense.Entry;
             * lcmSense.EntryID;
             * lcmSense.FullReferenceName;
             * lcmSense.GetDesiredMsaType();
             * lcmSense.Hvo;
             * lcmSense.ImportResidue;
             * lcmSense.IndexInOwner;
             * lcmSense.IsValidObject;
             * lcmSense.LexSenseReferences;
             * lcmSense.LongNameTSS;
             * lcmSense.ObjectIdName;
             * lcmSense.OwnedObjects;
             * lcmSense.Owner;
             * lcmSense.OwningFlid;
             * lcmSense.OwnOrd;
             * lcmSense.ReferringObjects;
             * lcmSense.ReversalNameForWs(wsVern);
             * lcmSense.SandboxMSA; // Set-only property
             * lcmSense.Self;
             * lcmSense.Services;
             * lcmSense.ShortName;
             * lcmSense.ShortNameTSS;
             * lcmSense.SortKey;
             * lcmSense.SortKey2;
             * lcmSense.SortKey2Alpha;
             * lcmSense.SortKeyWs;
             * lcmSense.VariantFormEntryBackRefs;
             * lcmSense.VisibleComplexFormBackRefs;
             */

            /* Fields not mapped because LanguageForge doesn't handle that data:
             * lcmSense.AppendixesRC;
             * lcmSense.ComplexFormEntries;
             * lcmSense.ComplexFormsNotSubentries;
             * lcmSense.DoNotPublishInRC;
             * lcmSense.Subentries;
             * lcmSense.ThesaurusItemsRC;
             * lcmSense.LiftResidue;
             * lcmSense.LexSenseOutline;
             * lcmSense.PublishIn;
             */

            BsonDocument customFieldsAndGuids = _convertCustomField.GetCustomFieldsForThisCmObject(lcmSense, "senses", ListConverters);
            BsonDocument customFieldsBson     = customFieldsAndGuids["customFields"].AsBsonDocument;
            BsonDocument customFieldGuids     = customFieldsAndGuids["customFieldGuids"].AsBsonDocument;

            // TODO: Role Views only set on initial clone
            if (LfProject.IsInitialClone)
            {
                ;
            }

            // If custom field was deleted in Flex, delete config here


            lfSense.CustomFields     = customFieldsBson;
            lfSense.CustomFieldGuids = customFieldGuids;

            return(lfSense);
        }
Esempio n. 27
0
		private ILexReference CreateSeqRefToSense(IActionHandler stack, ILexSense ls, bool createReferringObjInSameUow)
		{
			ILexReference lr = null;
			UndoableUnitOfWorkHelper.Do("Undo create referring item on new stack", "Redo",
				stack,
				() =>
				{
					var list = Cache.LangProject.LexDbOA.ReferencesOA;
					if (list == null)
					{
						list = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().Create();
						Cache.LangProject.LexDbOA.ReferencesOA = list;
					}
					var lrt = Cache.ServiceLocator.GetInstance<ILexRefTypeFactory>().Create();
					list.PossibilitiesOS.Add(lrt);
					lr = Cache.ServiceLocator.GetInstance<ILexReferenceFactory>().Create();
					lrt.MembersOC.Add(lr);
					if (!createReferringObjInSameUow)
						stack.BreakUndoTask("undo setting ref", "redo setting ref");
					lr.TargetsRS.Add(ls);
				});
			return lr;
		}
Esempio n. 28
0
			protected IWfiMorphBundle SetMorphBundle(IAnalysis analysis, int iMorphBundle, ILexSense sense)
			{
				IWfiAnalysis actualWfiAnalysis = analysis.Analysis;
				if (actualWfiAnalysis != null)
				{
					actualWfiAnalysis.MorphBundlesOS[iMorphBundle].SenseRA = sense;
					return actualWfiAnalysis.MorphBundlesOS[iMorphBundle];
				}
				return null;
			}
Esempio n. 29
0
 private void GiveSenseGloss(ILexSense sense)
 {
     sense.Gloss.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString("a sense gloss",
                                                                              Cache.DefaultAnalWs);
 }
			private void CopyGlossesToSense(ILexSense sense)
			{
				foreach (int wsId in m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss))
				{
					UpdateMlaIfDifferent(m_hvoSbWord, ktagSbWordGloss, wsId, sense.Hvo, LexSenseTags.kflidGloss);
				}
			}
Esempio n. 31
0
        /// <summary/>
        internal static void SetupLexEntryAndSense(string formLexEntry, string senseGloss, string partOfSpeech, FdoCache cache,
                                                   SandboxForTests testSandBox, out ILexEntry lexEntry, out ILexSense lexSense)
        {
            ITsString tssLexEntryForm = TsStringUtils.MakeTss(formLexEntry, cache.DefaultVernWs);
            // create a sense with a matching gloss
            var entryComponents = MorphServices.BuildEntryComponents(cache, tssLexEntryForm);
            int hvoSenseMsaPos  = testSandBox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, partOfSpeech);

            if (hvoSenseMsaPos != 0)
            {
                entryComponents.MSA.MainPOS = cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(hvoSenseMsaPos);
            }
            entryComponents.GlossAlternatives.Add(TsStringUtils.MakeTss(senseGloss, cache.DefaultAnalWs));
            ILexEntry newEntry = cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(entryComponents);

            lexEntry = newEntry;
            lexSense = newEntry.SensesOS[0];
        }
			// Answer true if the sense is only used in one WfiAnalysis.
			private bool OnlyUsedThisOnce(ILexSense sense)
			{
				return sense.ReferringObjects.Where(obj => obj is IWfiMorphBundle).Take(2).Count() <= 1;
			}
Esempio n. 33
0
			virtual public IWfiMorphBundle SetMorphSense(int iSegment, int iSegForm, int iMorphBundle, ILexSense sense)
			{
				var analysis = GetAnalysis(iSegment, iSegForm);
				// Find or create the current analysis of the actual annotation.
				return SetMorphBundle(analysis, iMorphBundle, sense);
			}
Esempio n. 34
0
 /// <summary>
 /// Create and setup a search for keywords from a LexSense in the Semantic Domain list.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="sense"></param>
 public SenseSearchStrategy(LcmCache cache, ILexSense sense) : base(cache)
 {
     m_sense      = sense;
     m_searchKeys = GetSearchKeysFromSense();
 }
		/// <summary>
		/// Gets delete status for the object.
		/// True means it can be deleted if the given sense is deleted first, otherwise false.
		/// </summary>
		public bool CanDeleteIfSenseDeleted(ILexSense senseToDelete)
		{
			if (!base.CanDelete)
				return false;
			var servLoc = m_cache.ServiceLocator;
			// If any surviving senses (which must belong to the same entry) refer to it, we can't delete it.
			if (((ILexEntry) Owner).AllSenses.FirstOrDefault(
				s => s.MorphoSyntaxAnalysisRA == this && (senseToDelete == null || s != senseToDelete)) != null)
			{
				return false;
			}
			var allMoMorphAdhocProhib = servLoc.GetInstance<IMoMorphAdhocProhibRepository>().AllInstances();
			var mapCount = (allMoMorphAdhocProhib.Where(map => map.FirstMorphemeRA == this
															   || map.MorphemesRS.Contains(this)
															   || map.RestOfMorphsRS.Contains(this))).Count();
			if (mapCount > 0) return false;

			int msaCount = servLoc.GetInstance<IMoMorphSynAnalysisRepository>().AllInstances().Count(msa => msa.ComponentsRS.Contains(this));
			return msaCount < 1;
		}
Esempio n. 36
0
        protected override void Init()
        {
            m_entryFactory         = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
            m_senseFactory         = Cache.ServiceLocator.GetInstance <ILexSenseFactory>();
            m_exampleFactory       = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>();
            m_lexEntryRefFactory   = Cache.ServiceLocator.GetInstance <ILexEntryRefFactory>();
            m_lexRefTypeFactory    = Cache.ServiceLocator.GetInstance <ILexRefTypeFactory>();
            m_lexRefFactory        = Cache.ServiceLocator.GetInstance <ILexReferenceFactory>();
            m_possListFactory      = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>();
            m_revIndexFactory      = Cache.ServiceLocator.GetInstance <IReversalIndexFactory>();
            m_revIndexEntryFactory = Cache.ServiceLocator.GetInstance <IReversalIndexEntryFactory>();

            m_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses",
                                                                            false);
            m_application = new MockFwXApp(new MockFwManager {
                Cache = Cache
            }, null, null);
            var configFilePath = Path.Combine(FwDirectoryFinder.CodeDirectory, m_application.DefaultConfigurationPathname);

            m_window = new MockFwXWindow(m_application, configFilePath);
            ((MockFwXWindow)m_window).Init(Cache);             // initializes Mediator values

            UndoableUnitOfWorkHelper.Do("do", "undo", Cache.ActionHandlerAccessor,
                                        () =>
            {
                m_domainBadWords    = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create();
                m_domainTemperature = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create();
                Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainBadWords);
                Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainTemperature);
                m_mainDict = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0];
                m_blank    = MakeEntry("blank", "swear word", true);
                m_blank.SensesOS[0].SemanticDomainsRC.Add(m_domainBadWords);
                m_hot     = MakeEntry("hot", "high temperature", false);
                m_hotTemp = m_hot.SensesOS[0];
                m_hotTemp.SemanticDomainsRC.Add(m_domainTemperature);
                m_trouble = MakeSense(m_hot, "trouble");
                m_trouble.DoNotPublishInRC.Add(m_mainDict);
                m_trouble.PicturesOS.Add(Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create());
                m_desirable = MakeSense(m_hot, "desirable");
                m_fastCar   = MakeSense(m_desirable, "fast (car)");

                m_badHot  = MakeExample(m_hotTemp, "a hot pile of blank", true);
                m_goodHot = MakeExample(m_hotTemp, "a hot bath", false);

                m_water              = MakeEntry("water", "H2O", false);
                m_waterH2O           = m_water.SensesOS[0];
                m_hotWater           = MakeEntry("hot water", "trouble", false);
                m_hotWaterComponents = MakeEntryRef(m_hotWater, new ICmObject[] { m_trouble, m_waterH2O },
                                                    new ICmObject[] { m_trouble, m_waterH2O },
                                                    LexEntryRefTags.krtComplexForm);

                m_blank2      = MakeEntry("blank", "vacant", false);
                m_blank3      = MakeEntry("blank", "erase", false);
                m_water2      = MakeEntry("water", "urinate", true);
                m_waterPrefix = MakeEntry("water", "aquatic", false);
                m_waterPrefix.LexemeFormOA.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>()
                                                         .GetObject(MoMorphTypeTags.kguidMorphPrefix);

                m_synonym       = MakeRefType("synonym", null, (int)LexRefTypeTags.MappingTypes.kmtSenseCollection);
                m_blip          = MakeEntry("blip", "rude word", true);
                m_bother        = MakeEntry("bother", "I'm annoyed by that", false);
                m_ouch          = MakeEntry("ouch", "that hurt", false);
                m_blipOuch      = MakeSense(m_blip.SensesOS[0], "rude ouch");
                m_blankSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_blank, m_ouch.SensesOS[0], m_blip.SensesOS[0], m_blipOuch, m_bother });

                m_problem         = MakeEntry("problem", "difficulty", false);
                m_problemSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_problem, m_trouble });

                m_body       = MakeEntry("body", "body", true);
                m_arm        = MakeEntry("arm", "arm", false);
                m_leg        = MakeEntry("leg", "leg", false);
                m_belly      = MakeEntry("belly", "belly", true);
                m_torso      = MakeEntry("torso", "torso", false);
                m_partWhole  = MakeRefType("partWhole", null, (int)LexRefTypeTags.MappingTypes.kmtEntryTree);
                m_bodyParts  = MakeLexRef(m_partWhole, new ICmObject[] { m_body, m_arm, m_leg.SensesOS[0], m_torso, m_belly });
                m_torsoParts = MakeLexRef(m_partWhole, new ICmObject[] { m_torso, m_arm, m_belly });

                m_hotBlank = MakeEntry("hotBlank", "problem rude word", false);
                MakeEntryRef(m_hotBlank, new ICmObject[] { m_trouble, m_water2 },
                             new ICmObject[] { m_trouble, m_water2 },
                             LexEntryRefTags.krtComplexForm);

                m_blueColor = MakeEntry("blue", "color blue", false);
                m_blueCold  = MakeEntry("blue", "cold", false);
                m_blueMusic = MakeEntry("blue", "jazzy", false);
                m_blueSad   = MakeEntry("blue", "sad", false);

                m_blueMusic.HomographNumber = 2;                               // will duplicate blue cold; pathological, but should not crash.
                m_blueSad.HomographNumber   = 3;                               // will conflict with renumbered blueMusic

                m_bluer             = m_blueColor.SensesOS[0];
                m_sky               = MakeEntry("sky", "interface between atmosphere and space", false, true);                   // true excludes as headword
                m_skyReal           = m_sky.SensesOS[0];
                m_blueSky           = MakeEntry("blue sky", "clear, huge potential", false);
                m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal },
                                                   new ICmObject[] { m_bluer, m_skyReal },
                                                   LexEntryRefTags.krtComplexForm);

                m_ringBell   = MakeEntry("ring", "bell", false);
                m_ringCircle = MakeEntry("ring", "circle", false, true);
                m_ringGold   = MakeEntry("ring", "gold", false);

                m_blackVerb  = MakeEntry("black", "darken", false, true);
                m_blackColor = MakeEntry("black", "dark", false);

                m_hotArm           = MakeEntry("hotarm", "pitcher", false);
                m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm },
                                                  new ICmObject[] { m_hot, m_arm },
                                                  LexEntryRefTags.krtComplexForm);
                m_hotArm.DoNotPublishInRC.Add(m_mainDict);
                m_hotArmComponents.ShowComplexFormsInRS.Add(m_hot);

                m_nolanryan           = MakeEntry("Nolan_Ryan", "pitcher", false);
                m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot },
                                                     new ICmObject[] { m_hot },
                                                     LexEntryRefTags.krtVariant);
                m_nolanryanComponents.VariantEntryTypesRS.Add(
                    (ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]);
                m_nolanryan.DoNotPublishInRC.Add(m_mainDict);

                m_edName   = MakeEntry("ed", "someone called ed", false);
                m_edSuffix = MakeEntry("ed", "past", false, false, true);

                m_revIndex = CreateInterestingReversalEntries();

                m_publisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid);
                m_publisher.SetOwningPropValue(Cache.LangProject.LexDbOA.Entries.Select(le => le.Hvo).ToArray());
                m_decorator = new DictionaryPublicationDecorator(Cache, m_publisher, ObjectListPublisher.OwningFlid);

                m_revPublisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid);
                m_revPublisher.SetOwningPropValue(m_revIndex.AllEntries.Select(rie => rie.Hvo).ToArray());
                m_revDecorator = new DictionaryPublicationDecorator(Cache, m_revPublisher, ObjectListPublisher.OwningFlid);
            });
        }
			private void UpdateSense(ILexSense sense, IPartOfSpeech pos)
			{
				CopyGlossesToSense(sense);
				var msa = (IMoStemMsa)sense.MorphoSyntaxAnalysisRA;
				var lexEntry = sense.Entry;
				if (msa.PartOfSpeechRA != pos)
				{
					// is there another MSA we can use?
					foreach (var msaOther in lexEntry.MorphoSyntaxAnalysesOC)
					{
						var stem = msaOther as IMoStemMsa;
						if (stem == null)
							continue;
						if (stem.PartOfSpeechRA == pos)
						{
							sense.MorphoSyntaxAnalysisRA = msaOther; // also updates WfiMorphBundle and deletes old obsolete MSA if obsolete.
							return;
						}
					}
					// Is this msa used elsewhere or can we modify it?
					if (lexEntry.SensesOS.Where(s => s != sense && s.MorphoSyntaxAnalysisRA == msa).Take(1).Count() > 0)
					{
						// Used; have to make a new one.
						msa = sense.Services.GetInstance<IMoStemMsaFactory>().Create();
						lexEntry.MorphoSyntaxAnalysesOC.Add(msa);
						sense.MorphoSyntaxAnalysisRA = msa;
					}
					msa.PartOfSpeechRA = pos;
				}
			}
        /// <summary>
        /// Takes the gloss, a short definition (if only one or two words), and reversal from a LexSense
        /// and uses those words as search keys to find Semantic Domains that have one of those words in
        /// their Name or ExampleWords fields.
        ///
        /// N.B.: This method looks for matches in the AnalysisDefaultWritingSystem.
        /// This ought to help ensure that we are searching in the Semantic Domain fields in the same
        /// writing system as the one the search keys in the Sense came from.
        /// </summary>
        /// <param name="sense"></param>
        /// <returns></returns>
        public IEnumerable <ICmSemanticDomain> FindDomainsThatMatchWordsIn(ILexSense sense)
        {
            IEnumerable <ICmSemanticDomain> dummy;

            return(FindDomainsThatMatchWordsIn(sense, out dummy));
        }
Esempio n. 39
0
		internal static bool TryGetLexGlossWithInflTypeTss(ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec, InterlinLineChoices lineChoices, int vernWsContext, ILexEntryInflType inflType, out ITsString result)
		{
			FdoCache cache = possibleVariant.Cache;
			using (var vcLexGlossFrag = new InterlinVc(cache))
			{
				vcLexGlossFrag.LineChoices = lineChoices;
				vcLexGlossFrag.PreferredVernWs = vernWsContext;


				result = null;
				var collector = new TsStringCollectorEnv(null, vcLexGlossFrag.Cache.MainCacheAccessor,
														 possibleVariant.Hvo)
									{
										RequestAppendSpaceForFirstWordInNewParagraph = false
									};
				if (vcLexGlossFrag.DisplayLexGlossWithInflType(collector, possibleVariant, sense, spec, inflType))
				{
					result = collector.Result;
					return true;
				}
				return false;
			}
		}
Esempio n. 40
0
 /// <summary>
 /// </summary>
 /// <param name="formLexEntry"></param>
 /// <param name="senseGloss"></param>
 /// <param name="lexEntry1_Entry"></param>
 /// <param name="lexEntry1_Sense1"></param>
 private void SetupLexEntryAndSense(string formLexEntry, string senseGloss, out ILexEntry lexEntry1_Entry, out ILexSense lexEntry1_Sense1)
 {
     SetupLexEntryAndSense(formLexEntry, senseGloss, "adjunct", out lexEntry1_Entry, out lexEntry1_Sense1);
 }
		private IWfiMorphBundle MakeBundle(IWfiAnalysis wa, ILexSense sense)
		{
			var mb = Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
			wa.MorphBundlesOS.Add(mb);
			mb.SenseRA = sense;
			return mb;
		}
Esempio n. 42
0
        private static IWfiMorphBundle AppendMorphBundleToAnalysis(ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, IWfiAnalysis analysis)
        {
            var             mbFactory   = analysis.Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
            IWfiMorphBundle morphBundle = mbFactory.Create();

            analysis.MorphBundlesOS.Add(morphBundle);
            morphBundle.MorphRA = lexEntry1_Entry.LexemeFormOA;
            morphBundle.SenseRA = lexEntry1_Sense1;
            morphBundle.MsaRA   = lexEntry1_Sense1.MorphoSyntaxAnalysisRA;
            return(morphBundle);
        }
			private static MorphItem GetMorphItem(IMoForm mf, ITsString tssName, ILexSense sense, ITsString tssSense,
				ILexEntryRef ler, int hvoLexEntry, ILexEntryInflType inflType)
			{
				IMoMorphSynAnalysis msa = null;
				string msaText = null;
				if (sense != null)
				{
					msa = sense.MorphoSyntaxAnalysisRA;
					if (msa != null)
						msaText = msa.InterlinearName;
				}

				var options = new MorphItemOptions
				{
					HvoMoForm = HvoOrZero(mf),
					HvoEntry = ler != null ? hvoLexEntry : 0,
					TssName = tssName,
					HvoSense = HvoOrZero(sense),
					SenseName = tssSense != null ? tssSense.Text : null,
					HvoMsa = HvoOrZero(msa),
					MsaName = msaText,
					InflType = inflType,
					EntryRef = ler,
				};
				return new MorphItem(options);
			}
Esempio n. 44
0
        private IWfiAnalysis SetupAnalysisForEntry(AnalysisOccurrence cba0_0, string gloss, ILexSense lexEntry1_Sense1, out IWfiWordform wf)
        {
            wf = cba0_0.Analysis.Wordform;
            var wag = WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(wf);

            wag.WfiAnalysis.CategoryRA = (lexEntry1_Sense1.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA;
            wag.Gloss.Form.set_String(Cache.DefaultAnalWs, gloss);
            return(wag.WfiAnalysis);
        }
			/// <summary>
			/// Update the sandbox cache to reflect a choice of the real MoForm and the
			/// entry indicated by the FdoCache hvos passed.
			/// </summary>
			internal void UpdateMorphEntry(IMoForm moFormReal, ILexEntry entryReal, ILexSense senseReal,
				ILexEntryInflType inflType = null)
			{
				CheckDisposed();

				bool fDirty = m_sandbox.Caches.DataAccess.IsDirty();
				bool fApproved = !m_sandbox.UsingGuess;
				bool fHasApprovedWordGloss = m_sandbox.HasWordGloss() && (fDirty || fApproved);
				bool fHasApprovedWordCat = m_sandbox.HasWordCat() && (fDirty || fApproved);

				var undoAction = new UpdateMorphEntryAction(m_sandbox, m_hvoMorph); // before changes.

				// Make a new morph, if one does not already exist, corresponding to the
				// selected item.  Its form must match what is already displayed.  Store it as
				// the new value.
				int hvoMorph = m_sandbox.CreateSecondaryAndCopyStrings(InterlinLineChoices.kflidMorphemes, moFormReal.Hvo,
					MoFormTags.kflidForm);
				m_caches.DataAccess.SetObjProp(m_hvoMorph, ktagSbMorphForm, hvoMorph);
				m_caches.DataAccess.PropChanged(m_rootb,
					(int)PropChangeType.kpctNotifyAll, m_hvoMorph, ktagSbMorphForm, 0,
					1, 1);

				// Try to establish the sense.  Call this before SetSelectedEntry and LoadSecDataForEntry.
				// reset cached gloss, since we should establish the sense according to the real sense or real entry.
				m_caches.DataAccess.SetObjProp(m_hvoMorph, ktagSbMorphGloss, 0);
				var morphEntry = moFormReal.Owner as ILexEntry;
				ILexSense realDefaultSense = m_sandbox.EstablishDefaultSense(m_hvoMorph, morphEntry, senseReal, inflType);
				// Make and install a secondary object to correspond to the real LexEntry.
				// (The zero says we are not guessing any more, since the user selected this entry.)

				m_sandbox.LoadSecDataForEntry(morphEntry, senseReal != null ? senseReal : realDefaultSense,
					m_hvoSbWord, m_caches.DataAccess as IVwCacheDa,
					m_wsVern, m_hvoMorph, 0, m_caches.MainCache.MainCacheAccessor, null);
				m_caches.DataAccess.PropChanged(m_rootb,
					(int)PropChangeType.kpctNotifyAll, m_hvoMorph, ktagSbMorphEntry, 0,
					1, WasReal());

				// Notify any delegates that the selected Entry changed.
				m_sandbox.SetSelectedEntry(entryReal);
				// fHasApprovedWordGloss: if an approved word gloss already exists -- don't replace it
				// fHasApprovedWordCat: if an approved word category already exists -- don't replace it
				CopyLexEntryInfoToMonomorphemicWordGlossAndPos(!fHasApprovedWordGloss, !fHasApprovedWordCat);
				undoAction.GetNewVals();
				// If we're doing this as part of something undoable, and then undo it, we should undo this also,
				// especially so the Sandbox isn't left displaying something whose creation has been undone. (FWR-3547)
				if (m_caches.MainCache.ActionHandlerAccessor.CurrentDepth > 0)
				{
					m_caches.MainCache.ActionHandlerAccessor.AddAction(undoAction);
				}
				return;
			}
Esempio n. 46
0
        public void PickLexGlossUsingExistingAnalysis()
        {
            var cba0_0 = GetCba(0, 0, 0);

            m_sandbox.SwitchWord(cba0_0);
            ILexEntry    lexEntry1_Entry;
            ILexSense    lexEntry1_Sense1;
            ILexEntry    lexEntry2_Entry;
            ILexSense    lexEntry2_Sense1;
            IWfiWordform wf;

            SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);
            SetupLexEntryAndSense("xxxa", "xxxa.AlternativeGloss", out lexEntry2_Entry, out lexEntry2_Sense1);
            // setup an existing analysis and gloss to match existing entry
            var morphBundle1 = SetupMorphBundleForEntry(cba0_0, "0.0.xxxa", lexEntry1_Entry, lexEntry1_Sense1, out wf);
            var morphBundle2 = SetupMorphBundleForEntry(cba0_0, "xxxa.AlternativeGloss", lexEntry2_Entry, lexEntry2_Sense1, out wf);

            // load sandbox with a guess.
            m_sandbox.SwitchWord(cba0_0);
#if WANTTESTPORT
            Assert.IsTrue(m_sandbox.UsingGuess);
#endif

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.Entries.Count();

            // first select 'unknown' to clear the guess for the word gloss/pos
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, "Unknown");
            // confirm Sandbox is in the expected state.
            ITsString tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                                        Cache.DefaultAnalWs);
            Assert.AreEqual(null, tssWordGlossInSandbox.Text);
            int hvoPos = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreEqual(0, hvoPos);

            // simulate selecting a lex gloss '0.0.xxxa'
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry1_Sense1.Hvo);
            // confirm Sandbox is in the expected state.
            tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs);
            Assert.AreEqual("0.0.xxxa", tssWordGlossInSandbox.Text);
            int hvoPos2 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreNotEqual(0, hvoPos2);

            // simulate selecting the other lex gloss 'xxxa.AlternativeGloss'
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry2_Sense1.Hvo);
            // confirm Sandbox is in the expected state.
            tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs);
            Assert.AreEqual("xxxa.AlternativeGloss", tssWordGlossInSandbox.Text);
            int hvoPos3 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreNotEqual(0, hvoPos3);

            // Next simulate picking an existing word gloss/pos by typing/selecting
            tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs, "0.0.xxxa");
            // set word pos, to first possibility (e.g. 'adjunct')
            int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

            // confirm the analysis (using existing analysis and a LexSense)
            var       wag      = m_sandbox.ConfirmAnalysis();
            IWfiGloss wfiGloss = wag.Gloss;

            // make sure we didn't add entries or senses to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.Entries.Count();
            Assert.AreEqual(cEntriesOrig, cEntriesAfter);
            Assert.AreEqual(1, lexEntry1_Entry.SensesOS.Count);

            // make sure the sense matches the existing one.
            ILexSense sense = m_sandbox.GetLexSenseForWord();
            Assert.AreEqual(lexEntry1_Sense1.Hvo, sense.Hvo);
            // make sure the strings of the wfi gloss matches the strings of the lex gloss.
            ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

            // confirm we have not created a new analysis and that it is monomorphemic
            IWfiAnalysis wfiAnalysis = wag.WfiAnalysis;
            Assert.AreEqual(wf, wag.Wordform, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRA.Hvo);
            Assert.AreEqual(2, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
            IWfiAnalysis wfiAnalysis2 = (morphBundle2 as IWfiMorphBundle).Owner as IWfiAnalysis;
            Assert.AreEqual(1, wfiAnalysis2.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis2.MeaningsOC.Count);

            // make sure the morph is linked to our lexicon sense, msa, and part of speech.
            IWfiMorphBundle wfiMorphBundle = wfiAnalysis.MorphBundlesOS[0];
            Assert.AreEqual(morphBundle1.Hvo, wfiMorphBundle.Hvo);
        }
Esempio n. 47
0
		/// <summary>
		/// Determines whether the entry is in a variant relationship with the given sense (or its entry).
		/// </summary>
		/// <param name="senseTargetComponent">the sense of which we are possibly a variant. If we aren't a variant of the sense,
		/// we will try to see if we are a variant of its owner entry</param>
		/// <param name="matchinEntryRef">if we found a match, the first (and only) ComponentLexeme will have matching sense or its owner entry.</param>
		/// <returns></returns>
		public bool IsVariantOfSenseOrOwnerEntry(ILexSense senseTargetComponent, out ILexEntryRef matchinEntryRef)
		{
			matchinEntryRef = null;
			if (senseTargetComponent != null && senseTargetComponent.Hvo != 0 && senseTargetComponent.EntryID != this.Hvo)
			{
				// expect hvoLexEntry to be a variant of the sense or the sense's entry.
				matchinEntryRef = this.FindMatchingVariantEntryRef(senseTargetComponent, null);
				if (matchinEntryRef == null)
				{
					// must be in relationship with the sense's entry, rather than the sense.
					matchinEntryRef = this.FindMatchingVariantEntryRef(senseTargetComponent.Entry, null);
				}
			}
			return matchinEntryRef != null;
		}
Esempio n. 48
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mainEntryOrSense"></param>
 /// <param name="mainEntry"></param>
 /// <param name="mainOrFirstSense"></param>
 public static void GetMainEntryAndSenseStack(IVariantComponentLexeme mainEntryOrSense, out ILexEntry mainEntry, out ILexSense mainOrFirstSense)
 {
     if (mainEntryOrSense is ILexEntry)
     {
         mainEntry        = mainEntryOrSense as ILexEntry;
         mainOrFirstSense = mainEntry.SensesOS.Count > 0 ? mainEntry.SensesOS[0] : null;
     }
     else if (mainEntryOrSense is ILexSense)
     {
         mainOrFirstSense = mainEntryOrSense as ILexSense;
         mainEntry        = mainOrFirstSense.Entry;
     }
     else
     {
         mainEntry        = null;
         mainOrFirstSense = null;
     }
 }
Esempio n. 49
0
		/// <summary>
		/// This goes through the LexSense and all its subsenses to create the needed MSAs on
		/// the current LexEntry, replacing all those found in the LexSense.
		/// </summary>
		/// <param name="ls"></param>
		/// <param name="msaHvos"></param>
		private void ReplaceMsasForSense(ILexSense ls, Dictionary<int, int> msaHvos)
		{
			int hvoMsaOld = ls.MorphoSyntaxAnalysisRAHvo;
			if (hvoMsaOld != 0)
			{
				int hvoMsaNew;
				if (!msaHvos.TryGetValue(hvoMsaOld, out hvoMsaNew))
				{
					hvoMsaNew = m_cache.CopyObject(hvoMsaOld, this.Hvo,
						(int)LexEntryTags.kflidMorphoSyntaxAnalyses);
					msaHvos[hvoMsaOld] = hvoMsaNew;
				}
				ls.MorphoSyntaxAnalysisRAHvo = hvoMsaNew;
			}
			for (int i = 0; i < ls.SensesOS.Count; ++i)
			{
				ReplaceMsasForSense(ls.SensesOS[i], msaHvos);
			}
		}
Esempio n. 50
0
        public static void WriteMorphInfoElements(this XmlWriter writer, LcmCache cache, string formID, string msaID, string wordType, string props)
        {
            ICmObject obj  = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(int.Parse(formID, CultureInfo.InvariantCulture));
            var       form = obj as IMoForm;

            if (form == null)
            {
                // 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.
                var lexEntryInflType = obj as ILexEntryInflType;
                if (lexEntryInflType != null)
                {
                    WriteLexEntryInflTypeElement(writer, wordType, lexEntryInflType);
                    return;
                }
            }
            string shortName;
            string alloform;
            string gloss;
            string citationForm;

            if (form != null)
            {
                shortName = form.LongName;
                int iFirstSpace = shortName.IndexOf(" (", StringComparison.Ordinal);
                int iLastSpace  = shortName.LastIndexOf("):", StringComparison.Ordinal) + 2;
                alloform = shortName.Substring(0, iFirstSpace);
                Tuple <int, int> msaTuple = ProcessMsaHvo(msaID);
                ICmObject        msaObj   = cache.ServiceLocator.GetObject(msaTuple.Item1);
                if (msaObj.ClassID == LexEntryTags.kClassId)
                {
                    var entry = msaObj as ILexEntry;
                    Debug.Assert(entry != null);
                    if (entry.EntryRefsOS.Count > 0)
                    {
                        ILexEntryRef  lexEntryRef = entry.EntryRefsOS[msaTuple.Item2];
                        ITsIncStrBldr sbGlossPrepend;
                        ITsIncStrBldr sbGlossAppend;
                        ILexSense     sense = MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                        CoreWritingSystemDefinition glossWs = cache.ServiceLocator.WritingSystemManager.Get(cache.DefaultAnalWs);
                        MorphServices.JoinGlossAffixesOfInflVariantTypes(lexEntryRef.VariantEntryTypesRS,
                                                                         glossWs, out sbGlossPrepend, out sbGlossAppend);
                        ITsIncStrBldr sbGloss = sbGlossPrepend;
                        sbGloss.Append(sense.Gloss.BestAnalysisAlternative.Text);
                        sbGloss.Append(sbGlossAppend.Text);
                        gloss = sbGloss.Text;
                    }
                    else
                    {
                        gloss = ParserCoreStrings.ksUnknownGloss;
                    }
                }
                else
                {
                    var msa = msaObj as IMoMorphSynAnalysis;
                    gloss = msa != null?msa.GetGlossOfFirstSense() : shortName.Substring(iFirstSpace, iLastSpace - iFirstSpace).Trim();
                }
                citationForm = shortName.Substring(iLastSpace).Trim();
                shortName    = String.Format(ParserCoreStrings.ksX_Y_Z, alloform, gloss, citationForm);
            }
            else
            {
                alloform     = ParserCoreStrings.ksUnknownMorpheme;             // in case the user continues...
                gloss        = ParserCoreStrings.ksUnknownGloss;
                citationForm = ParserCoreStrings.ksUnknownCitationForm;
                shortName    = String.Format(ParserCoreStrings.ksX_Y_Z, alloform, gloss, citationForm);
                throw new ApplicationException(shortName);
            }
            writer.WriteElementString("shortName", shortName);
            writer.WriteElementString("alloform", alloform);
            switch (form.ClassID)
            {
            case MoStemAllomorphTags.kClassId:
                WriteStemNameElement(writer, form, props);
                break;

            case MoAffixAllomorphTags.kClassId:
                WriteAffixAlloFeatsElement(writer, form, props);
                WriteStemNameAffixElement(writer, cache, props);
                break;
            }
            writer.WriteElementString("gloss", gloss);
            writer.WriteElementString("citationForm", citationForm);
        }
Esempio n. 51
0
			public LexSenseLexiconSense(FdoLexicon lexicon, LexemeKey lexemeKey, ILexSense lexSense)
			{
				m_lexicon = lexicon;
				m_lexemeKey = lexemeKey;
				m_lexSense = lexSense;
			}
Esempio n. 52
0
 public EmptyWwfInfo(IMoForm form, IMoMorphSynAnalysis msa, IPartOfSpeech pos, ILexSense sense)
 {
     Form  = form;
     Msa   = msa;
     Pos   = pos;
     Sense = sense;
 }
Esempio n. 53
0
		private IWfiMorphBundle CreateAtomicRefToSense(IActionHandler stack, ILexSense ls, bool createReferringObjInSameUow)
		{
			IWfiMorphBundle mb = null;
			UndoableUnitOfWorkHelper.Do("Undo create referring item on new stack", "Redo",
				stack,
				() =>
					{
						var wf = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create();
						var wa = Cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create();
						wf.AnalysesOC.Add(wa);
						mb = Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
						wa.MorphBundlesOS.Add(mb);
						if (!createReferringObjInSameUow)
							stack.BreakUndoTask("undo setting ref", "redo setting ref");
						mb.SenseRA = ls;
					});
			return mb;
		}
Esempio n. 54
0
        private void GetMainEntryAndSense(ILexEntry entryOrVariant, out ILexEntry mainEntry, out ILexSense sense)
        {
            sense = null;
            // first see if this is a variant of another entry.
            var entryRef = DomainObjectServices.GetVariantRef(entryOrVariant, true);

            if (entryRef != null)
            {
                // get the main entry or sense.
                var component = entryRef.ComponentLexemesRS[0] as IVariantComponentLexeme;
                if (component is ILexSense)
                {
                    sense     = component as ILexSense;
                    mainEntry = sense.Entry;
                }
                else
                {
                    mainEntry = component as ILexEntry;
                    // consider using the sense of the variant, if it has one. (LT-9681)
                }
            }
            else
            {
                mainEntry = entryOrVariant;
            }
        }
Esempio n. 55
0
			/// <summary>
			/// Clean up any resources being used.
			/// </summary>
			protected override void Dispose(bool disposing)
			{
				//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
				// Must not be run more than once.
				if (IsDisposed)
					return;

				base.Dispose(disposing);

				if (disposing)
				{
					if (m_vc != null)
						m_vc.Dispose();
					if (m_usedIndices != null)
						m_usedIndices.Clear();
				}

				m_sense = null;
				m_vc = null;
				if (m_tsf != null)
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_tsf);
				m_tsf = null;
				m_silCache = null;
				if (m_vwCache != null)
				{
					m_vwCache.ClearAllData();
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_vwCache);
					m_vwCache = null;
				}
				m_usedIndices = null;
			}
Esempio n. 56
0
 private void ValidateSenseWithAnalysis(ILexSense sense, IWfiGloss wfiGloss, int hvoSbWordPos)
 {
     ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos, false, sense.Entry.LexemeFormOA as IMoStemAllomorph);
 }
Esempio n. 57
0
 /// <summary/>
 internal static void SetupLexEntryAndSense(string formLexEntry, string senseGloss, FdoCache cache, SandboxForTests testSandBox, out ILexEntry lexEntry, out ILexSense lexSense)
 {
     SetupLexEntryAndSense(formLexEntry, senseGloss, "adjunct", cache, testSandBox, out lexEntry, out lexSense);
 }
Esempio n. 58
0
 private void SetupLexEntryAndSense(string formLexEntry, string senseGloss, string partOfSpeech,
                                    out ILexEntry lexEntry, out ILexSense lexSense)
 {
     SetupLexEntryAndSense(formLexEntry, senseGloss, partOfSpeech, Cache, m_sandbox, out lexEntry, out lexSense);
 }
Esempio n. 59
0
		public MasterCategoryListChooserLauncher(Form popupMgrParent, Mediator mediator,
			ICmPossibilityList possibilityList, string fieldName, ILexSense sense)
		{
			m_parentOfPopupMgr = popupMgrParent;
			m_mediator = mediator;
			CategoryList = possibilityList;
			m_sense = sense;
			FieldName = fieldName;
			Cache = m_sense.Cache;

			Application.Idle += new EventHandler(LaunchChooseFromMasterCategoryListOnIdle);
		}
Esempio n. 60
0
        public void DuplicateAnalysesApproval()
        {
            IWfiWordform pigs = CheckAnalysisSize("pigsTEST", 0, true);

            ParseResult  result = null;
            IWfiAnalysis anal1 = null, anal2 = null, anal3 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Bear entry
                ILexEntry pigN            = m_entryFactory.Create();
                IMoStemAllomorph pigNForm = m_stemAlloFactory.Create();
                pigN.AlternateFormsOS.Add(pigNForm);
                pigNForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("pigNTEST", m_vernacularWS.Handle);
                IMoStemMsa pigNMsa = m_stemMsaFactory.Create();
                pigN.MorphoSyntaxAnalysesOC.Add(pigNMsa);
                ILexSense pigNSense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();
                pigN.SensesOS.Add(pigNSense);

                var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>();
                var mbFactory   = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
                // First of two duplicate analyses
                IWfiAnalysis anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal1 = anal;
                IWfiMorphBundle mb = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                CheckEvaluationSize(anal1, 0, true, "anal1");

                // Non-duplicate, to make sure it does not get approved.
                anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal2 = anal;
                mb    = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.SenseRA = pigNSense;
                CheckEvaluationSize(anal2, 0, true, "anal2");

                // Second of two duplicate analyses
                anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal3 = anal;
                mb    = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                CheckEvaluationSize(anal3, 0, true, "anal3");
                CheckAnalysisSize("pigsTEST", 3, false);

                result = new ParseResult(new[]
                {
                    new ParseAnalysis(new[]
                    {
                        new ParseMorph(pigNForm, pigNMsa)
                    })
                });
            });

            m_filer.ProcessParse(pigs, ParserPriority.Low, result);
            ExecuteIdleQueue();
            CheckEvaluationSize(anal1, 1, false, "anal1Hvo");
            Assert.IsFalse(anal2.IsValidObject, "analysis 2 should end up with no evaluations and so be deleted");
            CheckEvaluationSize(anal3, 1, false, "anal3Hvo");
        }