示例#1
0
		/// <summary>
		/// This is called (by reflection) in an RDE view (DoMerges() method of XmlBrowseRDEView)
		/// that is creating LexSenses (and entries) by having
		/// the user enter a lexeme form and definition
		/// for a collection of words in a given semantic domain.
		/// On loss of focus, switch domain, etc., this method is called for each
		/// newly created sense, to determine whether it can usefully be merged into some
		/// pre-existing lex entry.
		///
		/// The idea is to do one of the following, in order of preference:
		/// (a) If there are other LexEntries which have the same LF and a sense with the
		/// same definition, add hvoDomain to the domains of those senses, and delete hvoSense.
		/// (b) If there is a pre-existing LexEntry (not the owner of one of newHvos)
		/// that has the same lexeme form, move hvoSense to that LexEntry.
		/// (c) If there is another new LexEntry (the owner of one of newHvos other than hvoSense)
		/// that has the same LF, we want to merge the two. In this case we expect to be called
		/// in turn for all of these senses, so to simplify, the one with the smallest HVO
		/// is kept and the others merged.
		/// </summary>
		/// <param name="hvoDomain"></param>
		/// <param name="tagList"></param>
		/// <param name="columns">List of XmlNode objects</param>
		/// <param name="cache"></param>
		/// <param name="hvoSense"></param>
		/// <param name="newHvos">Set of new senses (including hvoSense).</param>
		public static void RDEMergeSense(int hvoDomain, int tagList,
			List<XmlNode> columns, FdoCache cache, int hvoSense, Set<int> newHvos)
		{
			// The goal is to find a lex entry with the same lexeme form.form as hvoSense's LexEntry.
			ILexSense ls = LexSense.CreateFromDBObject(cache, hvoSense);
			ILexEntry leTarget = LexEntry.CreateFromDBObject(cache, ls.EntryID);
			string homographForm = leTarget.HomographForm;
			string sDefnTarget = ls.Definition.AnalysisDefaultWritingSystem.Text;

			// Check for pre-existing LexEntry which has the same homograph form
			bool fGotExactMatch;
			ILexEntry leSaved = FindBestLexEntryAmongstHomographs(cache, homographForm, sDefnTarget, leTarget, newHvos, hvoDomain, out fGotExactMatch);
			if (fGotExactMatch)
			{
				// delete the entry AND sense
				leTarget.DeleteUnderlyingObject();
				DeleteSense(cache, hvoDomain, tagList, hvoSense);
			}
			else if (leSaved != null)
			{
				// move the one and only sense of leTarget to leSaved...provided it has a compatible MSA
				// of the expected type.
				ILexSense sense = leTarget.SensesOS.FirstItem as ILexSense;
				if (sense.MorphoSyntaxAnalysisRA is MoStemMsa)
				{
					IMoMorphSynAnalysis newMsa = null;
					foreach (IMoMorphSynAnalysis msa in leSaved.MorphoSyntaxAnalysesOC)
					{
						if (msa is IMoStemMsa)
							newMsa = msa;
					}
					if (newMsa != null)
					{
						// Fix the MSA of the sense to point at one of the MSAs of the new owner.
						sense.MorphoSyntaxAnalysisRA = newMsa;
						// Move it to the new owner.
						cache.MoveOwningSequence(leTarget.Hvo, (int)LexEntry.LexEntryTags.kflidSenses, 0, 0,
							leSaved.Hvo, (int)LexEntry.LexEntryTags.kflidSenses, leSaved.SensesOS.Count);
						// delete the entry.
						leTarget.DeleteUnderlyingObject();
						// But NOT the sense from the domain...it just moved to another entry.
						//DeleteSense(cache, hvoDomain, tagList, hvoSense);
					}
				}
			}
			// else do nothing (no useful match, let the LE survive)
		}