Exemplo n.º 1
0
		/// <summary>
		/// Make one. Everything interesting happens when it is given a root object, however.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoAnalysis"></param>
		/// <param name="configurationNode"></param>
		/// <param name="stringTable"></param>
		public AnalysisInterlinearRS(FdoCache cache, int hvoAnalysis,
			XmlNode configurationNode, StringTable stringTable) : base(cache)
		{
			m_configurationNode = configurationNode;
			m_hvoWfiAnalysis = hvoAnalysis;
			m_wordform = (WfiWordform)CmObject.CreateFromDBObject(m_fdoCache, m_fdoCache.GetOwnerOfObject(m_hvoWfiAnalysis), false);
			//			RightMouseClickedEvent += new FwRightMouseClickEventHandler(InterlinDocChild_RightMouseClickedEvent);
		}
Exemplo n.º 2
0
		public void VectorEnumerator()
		{
			CheckDisposed();

			FdoOwningCollection<IWfiWordform> oc = m_fdoCache.LangProject.WordformInventoryOA.WordformsOC;
			//do this two times to reduce the interference of which method went first.
			for (int i = 0; i< 2; i++)
			{
				//test using hvos and no pre-caching
				int[] hvos = oc.HvoArray;
				foreach(int hvo in hvos)
				{
					WfiWordform word;
					word = new WfiWordform (m_fdoCache, hvo);
				}
			}
		}
Exemplo n.º 3
0
		public void SetAgentOpinion()
		{
			ICmAgent agent = m_fdoCache.LangProject.DefaultComputerAgent;
			IWfiWordform wf = new WfiWordform(m_fdoCache, WfiWordform.FindOrCreateWordform(m_fdoCache,"xxxyyyzzz12234", m_fdoCache.DefaultVernWs, true));
			IWfiAnalysis wa = new WfiAnalysis();
			wf.AnalysesOC.Add(wa);
			ICmObject target = wa; // can pick anything as target for evaluation!

			m_fdoCache.BeginUndoTask("doit", "undoit");
			wa.SetAgentOpinion(agent, Opinions.approves);
			m_fdoCache.EndUndoTask();
			Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));
			m_fdoCache.Undo();
			Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
			m_fdoCache.Redo();
			Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));

			m_fdoCache.BeginUndoTask("changeit", "unchangeit");
			wa.SetAgentOpinion(agent, Opinions.disapproves);
			m_fdoCache.EndUndoTask();
			Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));
			m_fdoCache.Undo();
			Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));
			m_fdoCache.Redo();
			Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));

			m_fdoCache.BeginUndoTask("clearit", "unclearit");
			wa.SetAgentOpinion(agent, Opinions.noopinion);
			m_fdoCache.EndUndoTask();
			Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
			m_fdoCache.Undo();
			Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));
			m_fdoCache.Redo();
			Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
		}
Exemplo n.º 4
0
		private bool BaselineFormDiffersFromAnalysisWord(int hvoAnnotation, out ITsString baselineCbaForm)
		{
			ICmBaseAnnotation cbaRealAnnotation = CmBaseAnnotation.CreateFromDBObject(m_fdoCache, hvoAnnotation);
			baselineCbaForm = StTxtPara.TssSubstring(cbaRealAnnotation);
			int wsBaselineCbaForm = StringUtils.GetWsAtOffset(baselineCbaForm, 0);
			// We've updated the annotation to have InstanceOf set to the NEW analysis, so what we now derive from
			// that is the NEW wordform.
			int hvoNewWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoAnnotation);
			WfiWordform wfNew = new WfiWordform(Cache, hvoNewWf);
			ITsString tssWfNew = wfNew.Form.GetAlternativeTss(wsBaselineCbaForm);
			return !baselineCbaForm.Equals(tssWfNew);
		}
Exemplo n.º 5
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)
			{
				//RightMouseClickedEvent -= new FwRightMouseClickEventHandler(InterlinDocChild_RightMouseClickedEvent);
				if (m_oneAnalSandbox != null)
				{
					if (!Controls.Contains(m_oneAnalSandbox))
						m_oneAnalSandbox.Dispose();
				}
				if (m_vc != null)
					m_vc.Dispose();
			}
			m_oneAnalSandbox = null;
			m_vc = null;
			m_configurationNode = null;
			m_wordform = null;
		}
Exemplo n.º 6
0
		private IWfiAnalysis SetupAnalysisForEntry(int hvoCba0_0, string gloss, ILexSense lexEntry1_Sense1, out WfiWordform wf)
		{
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			wf = new WfiWordform(Cache, hvoWf);
			IWfiAnalysis analysis = wf.AnalysesOC.Add(new WfiAnalysis());
			analysis.CategoryRA = (lexEntry1_Sense1.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA;
			IWfiGloss wfigloss = analysis.MeaningsOC.Add(new WfiGloss());
			wfigloss.Form.SetAlternative(gloss, Cache.DefaultAnalWs);
			return analysis;
		}
Exemplo n.º 7
0
		public void PickLexGlossCreatingNewAnalysis()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			ILexEntry lexEntry1_Entry;
			ILexSense lexEntry1_Sense1;
			SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries or senses to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.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 morph is linked to our lexicon sense, msa, and part of speech.
			ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

			// confirm we have created a new analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
		}
Exemplo n.º 8
0
			/// <summary>
			/// Do the bulk of the computation, everything after initial error checking, which is now nonexistent.
			/// </summary>
			/// <returns>HVO of analysis (WfiWordform, WfiAnalyis, or WfiGloss)</returns>
			private int FinishItOff()
			{
				FdoCache fdoCache = m_caches.MainCache;
				IWordformInventory wfi = fdoCache.LangProject.WordformInventoryOA;
				// Enhance JohnT: this detects temporary, dummy objects at present, but it would be better
				// to make an interface method on ISilDataAccess (or possibly IVwCacheDa) to test for dummy IDs.
				// Note that IsValidObject considers dummy IDs to be valid, so it won't work here.
				if (fdoCache.IsDummyObject(m_hvoWordform))
				{
					// The 'wordform' we were analyzing was a dummy one made by the parser. Now it needs to
					// become real.
					Debug.Fail("Any basic wordform in the FocusBox should now already be a real wordform.");
					// Note: We currently don't use OnRequestConversionToReal here because that will currently
					// only do the conversion if our DummyRecordList has been created.
					// The side effect is that our DummyRecordList will do a full reload if we are in the Words area.
					m_hvoWordform = (wfi as IDummy).ConvertDummyToReal(
						WordformInventory.ConcordanceWordformsFlid(fdoCache), m_hvoWordform).Hvo;
				}
				if (m_hvoWordform == 0)
				{
					// first see if we can find a matching form
					m_hvoWordform = wfi.GetWordformId(m_tssForm);
					// The user selected a case form that did not previously have a WfiWordform.
					// Since he is confirming this analysis, we now need to create one.
					// Note: if in context of the wordforms DummyRecordList, the RecordList is
					// smart enough to handle inserting one object without having to Reload the whole list.
					if (m_hvoWordform == 0)
						m_hvoWordform = wfi.AddRealWordform(m_tssForm).Hvo;
				}
				CleanupCurrentAnnotation();	// if user confirmed alternate case, we may need to readjust InstanceOf.
				// If sandbox contains only an empty morpheme string, don't consider this to be a true analysis.
				// Assume that the user was not finished with his analysis (cf. LT-1621).
				if (m_sandbox.IsAnalysisEmpty)
				{
					return m_hvoWordform;
				}

				// Update the wordform with any additional wss.
				List<int> wordformWss = m_choices.OtherWritingSystemsForFlid(InterlinLineChoices.kflidWord, 0);
				// we need another way to detect the static ws for kflidWord.
				foreach (int wsId in wordformWss)
				{
					UpdateMlaIfDifferent(m_hvoSbWord, ktagSbWordForm, wsId, m_hvoWordform, (int)WfiWordform.WfiWordformTags.kflidForm);
				}

				// (LT-7807)
				// if we're in a special mode for adding monomorphemic words to lexicon
				// if we don't have a lexeme form match, create a new lex entry and sense OR
				// if we have a lexeme form, but no gloss match, create a new sense for the matching LexEntry OR
				// if we have a lexeme form and gloss match, just use it in the analysis.
				if (m_sandbox.ShouldAddWordGlossToLexicon)
				{
					IhMorphEntry.MorphItem matchingMorphItem = new IhMissingEntry.MorphItem(0, null);
					WfiWordform wf = new WfiWordform(fdoCache, m_hvoWordform);
					ITsString tssWf = wf.Form.GetAlternativeTss(m_sandbox.RawWordformWs);
					// go through the combo options for lex entries / senses to see if we can find any existing matches.
					int hvoSbMorph = m_sda.get_VecItem(m_hvoSbWord, ktagSbWordMorphs, 0);
					using (SandboxBase.IhMorphEntry handler = InterlinComboHandler.MakeCombo(Sandbox.ktagWordGlossIcon, m_sandbox, hvoSbMorph) as SandboxBase.IhMorphEntry)
					{
						List<IhMorphEntry.MorphItem> morphItems = handler.MorphItems;
						// see if we can use an existing Sense, if it matches the word gloss and word MSA
						foreach (IhMorphEntry.MorphItem morphItem in morphItems)
						{
							// skip lex senses that do not match word gloss and pos in the Sandbox
							if (!SbWordGlossMatchesSenseGloss(morphItem))
								continue;
							if (!SbWordPosMatchesSenseMsaPos(morphItem))
								continue;
							// found a LexSense matching our Word Gloss and MSA POS
							matchingMorphItem = morphItem;
							break;
						}
						// if we couldn't use an existing sense but we match a LexEntry form,
						// add a new sense to an existing entry.
						ILexEntry bestEntry = null;
						if (morphItems.Count > 0 && matchingMorphItem.m_hvoSense == 0)
						{
							// Tried using FindBestLexEntryAmongstHomographs() but it matches
							// only CitationForm which MorphItems doesn't know anything about,
							// and doesn't match against Allomorphs which MorphItems do track
							// so this could lead to a crash (LT-9430).
							//
							// Solution: if the user specified a category, see if we can find an entry
							// with a sense using that same category
							// otherwise just add the new sense to the first entry in MorphItems.
							IhMorphEntry.MorphItem bestMorphItem = morphItems[0];
							foreach (IhMorphEntry.MorphItem morphItem in morphItems)
							{
								// skip items that do not match word main pos in the Sandbox
								if (!SbWordMainPosMatchesSenseMsaMainPos(morphItem))
									continue;
								bestMorphItem = morphItem;
								break;
							}

							int hvoEntry = bestMorphItem.GetPrimaryOrOwningEntry(m_caches.MainCache);
							if (hvoEntry != 0)
								bestEntry = LexEntry.CreateFromDBObject(m_caches.MainCache, hvoEntry);
							// lookup this entry;
							matchingMorphItem = FindLexEntryMorphItem(morphItems, bestEntry);
						}

						if (matchingMorphItem.m_hvoMorph == 0)
						{
							// we didn't find a matching lex entry, so create a new entry
							ILexEntry newEntry;
							ILexSense newSense;
							IMoForm allomorph;
							handler.CreateNewEntry(true, out newEntry, out allomorph, out newSense);
						}
						else if (bestEntry != null)
						{
							// we found matching lex entry, so create a new sense for it
							ILexSense newSense = LexSense.CreateSense(bestEntry, new DummyGenericMSA(), "");
							// copy over any word glosses we're showing.
							foreach (int wsId in m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss))
							{
								UpdateMlaIfDifferent(m_hvoSbWord, ktagSbWordGloss, wsId, newSense.Hvo, (int)LexSense.LexSenseTags.kflidGloss);
							}
							// copy over the Word POS
							(newSense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo =
								m_caches.RealHvo(m_sda.get_ObjectProp(m_hvoSbWord, ktagSbWordPos));
							handler.UpdateMorphEntry(matchingMorphItem.m_hvoMorph, bestEntry.Hvo, newSense.Hvo);
						}
						else
						{
							// we found a matching lex entry and sense, so select it.
							int iMorphItem = morphItems.IndexOf(matchingMorphItem);
							handler.HandleSelect(iMorphItem);
						}
					}
				}

				BuildMorphLists(); // Used later on in the code.
				m_hvoCategoryReal = m_caches.RealHvo(m_sda.get_ObjectProp(m_hvoSbWord, ktagSbWordPos));

				// We may need to create a new WfiAnalysis based on whether we have any sandbox gloss content.
				bool fNeedGloss = false;
				bool fWordGlossLineIsShowing = false; // Set to 'true' if the wrod gloss line is included in the m_choices fields.
				foreach (InterlinLineSpec ilc in m_choices)
				{
					if (ilc.Flid == InterlinLineChoices.kflidWordGloss)
					{
						fWordGlossLineIsShowing = true;
						break;
					}
				}
				if (fWordGlossLineIsShowing)
				{
					// flag that we need to create wfi gloss information if any configured word gloss lines have content.
					foreach (int wsId in m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss))
					{
						if (m_sda.get_MultiStringAlt(m_hvoSbWord, ktagSbWordGloss, wsId).Length > 0)
						{
							fNeedGloss = true;
							break;
						}
					}
				}

				// We decided to take this logic out (see LT-1653) because it is annoying when
				// deliberately removing a wrong morpheme breakdown guess.
				//				// We need to create (or find an existing) WfiAnalysis if we have any morphemes,
				//				// a word gloss, or a word category.
				//				bool fNeedAnalysis = fNeedGloss || m_cmorphs > 1 || m_hvoCategoryReal != 0;
				//
				//				// If we have exactly one morpheme, see if it has some non-trivial information
				//				// associated. If not, don't make an analysis.
				//				if (!fNeedGloss && m_cmorphs == 1 && m_hvoCategoryReal == 0 && m_analysisMsas[0] == 0
				//					&& m_analysisSenses[0] == 0 && m_analysisMorphs[0] == 0)
				//				{
				//					fNeedAnalysis = false;
				//				}
				//				// If there's no information at all, the 'analysis' is just the original wordform.
				//				if (!fNeedAnalysis)
				//					return m_hvoWordform;
				// OK, we have some information that corresponds to an analysis. Find or create
				// an analysis that matches.
				int wsVern = m_sandbox.RawWordformWs;
				m_hvoWfiAnalysis = FindMatchingAnalysis(true);
				bool fFoundAnalysis = m_hvoWfiAnalysis != 0;
				if (!fFoundAnalysis)
				{
					// Clear the checksum on the wordform. This allows the parser filer to re-evaluate it and
					// delete the old analysis if it is just a simpler, parser-generated form of the one we're now making.
					m_sdaMain.SetInt(m_hvoWordform, (int)WfiWordform.WfiWordformTags.kflidChecksum, 0);
					// Check whether there's a parser-generated analysis that the current settings
					// subsume.  If so, reuse that analysis by filling in the missing data (word gloss,
					// word category, and senses).
					int hvoPartialWfiAnal = FindMatchingAnalysis(false);
					bool fNewAnal = hvoPartialWfiAnal == 0;
					if (fNewAnal)
					{
						// Create one.
						m_hvoWfiAnalysis = m_sdaMain.MakeNewObject(WfiAnalysis.kclsidWfiAnalysis, m_hvoWordform,
							(int)WfiWordform.WfiWordformTags.kflidAnalyses, -1);
						// Use the following instead of -1 if the collection is changed to a sequence.
						//	m_sdaMain.get_VecSize(m_hvoWordform, (int)WfiWordform.WfiWordformTags.kflidAnalyses));
					}
					else
					{
						m_hvoWfiAnalysis = hvoPartialWfiAnal;
					}
					m_sdaMain.SetObjProp(m_hvoWfiAnalysis, (int)WfiAnalysis.WfiAnalysisTags.kflidCategory, m_hvoCategoryReal);
					for (int imorph = 0; imorph < m_cmorphs; imorph++)
					{
						int hvoMb;
						if (fNewAnal)
						{
							hvoMb = m_sdaMain.MakeNewObject(WfiMorphBundle.kclsidWfiMorphBundle, m_hvoWfiAnalysis,
								(int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles, imorph);
						}
						else
						{
							hvoMb = m_sdaMain.get_VecItem(m_hvoWfiAnalysis,
								(int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles, imorph);
						}
						// An undo operation can leave stale information in the sandbox.  If
						// that happens, the stored database id values are invalid.  Set them
						// all to zero if the morph is invalid.  (See LT-3824 for a crash
						// scenario.)  This fix prevents a crash, but doesn't do anything for
						// restoring the original values before the operation that is undone.
						if (m_analysisMorphs[imorph] != 0 &&
							!m_sdaMain.get_IsValidObject(m_analysisMorphs[imorph]))
						{
							m_analysisMorphs[imorph] = 0;
							m_analysisMsas[imorph] = 0;
							m_analysisSenses[imorph] = 0;
						}
						// Set the Morph of the bundle if we know a real one; otherwise, just set its Form
						if (m_analysisMorphs[imorph] == 0)
						{
							int hvoSbMorph = m_sda.get_VecItem(m_hvoSbWord, ktagSbWordMorphs, imorph);
							m_sdaMain.SetMultiStringAlt(hvoMb,
								(int)WfiMorphBundle.WfiMorphBundleTags.kflidForm, wsVern,
								m_sandbox.GetFullMorphForm(hvoSbMorph));
							// Copy any other wss over, without any funny business about morpheme breaks
							foreach (int ws in m_choices.OtherWritingSystemsForFlid(InterlinLineChoices.kflidMorphemes, 0))
							{
								m_sdaMain.SetMultiStringAlt(hvoMb,
									(int)WfiMorphBundle.WfiMorphBundleTags.kflidForm, ws,
									m_caches.DataAccess.get_MultiStringAlt(hvoSbMorph, ktagSbNamedObjName, ws));
							}
						}
						else
						{
							m_sdaMain.SetObjProp(hvoMb, (int)WfiMorphBundle.WfiMorphBundleTags.kflidMorph, m_analysisMorphs[imorph]);
						}
						// Set the MSA if we have one. Note that it is (pathologically) possible that the user has done
						// something in another window to destroy the MSA we remember, so don't try to set it if so.
						if (m_analysisMsas[imorph] != 0 && m_sdaMain.get_IsValidObject(m_analysisMsas[imorph]))
						{
							m_sdaMain.SetObjProp(hvoMb, (int)WfiMorphBundle.WfiMorphBundleTags.kflidMsa, m_analysisMsas[imorph]);
						}
						// Likewise the Sense
						if (m_analysisSenses[imorph] != 0)
						{
							m_sdaMain.SetObjProp(hvoMb, (int)WfiMorphBundle.WfiMorphBundleTags.kflidSense, m_analysisSenses[imorph]);
						}
					}
				}
				else if (fWordGlossLineIsShowing) // If the line is not showing at all, don't bother.
				{
					// (LT-1428) Since we're using an existing WfiAnalysis,
					// We will find or create a new WfiGloss (even for blank lines)
					// if WfiAnalysis already has WfiGlosses
					//	or m_hvoWordGloss is nonzero
					//	or Sandbox has gloss content.
					bool fSbGlossContent = fNeedGloss;
					int cGloss = m_sdaMain.get_VecSize(m_hvoWfiAnalysis,
						(int)WfiAnalysis.WfiAnalysisTags.kflidMeanings);
					fNeedGloss = cGloss > 0 || m_hvoWordGloss != 0 || fSbGlossContent;
				}

				if (m_hvoWfiAnalysis != 0)
					EnsureCorrectMorphForms();

				if (!fNeedGloss || m_fWantOnlyWfiAnalysis)
					return m_hvoWfiAnalysis;

				if (m_hvoWordGloss != 0)
				{
					// We may consider editing it instead of making a new one.
					// But ONLY if it belongs to the right analysis!!
					if (fdoCache.GetOwnerOfObject(m_hvoWordGloss) != m_hvoWfiAnalysis)
						m_hvoWordGloss = 0;
				}
				/* These are the types of things we are trying to accomplish here.
				Problem 1 -- Correcting a spelling mistake.
					Gloss1: mn <-
				User corrects spelling to men
				Desired:
					Gloss1: men <-
				Bad result:
					Gloss1: mn
					Gloss2: men <-

				Problem 2 -- Switching to a different gloss via typing.
					Gloss1: he <-
					Gloss2: she
				User types in she rather than using dropdown box to select it
				Desired:
					Gloss1: he
					Gloss2: she <-
				Bad result:
					Gloss1: she <-
					Gloss2: she

				Problem 2A
							Gloss1: he <-
				User types in she without first using dropdown box to select "add new gloss"
				Desired:
							Gloss1: he (still used for N other occurrences)
							Gloss2: she <-
				Bad (at least dubious) result:
							Gloss1: she <- (used for this and all other occurrences)

				Problem 3 -- Adding a missing alternative when there are not duplications.
					Gloss1: en=green <-
				User adds the French equivalent
				Desired:
					Gloss1: en=green, fr=vert <-
				Bad result:
					Gloss1: en=green
					Gloss2: en=green, fr=vert <-

				The logic used to be to look for glosses with all alternatives matching or else it
				creates a new one. So 2 would actually work, but 1 and 3 were both bad.

				New logic: keep track of the starting WfiAnalysis and WfiGloss.
				Assuming we haven't changed to a new WfiAnalysis based on other changes, if there
				is a WfiGloss that matches any of the existing alternatives, we switch to that.
				Otherwise we set the alternatives of the starting WfiGloss to whatever the user
				entered. This logic would work for all three examples above, but has problems
				with the following.

				Problem -- add a missing gloss where there are identical glosses in another ws.
					Gloss1: en=them <-
				User adds Spanish gloss
				Desired:
					Gloss1: en=them, es=ellas <-
				This works ok with above logic. But now in another location the user needs to
				use the masculine them in Spanish, so changes ellas to ellos
				Desired:
					Gloss1: en=them, es=ellas
					Gloss2: en=them, es=ellos <-
				Bad result:
					Gloss1: en=them, es=ellos <-

				Eventually, we'll probably want to display a dialog box to ask users what they really want.
				"There are 15 places where "XXX" analyzed as 3pp is currently glossed
				en->"them".  Would you like to
				<radio button, selected> change them all to en->"them" sp->"ellas"?
				<radio button> leave the others glossed en->"them" and let just this one
				be en->"them" sp->"ellas"?
				<radio button> see a concordance and choose which ones to change to
				en->"them" sp->"ellas"?
				*/

				// (LT-1428)
				// -----------------------------
				// When the user edits a gloss,
				// (1) If there is an existing gloss matching what they just changed it to
				//		then switch this instance to point to that one.
				// (2) Else if the gloss is used only in this instance
				//		then apply the edits directly to the gloss.
				// (3) Else, create a new gloss.
				//-------------------------------
				int hvoGloss = fFoundAnalysis ? FindMatchingGloss() : 0;

				if (hvoGloss == 0 && m_sandbox.WordGlossReferenceCount == 1)
				{
					hvoGloss = m_hvoWordGloss; // update the existing gloss.
				}

				if (hvoGloss == 0)
				{
					// Create one.
					hvoGloss = m_sdaMain.MakeNewObject(WfiGloss.kclsidWfiGloss, m_hvoWfiAnalysis,
						(int)WfiAnalysis.WfiAnalysisTags.kflidMeanings, -1);
					// use the following if changed to sequence.
					//	m_sdaMain.get_VecSize(m_hvoWfiAnalysis, (int)WfiAnalysis.WfiAnalysisTags.kflidMeanings));

				}
				foreach (int wsId in m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss))
				{
					ITsString tssGloss = m_sda.get_MultiStringAlt(m_hvoSbWord, ktagSbWordGloss, wsId);
					if (!tssGloss.Equals(m_sdaMain.get_MultiStringAlt(hvoGloss,
						(int)WfiGloss.WfiGlossTags.kflidForm, wsId)))
					{
						m_sdaMain.SetMultiStringAlt(hvoGloss, (int)WfiGloss.WfiGlossTags.kflidForm,
							wsId, tssGloss);
					}
				}
				return hvoGloss;
			}
Exemplo n.º 9
0
		public void NewGlossExistingLexEntryNewLexSense()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			string formLexEntry = "xxxa";
			ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
			int clsidForm;
			ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache,
				MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
				"xxxa.existingsense1", null);
			ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0];

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);

			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);
		}
Exemplo n.º 10
0
		public void NewGlossExistingLexEntryAllomorphNewLexSense()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			string formLexEntry = "xxxab";
			ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
			string formAllomorph = "xxxa";
			ITsString tssAllomorphForm = StringUtils.MakeTss(formAllomorph, Cache.DefaultVernWs);

			// first create an entry with a matching allomorph that doesn't match 'verb' POS we will be selecting in the sandbox
			ILexEntry lexEntry_NounPos;
			ILexSense lexSense_NounPos;
			SetupLexEntryAndSense("xxxab", "0.0.xxxab_NounPos", "noun", out lexEntry_NounPos, out lexSense_NounPos);
			IMoStemAllomorph allomorph0 = lexEntry_NounPos.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;
			allomorph0.Form.SetAlternativeTss(tssAllomorphForm);

			// now create the entry we want to match, that has a 'verb' POS.
			ILexEntry lexEntry1_Entry;
			ILexSense lexEntry1_Sense1;
			SetupLexEntryAndSense("xxxab", "0.0.xxxab_VerbPos", "verb", out lexEntry1_Entry, out lexEntry1_Sense1);
			IMoStemAllomorph allomorph = lexEntry1_Entry.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;
			allomorph.Form.SetAlternativeTss(tssAllomorphForm);

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos to verb
			int hvoSbWordPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, "transitive verb");
			m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordPos, 0, hvoSbWordPos);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);

			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos, true, allomorph);
		}
Exemplo n.º 11
0
		public void NewGlossNewLexEntryNewLexSense()
		{
			// load sandbox for first 'xxxa'
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);

			// verify that the word gloss is empty
			ITsString tssEmpty = StringUtils.MakeTss("", Cache.DefaultAnalWs);
			ITsString tssWordGloss = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);
			CompareTss(tssEmpty, tssWordGloss);
			// add a new word gloss and confirm the analysis.
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;
			// verify no analyses exist for this wordform;
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			Assert.AreEqual(0, wf.AnalysesOC.Count);

			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);
			Assert.IsFalse(hvoSbWordPos == 0);	 // select nonzero pos

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();

			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);
			CompareTss(tssWordGlossInSandbox, wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));
			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);

			// make sure a new entry is in the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig + 1, cEntriesAfter);
		}
Exemplo n.º 12
0
		public void SetGetMultiUnicode()
		{
			CheckDisposed();

			m_inMemoryCache.InitializeLexDb();

			WfiWordform w = new WfiWordform();
			Cache.LangProject.WordformInventoryOA.WordformsOC.Add(w);

			// TEST WRITE
			string s = "test" + m_rand.Next().ToString();
			w.Form.AnalysisDefaultWritingSystem = s;

			// TEST READ

			Assert.AreEqual(s, w.Form.AnalysisDefaultWritingSystem);
		}
Exemplo n.º 13
0
		// Make some sort of wfics for the text of the specified paragraph. Assumes no double spaces!
		// Caches results and does not repeat on same para
		internal int[] MakeAnnotations(StTxtPara para)
		{
			int[] previous;
			if (m_annotations.TryGetValue(para.Hvo, out previous))
				return previous;
			string contents = para.Contents.Text;
			string[] words = contents.Split(new char[] { ' ', '.' });
			int ich = 0;
			List<int> results = new List<int>();
			ICmAnnotationDefn WficType = CmAnnotationDefn.Twfic(Cache);
			foreach (string word in words)
			{
				if (word == "")
				{
					ich++;
					continue;
				}
				WfiWordform wordform = new WfiWordform();
				Cache.LangProject.WordformInventoryOA.WordformsOC.Add(wordform);
				wordform.Form.SetAlternative(word, Cache.DefaultVernWs);
				// JohnT: This should ideally use CmBaseAnnotation.CreateUnownedCba. But most or all uses of this
				// method are memory-only tests, and that method requires a database.
				CmBaseAnnotation cba = new CmBaseAnnotation();
				Cache.LangProject.AnnotationsOC.Add(cba);
				cba.BeginOffset = ich;
				ich += word.Length;
				cba.EndOffset = ich;
				ich++; // past space or dot
				cba.BeginObjectRA = para;
				cba.AnnotationTypeRA = WficType;
				//cba.AnnotationTypeRA = ?? can we get CmAnnotationDefn.Twfic(Cache) with a non-database cache?
				WfiAnalysis analysis = new WfiAnalysis();
				wordform.AnalysesOC.Add(analysis);
				WfiGloss gloss = new WfiGloss();
				analysis.MeaningsOC.Add(gloss);
				gloss.Form.SetAlternative(word + "Gloss" + ich, Cache.DefaultAnalWs);
				cba.InstanceOfRA = gloss;
				results.Add(cba.Hvo);

			}
			int[] result = results.ToArray();
			m_annotations[para.Hvo] = result;
			return result;
		}
Exemplo n.º 14
0
		/// <summary>
		/// Put the wordform in the highest priority queue of the Parser
		/// </summary>
		/// <param name="wf"></param>
		public void UpdateWordformAsap(WfiWordform wf)
		{
			CheckDisposed();

			ParserConnection con = Connection;
			if (con != null && con.Parser != null &&
				wf.Form.VernacularDefaultWritingSystem != null)
			{
				con.Parser.ScheduleOneWordformForUpdate(wf.Hvo, WordWorks.Parser.ParserScheduler.Priority.ASAP);
			}
		}
Exemplo n.º 15
0
		private IWfiMorphBundle SetupMorphBundleForEntry(int hvoCba0_0, string gloss, ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, out WfiWordform wf)
		{
			IWfiAnalysis analysis = SetupAnalysisForEntry(hvoCba0_0, gloss, lexEntry1_Sense1, out wf);
			return AppendMorphBundleToAnalysis(lexEntry1_Entry, lexEntry1_Sense1, analysis);
		}
Exemplo n.º 16
0
		private string FormOfWord(int hvo)
		{
			try
			{
				WfiWordform word = new WfiWordform (m_cache, hvo);
				return word.Form.VernacularDefaultWritingSystem;
			}
			catch (Exception)
			{
				Debug.Assert(false, "The word returned in msg from parser apparently doesn't exist in db");
				return ParserUIStrings.ksUnknown;
			}
		}
Exemplo n.º 17
0
		private ITsString GetBestVernWordform(int hvoWordform)
		{
			// first we'll try getting vernacular ws directly, since it'll be true in most cases.
			ITsString tssForm = m_caches.MainCache.MainCacheAccessor.get_MultiStringAlt(
				hvoWordform, (int)WfiWordform.WfiWordformTags.kflidForm, this.RawWordformWs);
			if (tssForm == null || tssForm.Length == 0)
			{
				// see if we can find a best vernacular form to use instead.
				// (Currently dummy wordforms only support default vernacular.)
				if (!m_caches.MainCache.IsDummyObject(hvoWordform))
				{
					IWfiWordform wf = new WfiWordform(m_caches.MainCache, hvoWordform);
					tssForm = wf.Form.BestVernacularAlternative;
				}
			}
			return tssForm;
		}