private void SearchInAbbreviationForMatches(ICmSemanticDomain domain)
 {
     if (domain.Abbreviation.BestAnalysisAlternative.Text.StartsWith(m_searchString))
     {
         SearchResults.AddResultToBucketX(0, domain);
     }
 }
Ejemplo n.º 2
0
        private void SetRelatedDomainsLinks()
        {
            ICmSemanticDomainRepository repo = m_cache.ServiceLocator.GetInstance <ICmSemanticDomainRepository>();

            foreach (Guid guidKey in m_mapRelatedDomains.Keys)
            {
                try
                {
                    ICmSemanticDomain dom = repo.GetObject(guidKey);
                    foreach (Guid guidLink in m_mapRelatedDomains[guidKey])
                    {
                        try
                        {
                            ICmSemanticDomain domLink = repo.GetObject(guidLink);
                            dom.RelatedDomainsRC.Add(domLink);
                        }
                        catch { }
                    }
                    if (m_progress != null)
                    {
                        m_progress.Step(1);
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the text from a Semantic Domain's Name field.
        /// </summary>
        /// <param name="domain"></param>
        /// <returns>an array of Tuples, where each Tuple has a ws handle and a name string</returns>
        private static Tuple <int, string>[] GetDomainNameString(ICmSemanticDomain domain)
        {
            var name = domain.Name;

            return(name.AvailableWritingSystemIds.Select(ws => new Tuple <int, string>(
                                                             ws, name.get_String(ws).Text)).Where(tuple => !String.IsNullOrEmpty(tuple.Item2)).ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Take a string to look in (from a domain's Name or ExampleWords) and try to find
        /// a match for some (strategy-defined) search key(s).
        /// </summary>
        /// <param name="searchIn"></param>
        /// <param name="domain"></param>
        /// <param name="wholeWordBucket"></param>
        /// <returns></returns>
        protected bool CollectPossibleMatchIn(string searchIn, ICmSemanticDomain domain, int wholeWordBucket)
        {
            if (string.IsNullOrEmpty(searchIn))
            {
                return(false);
            }
            var wordsToLookIn = ParseStringIntoWords(searchIn);

            switch (DoesInputMatchWord(wordsToLookIn))
            {
            case MatchingResult.WholeWordMatch:
                SearchResults.AddResultToBucketX(wholeWordBucket, domain);
                return(true);

            case MatchingResult.StartOfWordMatch:
                SearchResults.AddResultToBucketX(wholeWordBucket + PartialMatchRelativeIndex, domain);
                return(true);

            case MatchingResult.NoMatch:
                // do nothing
                break;

            default:
                throw new ApplicationException("Unknown MatchingResult");
            }
            return(false);
        }
        protected override void PopulatePossibilityFromExtraData(ICmPossibility poss)
        {
            ICmSemanticDomain semdom = poss as ICmSemanticDomain;

            if (semdom == null)
            {
                return;
            }
            ILgWritingSystemFactory wsf = semdom.Cache.WritingSystemFactory;
            var questionFactory         = semdom.Cache.ServiceLocator.GetInstance <ICmDomainQFactory>();
            Dictionary <string, List <SemDomQuestion> > questionsByWs = GetExtraDataWsDict <SemDomQuestion>("Questions");
            // This dict looks like {"en": (question 1, question 2...)} but each question object wants to get data that
            // looks more or less like {"en": "the question in English", "fr": "la question en francais"}...
            // So first we ensure that there are enough question objects available, and then we'll access them by index
            // as we step through the writing systems.
            int numQuestions = questionsByWs.Values.Select(questionList => questionList.Count).Max();

            while (semdom.QuestionsOS.Count < numQuestions)
            {
                semdom.QuestionsOS.Add(questionFactory.Create());
            }
            foreach (string ws in questionsByWs.Keys)
            {
                int wsId = wsf.GetWsFromStr(ws);
                int i    = 0;
                foreach (SemDomQuestion qStruct in questionsByWs[ws])
                {
                    semdom.QuestionsOS[i].Question.set_String(wsId, qStruct.Question ?? string.Empty);
                    semdom.QuestionsOS[i].ExampleSentences.set_String(wsId, qStruct.ExampleSentences ?? string.Empty);
                    semdom.QuestionsOS[i].ExampleWords.set_String(wsId, qStruct.ExampleWords ?? string.Empty);
                    i++;
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// The buckets are ordered in priority so adding a result to one bucket
 /// should remove that result from all lower (higher index) ones.
 /// N.B. Strategy subclasses should take care not to add a domain to a bucket
 /// if it is already in a higher priority bucket.
 /// </summary>
 /// <param name="bucketIndex"></param>
 /// <param name="domain"></param>
 public void AddResultToBucketX(int bucketIndex, ICmSemanticDomain domain)
 {
     m_bucketList[bucketIndex].Add(domain);
     for (var i = bucketIndex + 1; i < m_bucketList.Length; i++)
     {
         m_bucketList[i].Remove(domain);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Subclasses can override this method to change how Semantic Domains are compared
 /// with any search key(s) and the priority types of matches for putting the
 /// domain into an appropriate search results bucket (if any).
 /// N.B. Strategy subclasses should take care not to add a domain to a bucket
 /// if it is already in a higher priority bucket.
 /// </summary>
 /// <param name="domain"></param>
 internal virtual void PutDomainInDesiredBucket(ICmSemanticDomain domain)
 {
     // Check for whole word and partial matches in Name first
     if (!CollectPossibleMatchIn(GetDomainNameString(domain), domain, WholeWordBucketIndex))
     {
         // If no whole word match in Name, look in Example Words too.
         CollectPossibleMatchIn(GetExampleWordsString(domain.QuestionsOS), domain, WholeWordExamplesBucketIndex);
     }
 }
 internal override void PutDomainInDesiredBucket(ICmSemanticDomain domain)
 {
     foreach (var kvp in m_searchKeys)
     {
         CurrentWs         = kvp.Key;
         CurrentSearchKeys = kvp.Value;
         base.PutDomainInDesiredBucket(domain);
     }
 }
Ejemplo n.º 9
0
		private void CacheWordsIn(Tuple<int, string>[] wsStringTupleArray, ICmSemanticDomain domain)
		{
			foreach (var tuple in wsStringTupleArray)
			{
				var ws = tuple.Item1;
				var words = ParseStringIntoWords(tuple.Item2);
				foreach (var word in words)
				{
					CacheWord(ws, word, domain);
				}
			}
		}
Ejemplo n.º 10
0
 private void CacheWordsIn(Tuple <int, string>[] wsStringTupleArray, ICmSemanticDomain domain)
 {
     foreach (var tuple in wsStringTupleArray)
     {
         var ws    = tuple.Item1;
         var words = ParseStringIntoWords(tuple.Item2);
         foreach (var word in words)
         {
             CacheWord(ws, word, domain);
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Don't count references to Semantic Domains from other Semantic Domains.
        /// The user only cares about how many times in the lexicon the Semantic Domain is used.
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public static int SenseReferenceCount(ICmSemanticDomain domain)
        {
            int count = 0;

            if (domain.ReferringObjects != null)
            {
                count = (from item in domain.ReferringObjects
                         where item is ILexSense
                         select item).Count();
            }
            return(count);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Load data that looks like this
 /// &lt;Questions&gt;
 ///	&lt;CmDomainQ&gt;
 ///		&lt;Question&gt;
 ///			&lt;AUni ws="en"&gt;(1) What words refer to the sun?&lt;/AUni&gt;
 ///			&lt;AUni ws="fr"&gt;Quels sont les mots pour parler du soleil?&lt;/AUni&gt;
 ///		&lt;/Question&gt;
 ///		&lt;ExampleWords&gt;
 ///			&lt;AUni ws="en"&gt;sun, solar, sol, daystar, our star&lt;/AUni&gt;
 ///			&lt;AUni ws="fr"&gt;soleil, solaire, notre soleil&lt;/AUni&gt;
 ///		&lt;/ExampleWords&gt;
 ///	&lt;/CmDomainQ&gt;
 ///	&lt;CmDomainQ&gt;
 ///		&lt;Question&gt;
 ///			&lt;AUni ws="en"&gt;(2) What words refer to the time when the sun rises?&lt;/AUni&gt;
 ///			&lt;AUni ws="fr"&gt;Quels sont les mots qui signifient le lever du soleil?&lt;/AUni&gt;
 ///		&lt;/Question&gt;
 ///		&lt;ExampleWords&gt;
 ///			&lt;AUni ws="en"&gt;dawn, sunrise, sunup, daybreak, cockcrow, &lt;/AUni&gt;
 ///		&lt;/ExampleWords&gt;
 ///		&lt;ExampleSentences&gt;
 ///			&lt;AStr ws="en"&gt;
 ///				&lt;Run ws="en"&gt;We got up before “dawn”, in order to get an early start.&lt;/Run&gt;
 ///			&lt;/AStr&gt;
 ///		&lt;/ExampleSentences&gt;
 ///	&lt;/CmDomainQ&gt;
 ///&lt;/Questions&gt;
 /// </summary>
 private void LoadQuestionsFromXml(XmlReader xrdr, ICmSemanticDomain dom)
 {
     Debug.Assert(dom != null);
     if (xrdr.ReadToDescendant("CmDomainQ"))
     {
         EnsureFactoryForClass("CmDomainQ");
         do
         {
             ReadDomainQuestion(xrdr.ReadSubtree(), dom);
         } while (xrdr.ReadToNextSibling("CmDomainQ"));
     }
     xrdr.Read();                // reads end element
 }
Ejemplo n.º 13
0
        private void ReadDomainQuestion(XmlReader xrdrSub, ICmSemanticDomain dom)
        {
            try
            {
                ICmDomainQ domQ = null;
                while (xrdrSub.Read())
                {
                    if (xrdrSub.NodeType == XmlNodeType.Element)
                    {
                        switch (xrdrSub.Name)
                        {
                        case "ExampleSentences":
                            if (domQ == null)
                            {
                                domQ = m_factCmDomainQ.Create();
                                dom.QuestionsOS.Add(domQ);
                            }
                            SetMultiStringFromXml(xrdrSub, domQ.ExampleSentences);
                            break;

                        case "ExampleWords":
                            if (domQ == null)
                            {
                                domQ = m_factCmDomainQ.Create();
                                dom.QuestionsOS.Add(domQ);
                            }
                            SetMultiUnicodeFromXml(xrdrSub, domQ.ExampleWords);
                            break;

                        case "Question":
                            if (domQ == null)
                            {
                                domQ = m_factCmDomainQ.Create();
                                dom.QuestionsOS.Add(domQ);
                            }
                            SetMultiUnicodeFromXml(xrdrSub, domQ.Question);
                            break;
                        }
                    }
                }
            }
            finally
            {
                xrdrSub.Close();
            }
        }
Ejemplo n.º 14
0
		private void CacheWord(int ws, string word, ICmSemanticDomain domain)
		{
			var searchKey = new Tuple<string, int>(word, ws);
			HashSet<ICmSemanticDomain> cachedValues; // out var
			if (m_semDomCache.TryGetValue(searchKey, out cachedValues))
			{
				if (cachedValues.Contains(domain))
					return; // this domain is already cached

				// searchKey is already cached, but we need to add this domain
				cachedValues.Add(domain);
				m_semDomCache.Remove(searchKey);
				m_semDomCache.Add(searchKey, cachedValues);
				return;
			}

			// searchKey was not found, add it with this domain
			m_semDomCache.Add(searchKey, new HashSet<ICmSemanticDomain>() { domain });
		}
        /// <summary>
        /// This implementation checks to see of the search key starts with a digit first.
        /// If so, it looks in the Abbreviation field for a search key match in the hierarchical number
        /// (e.g. "8.3.3"; these would go in the first bucket).
        /// Otherwise it checks next for matches where the key corresponds to the beginning
        /// of the Name field (first bucket). Failing that, it checks for whole word (second bucket) or
        /// partial matches (third bucket) between the search key and the contents of a Semantic Domain's
        /// Name and ExampleWords fields.
        /// N.B. Strategy subclasses should take care not to add a domain to a bucket
        /// if it is already in a higher priority bucket.
        /// </summary>
        internal override void PutDomainInDesiredBucket(ICmSemanticDomain domain)
        {
            // Look in Name and Example Words for matches
            if (m_fnumeric)
            {
                SearchInAbbreviationForMatches(domain);
                return;
            }

            // Check to see if this domain is a first bucket match
            // Boolean param in StartsWith() ignores case
            // N.B.: WritingSystem check should be the same as what's displayed in the UI!
            if (domain.Name.BestAnalysisAlternative.Text.StartsWith(m_searchString, true, AppropriateCulture))
            {
                SearchResults.AddResultToBucketX(0, domain);
                return;
            }
            base.PutDomainInDesiredBucket(domain);
        }
Ejemplo n.º 16
0
        private ILexEntry MakeLexEntry(string cf, string defn, ICmSemanticDomain domain)
        {
            var servLoc = Cache.ServiceLocator;
            var le      = servLoc.GetInstance <ILexEntryFactory>().Create();

            var ws = Cache.DefaultVernWs;

            le.CitationForm.set_String(ws, Cache.TsStrFactory.MakeString(cf, ws));
            var ls = servLoc.GetInstance <ILexSenseFactory>().Create();

            le.SensesOS.Add(ls);
            ws = Cache.DefaultAnalWs;
            ls.Definition.set_String(ws, Cache.TsStrFactory.MakeString(defn, ws));
            ls.SemanticDomainsRC.Add(domain);
            var msa = servLoc.GetInstance <IMoStemMsaFactory>().Create();

            le.MorphoSyntaxAnalysesOC.Add(msa);
            ls.MorphoSyntaxAnalysisRA = msa;
            return(le);
        }
Ejemplo n.º 17
0
 private void ReadQuestionsFromXml(XmlReader xrdrSub, ICmSemanticDomain semdom)
 {
     try
     {
         if (xrdrSub.IsEmptyElement)
         {
             xrdrSub.Read();
         }
         else if (xrdrSub.ReadToDescendant("CmDomainQ"))
         {
             do
             {
                 ReadDomainQFromXml(xrdrSub.ReadSubtree(), semdom);
             } while (xrdrSub.ReadToNextSibling("CmDomainQ"));
         }
     }
     finally
     {
         xrdrSub.Close();
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Load data that looks like this, storing it for future processing.  (Some of the
 /// guids may be forward references.)
 /// &lt;RelatedDomains&gt;
 ///		&lt;Link guid="4BF411B7-2B5B-4673-B116-0E6C31FBD08A"/&gt;
 ///		&lt;Link guid="CBA6876C-5B48-42F4-AE0A-7FBE9BB971EF"/&gt;
 ///		&lt;Link guid="0CC62B4A-D5FF-4F45-83D1-E2B46E5D159A"/&gt;
 /// &lt;/RelatedDomains&gt;
 /// </summary>
 private void LoadRelatedDomainsFromXml(XmlReader xrdr, ICmSemanticDomain dom)
 {
     Debug.Assert(dom != null);
     if (xrdr.ReadToDescendant("Link"))
     {
         do
         {
             string sGuid = xrdr.GetAttribute("guid");
             if (!String.IsNullOrEmpty(sGuid))
             {
                 Guid        guidLink = new Guid(sGuid);
                 List <Guid> rgGuids;
                 if (!m_mapRelatedDomains.TryGetValue(dom.Guid, out rgGuids))
                 {
                     rgGuids = new List <Guid>();
                     m_mapRelatedDomains.Add(dom.Guid, rgGuids);
                 }
                 rgGuids.Add(guidLink);
             }
         } while (xrdr.ReadToNextSibling("Link"));
     }
     xrdr.Read();                // reads end element
 }
Ejemplo n.º 19
0
        private void CacheWord(int ws, string word, ICmSemanticDomain domain)
        {
            var searchKey = new Tuple <string, int>(word, ws);
            HashSet <ICmSemanticDomain> cachedValues;            // out var

            if (m_semDomCache.TryGetValue(searchKey, out cachedValues))
            {
                if (cachedValues.Contains(domain))
                {
                    return;                     // this domain is already cached
                }
                // searchKey is already cached, but we need to add this domain
                cachedValues.Add(domain);
                m_semDomCache.Remove(searchKey);
                m_semDomCache.Add(searchKey, cachedValues);
                return;
            }

            // searchKey was not found, add it with this domain
            m_semDomCache.Add(searchKey, new HashSet <ICmSemanticDomain>()
            {
                domain
            });
        }
		/// <summary>
		/// This implementation checks to see of the search key starts with a digit first.
		/// If so, it looks in the Abbreviation field for a search key match in the hierarchical number
		/// (e.g. "8.3.3"; these would go in the first bucket).
		/// Otherwise it checks next for matches where the key corresponds to the beginning
		/// of the Name field (first bucket). Failing that, it checks for whole word (second bucket) or
		/// partial matches (third bucket) between the search key and the contents of a Semantic Domain's
		/// Name and ExampleWords fields.
		/// N.B. Strategy subclasses should take care not to add a domain to a bucket
		/// if it is already in a higher priority bucket.
		/// </summary>
		internal override void PutDomainInDesiredBucket(ICmSemanticDomain domain)
		{
			// Look in Name and Example Words for matches
			if (m_fnumeric)
			{
				SearchInAbbreviationForMatches(domain);
				return;
			}

			// Check to see if this domain is an exact match
			// Boolean param in Compare() ignores case
			// N.B.: WritingSystem check should be the same as what's displayed in the UI!
			if (String.Compare(domain.Name.BestAnalysisAlternative.Text, m_searchString, true, AppropriateCulture) == 0)
			{
				SearchResults.AddResultToBucketX(0, domain);
				return;
			}

			base.PutDomainInDesiredBucket(domain);
		}
Ejemplo n.º 21
0
		/// <summary>
		/// Load data that looks like this, storing it for future processing.  (Some of the
		/// guids may be forward references.)
		/// &lt;RelatedDomains&gt;
		///		&lt;Link guid="4BF411B7-2B5B-4673-B116-0E6C31FBD08A"/&gt;
		///		&lt;Link guid="CBA6876C-5B48-42F4-AE0A-7FBE9BB971EF"/&gt;
		///		&lt;Link guid="0CC62B4A-D5FF-4F45-83D1-E2B46E5D159A"/&gt;
		/// &lt;/RelatedDomains&gt;
		/// </summary>
		private void LoadRelatedDomainsFromXml(XmlReader xrdr, ICmSemanticDomain dom)
		{
			Debug.Assert(dom != null);
			if (xrdr.ReadToDescendant("Link"))
			{
				do
				{
					string sGuid = xrdr.GetAttribute("guid");
					if (!String.IsNullOrEmpty(sGuid))
					{
						Guid guidLink = new Guid(sGuid);
						List<Guid> rgGuids;
						if (!m_mapRelatedDomains.TryGetValue(dom.Guid, out rgGuids))
						{
							rgGuids = new List<Guid>();
							m_mapRelatedDomains.Add(dom.Guid, rgGuids);
						}
						rgGuids.Add(guidLink);
					}
				} while (xrdr.ReadToNextSibling("Link"));
			}
			xrdr.Read();	// reads end element
		}
Ejemplo n.º 22
0
		/// <summary>
		/// Load data that looks like this
		/// &lt;Questions&gt;
		///	&lt;CmDomainQ&gt;
		///		&lt;Question&gt;
		///			&lt;AUni ws="en"&gt;(1) What words refer to the sun?&lt;/AUni&gt;
		///			&lt;AUni ws="fr"&gt;Quels sont les mots pour parler du soleil?&lt;/AUni&gt;
		///		&lt;/Question&gt;
		///		&lt;ExampleWords&gt;
		///			&lt;AUni ws="en"&gt;sun, solar, sol, daystar, our star&lt;/AUni&gt;
		///			&lt;AUni ws="fr"&gt;soleil, solaire, notre soleil&lt;/AUni&gt;
		///		&lt;/ExampleWords&gt;
		///	&lt;/CmDomainQ&gt;
		///	&lt;CmDomainQ&gt;
		///		&lt;Question&gt;
		///			&lt;AUni ws="en"&gt;(2) What words refer to the time when the sun rises?&lt;/AUni&gt;
		///			&lt;AUni ws="fr"&gt;Quels sont les mots qui signifient le lever du soleil?&lt;/AUni&gt;
		///		&lt;/Question&gt;
		///		&lt;ExampleWords&gt;
		///			&lt;AUni ws="en"&gt;dawn, sunrise, sunup, daybreak, cockcrow, &lt;/AUni&gt;
		///		&lt;/ExampleWords&gt;
		///		&lt;ExampleSentences&gt;
		///			&lt;AStr ws="en"&gt;
		///				&lt;Run ws="en"&gt;We got up before “dawn”, in order to get an early start.&lt;/Run&gt;
		///			&lt;/AStr&gt;
		///		&lt;/ExampleSentences&gt;
		///	&lt;/CmDomainQ&gt;
		///&lt;/Questions&gt;
		/// </summary>
		private void LoadQuestionsFromXml(XmlReader xrdr, ICmSemanticDomain dom)
		{
			Debug.Assert(dom != null);
			if (xrdr.ReadToDescendant("CmDomainQ"))
			{
				EnsureFactoryForClass("CmDomainQ");
				do
				{
					ReadDomainQuestion(xrdr.ReadSubtree(), dom);
				} while (xrdr.ReadToNextSibling("CmDomainQ"));
			}
			xrdr.Read();	// reads end element
		}
Ejemplo n.º 23
0
 /// <summary>
 /// Get the text from a Semantic Domain's Name field.
 /// This version uses BestAnalysisAlternative which should always have a value,
 /// but a subclass might use a more specific writing system which may not have a value
 /// (i.e. be prepared for a null return value).
 /// </summary>
 /// <param name="domain"></param>
 /// <returns></returns>
 protected virtual string GetDomainNameString(ICmSemanticDomain domain)
 {
     return(domain.Name.BestAnalysisAlternative.Text);
 }
Ejemplo n.º 24
0
		/// <summary>
		/// Subclasses can override this method to change how Semantic Domains are compared
		/// with any search key(s) and the priority types of matches for putting the
		/// domain into an appropriate search results bucket (if any).
		/// N.B. Strategy subclasses should take care not to add a domain to a bucket
		/// if it is already in a higher priority bucket.
		/// </summary>
		/// <param name="domain"></param>
		internal virtual void PutDomainInDesiredBucket(ICmSemanticDomain domain)
		{
			// Check for whole word and partial matches in Name first
			if (!CollectPossibleMatchIn(GetDomainNameString(domain), domain, WholeWordBucketIndex))
			{
				// If no whole word match in Name, look in Example Words too.
				CollectPossibleMatchIn(GetExampleWordsString(domain.QuestionsOS), domain, WholeWordExamplesBucketIndex);
			}
		}
Ejemplo n.º 25
0
		/// <summary>
		/// Get the text from a Semantic Domain's Name field.
		/// This version uses BestAnalysisAlternative which should always have a value,
		/// but a subclass might use a more specific writing system which may not have a value
		/// (i.e. be prepared for a null return value).
		/// </summary>
		/// <param name="domain"></param>
		/// <returns></returns>
		protected virtual string GetDomainNameString(ICmSemanticDomain domain)
		{
			return domain.Name.BestAnalysisAlternative.Text;
		}
Ejemplo n.º 26
0
		private ILexEntry MakeLexEntry(string cf, string defn, ICmSemanticDomain domain)
		{
			var servLoc = Cache.ServiceLocator;
			var le = servLoc.GetInstance<ILexEntryFactory>().Create();

			var ws = Cache.DefaultVernWs;
			le.CitationForm.set_String(ws, Cache.TsStrFactory.MakeString(cf, ws));
			var ls = servLoc.GetInstance<ILexSenseFactory>().Create();
			le.SensesOS.Add(ls);
			ws = Cache.DefaultAnalWs;
			ls.Definition.set_String(ws, Cache.TsStrFactory.MakeString(defn, ws));
			ls.SemanticDomainsRC.Add(domain);
			var msa = servLoc.GetInstance<IMoStemMsaFactory>().Create();
			le.MorphoSyntaxAnalysesOC.Add(msa);
			ls.MorphoSyntaxAnalysisRA = msa;
			return le;
		}
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            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_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses",
                                                                            false);

            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[] { 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, false);
                m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal },
                                                   new[] { m_bluer, m_skyReal },
                                                   LexEntryRefTags.krtComplexForm);

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

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

                m_hotArm           = MakeEntry("hotarm", "pitcher", false, false);
                m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm },
                                                  new[] { 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, false);
                m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot },
                                                     new[] { m_hot },
                                                     LexEntryRefTags.krtVariant);
                m_nolanryanComponents.VariantEntryTypesRS.Add(
                    (ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]);
                m_nolanryan.DoNotPublishInRC.Add(m_mainDict);

                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);
            });
        }
Ejemplo n.º 28
0
            private void ExportSemanticDomainFields(TextWriter w, TextWriterStream stream,
				ICmSemanticDomain item)
            {
                if (item != null && item.QuestionsOS.Count > 0)
                {
                    w.WriteLine("<Questions>");
                    foreach (var domainQ in item.QuestionsOS)
                    {
                        w.WriteLine("<CmDomainQ>");
                        ExportMultiUnicode(w, domainQ.Question);
                        ExportMultiUnicode(w, domainQ.ExampleWords);
                        ExportMultiString(w, stream, domainQ.ExampleSentences);
                        w.WriteLine("</CmDomainQ>");
                    }
                    w.WriteLine("</Questions>");
                }
            }
Ejemplo n.º 29
0
		internal override void PutDomainInDesiredBucket(ICmSemanticDomain domain)
		{
			foreach (var kvp in m_searchKeys)
			{
				CurrentWs = kvp.Key;
				CurrentSearchKeys = kvp.Value;
				base.PutDomainInDesiredBucket(domain);
			}
		}
Ejemplo n.º 30
0
		/// <summary>
		/// Get the text from a Semantic Domain's Name field.
		/// This version uses AnalysisDefault ws which may not always have a value
		/// (i.e. be prepared for a null return value).
		/// </summary>
		/// <param name="domain"></param>
		/// <returns></returns>
		protected override string GetDomainNameString(ICmSemanticDomain domain)
		{
			return domain.Name.get_String(CurrentWs).Text;
		}
		public override void FixtureSetup()
		{
			base.FixtureSetup();
			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_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses",
				false);

			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[] { 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, false);
						m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal },
							new[] { m_bluer, m_skyReal },
							LexEntryRefTags.krtComplexForm);

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

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

						m_hotArm = MakeEntry("hotarm", "pitcher", false, false);
						m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm },
												new[] { 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, false);
						m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot },
												new[] { 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_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);
					});
		}
Ejemplo n.º 32
0
			/// <summary>
			/// The buckets are ordered in priority so adding a result to one bucket
			/// should remove that result from all lower (higher index) ones.
			/// N.B. Strategy subclasses should take care not to add a domain to a bucket
			/// if it is already in a higher priority bucket.
			/// </summary>
			/// <param name="bucketIndex"></param>
			/// <param name="domain"></param>
			public void AddResultToBucketX(int bucketIndex, ICmSemanticDomain domain)
			{
				m_bucketList[bucketIndex].Add(domain);
				for (var i = bucketIndex + 1; i < m_bucketList.Length; i++)
				{
					m_bucketList[i].Remove(domain);
				}
			}
Ejemplo n.º 33
0
		private ILexSense AddLexSense(ILexEntry le, string defn, ICmSemanticDomain domain, IMoMorphSynAnalysis msa)
		{
			var servLoc = Cache.ServiceLocator;
			var ws = Cache.DefaultAnalWs;
			var ls = servLoc.GetInstance<ILexSenseFactory>().Create();
			le.SensesOS.Add(ls);
			ls.Definition.set_String(ws, Cache.TsStrFactory.MakeString(defn, ws));
			if (domain != null)
				ls.SemanticDomainsRC.Add(domain);
			var msaToAdd = msa ?? servLoc.GetInstance<IMoStemMsaFactory>().Create();
			le.MorphoSyntaxAnalysesOC.Add(msaToAdd);
			ls.MorphoSyntaxAnalysisRA = msaToAdd;
			return ls;
		}
Ejemplo n.º 34
0
		private void ReadQuestionsFromXml(XmlReader xrdrSub, ICmSemanticDomain semdom)
		{
			try
			{
				if (xrdrSub.IsEmptyElement)
				{
					xrdrSub.Read();
				}
				else if (xrdrSub.ReadToDescendant("CmDomainQ"))
				{
					do
					{
						ReadDomainQFromXml(xrdrSub.ReadSubtree(), semdom);
					} while (xrdrSub.ReadToNextSibling("CmDomainQ"));
				}
			}
			finally
			{
				xrdrSub.Close();
			}
		}
Ejemplo n.º 35
0
		/// <summary>
		/// Take a string to look in (from a domain's Name or ExampleWords) and try to find
		/// a match for some (strategy-defined) search key(s).
		/// </summary>
		/// <param name="searchIn"></param>
		/// <param name="domain"></param>
		/// <param name="wholeWordBucket"></param>
		/// <returns></returns>
		protected bool CollectPossibleMatchIn(string searchIn, ICmSemanticDomain domain, int wholeWordBucket)
		{
			if (string.IsNullOrEmpty(searchIn))
				return false;
			var wordsToLookIn = ParseStringIntoWords(searchIn);
			switch (DoesInputMatchWord(wordsToLookIn))
			{
				case MatchingResult.WholeWordMatch:
					SearchResults.AddResultToBucketX(wholeWordBucket, domain);
					return true;
				case MatchingResult.StartOfWordMatch:
					SearchResults.AddResultToBucketX(wholeWordBucket + PartialMatchRelativeIndex, domain);
					return true;
				case MatchingResult.NoMatch:
					// do nothing
					break;
				default:
					throw new ApplicationException("Unknown MatchingResult");
			}
			return false;
		}
Ejemplo n.º 36
0
        private ILexEntry MakeLexEntry(string lf, string cf, string gloss, string defn, ICmSemanticDomain domain)
        {
            var le    = MakeLexEntry(cf, defn, domain);
            var morph = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create();

            le.LexemeFormOA = morph;
            morph.Form.set_String(Cache.DefaultVernWs, lf);
            le.SensesOS[0].Gloss.set_String(Cache.DefaultAnalWs, gloss);
            return(le);
        }
Ejemplo n.º 37
0
        public void RdeMerge()
        {
            if (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
            {
                ICmSemanticDomainFactory factSemDom = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>();
                while (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
                {
                    ICmSemanticDomain sem = factSemDom.Create();
                    Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(sem);
                }
            }
            IFdoOwningSequence <ICmPossibility> seqSemDom = Cache.LangProject.SemanticDomainListOA.PossibilitiesOS;
            ICmSemanticDomain semDom1 = seqSemDom[0] as ICmSemanticDomain;
            ICmSemanticDomain semDom2 = seqSemDom[1] as ICmSemanticDomain;
            ICmSemanticDomain semDom3 = seqSemDom[2] as ICmSemanticDomain;
            ICmSemanticDomain semDom4 = seqSemDom[4] as ICmSemanticDomain;

            // Create a LexEntry LE1 ("xyzTest1" defined as "xyzDefn1.1" in D1).
            // Attempt to merge it and verify that it survives.

            ILexEntry le1      = MakeLexEntry("xyzTest1", "xyzDefn1.1", semDom1);
            Set <int> newItems = new Set <int>();
            ILexSense sense1   = le1.SensesOS[0];

            newItems.Add(sense1.Hvo);
            // get an id for the 'list of senses' property (which isn't in the model)
            int fakeFlid = (int)CmObjectFields.kflidStartDummyFlids + 1;

            List <XmlNode> columns       = new List <XmlNode>();
            bool           fSenseDeleted = sense1.RDEMergeSense(semDom1.Hvo, columns, Cache, newItems);

            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 1: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.IsTrue(le1.SensesOS[0].SemanticDomainsRC.Contains(semDom1));

            // Attempt to merge them both.
            // Verify that LE3 survives.
            // Verify that old LE1 survives and now has two senses; new sense has xyzDefn1.2.
            // Verify that LE2 is deleted and LE3 survives.
            ILexEntry le2       = MakeLexEntry("xyzTest1", "xyzDefn1.2", semDom2);
            Set <int> newItems2 = new Set <int>();
            ILexSense sense2    = le2.SensesOS[0];

            newItems2.Add(sense2.Hvo);

            ILexEntry le3    = MakeLexEntry("xyzTest3", "xyzDefn3.1", semDom2);
            ILexSense sense3 = le3.SensesOS[0];

            newItems2.Add(sense3.Hvo);

            fSenseDeleted = sense2.RDEMergeSense(semDom2.Hvo, columns, Cache, newItems2);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 2: sense should not be deleted");
            fSenseDeleted = sense3.RDEMergeSense(semDom2.Hvo, columns, Cache, newItems2);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 3: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le3));
            Assert.IsFalse(IsRealLexEntry(le2), "entry should be deleted");
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.AreEqual(2, le1.SensesOS.Count, "sense added to entry by merge");
            Assert.AreEqual(1, le3.SensesOS.Count, "should still be one sense");
            Assert.AreEqual("xyzDefn1.2", le1.SensesOS[1].Definition.AnalysisDefaultWritingSystem.Text);
            Assert.IsTrue(le1.SensesOS[1].SemanticDomainsRC.Contains(semDom2));
            Assert.IsTrue(le3.SensesOS[0].SemanticDomainsRC.Contains(semDom2));

            // Create two more entries LE4("xyzTest1/xyzDefn1.2/D3" and LE5 ("xyzTest1/xyzDefn1.3/D3").
            // Verify that the second sense of LE1 gains a domain;
            // It also gains exactly one new sense;
            // And LE4 and LE5 are both deleted.
            ILexEntry le4       = MakeLexEntry("xyzTest1", "xyzDefn1.2", semDom3);
            Set <int> newItems3 = new Set <int>();
            ILexSense sense4    = le4.SensesOS[0];

            newItems3.Add(sense4.Hvo);

            ILexEntry le5    = MakeLexEntry("xyzTest1", "xyzDefn1.3", semDom3);
            ILexSense sense5 = le5.SensesOS[0];

            newItems3.Add(sense5.Hvo);

            fSenseDeleted = sense4.RDEMergeSense(semDom3.Hvo, columns, Cache, newItems3);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 4: sense should be deleted");
            fSenseDeleted = sense5.RDEMergeSense(semDom3.Hvo, columns, Cache, newItems3);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 5: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le3));
            Assert.IsFalse(IsRealLexEntry(le4));
            Assert.IsFalse(IsRealLexEntry(le5));
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.AreEqual(3, le1.SensesOS.Count, "one sense added to entry by merge");
            Assert.AreEqual("xyzDefn1.3", le1.SensesOS[2].Definition.AnalysisDefaultWritingSystem.Text);
            Assert.IsTrue(le1.SensesOS[2].SemanticDomainsRC.Contains(semDom3));
            int[] sense2Domains = le1.SensesOS[1].SemanticDomainsRC.ToHvoArray();
            Assert.AreEqual(2, sense2Domains.Length, "got 2 semantic domains on sense 2");
            int minDom    = Math.Min(semDom2.Hvo, semDom3.Hvo);           // smaller of expected domains.
            int maxDom    = Math.Max(semDom2.Hvo, semDom3.Hvo);
            int minActual = Math.Min(sense2Domains[0], sense2Domains[1]);
            int maxActual = Math.Max(sense2Domains[0], sense2Domains[1]);

            Assert.AreEqual(minDom, minActual, "expected domains on merged sense");
            Assert.AreEqual(maxDom, maxActual, "expected domains on merged sense");

            // Try adding four senses, three for the same CF, but which doesn't pre-exist.
            // Also, the three are exact duplicates.
            ILexEntry le6       = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            Set <int> newItems4 = new Set <int>();
            ILexSense sense6    = le6.SensesOS[0];

            newItems4.Add(sense6.Hvo);

            ILexEntry le7    = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            ILexSense sense7 = le7.SensesOS[0];

            newItems4.Add(sense7.Hvo);

            ILexEntry le8    = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            ILexSense sense8 = le8.SensesOS[0];

            newItems4.Add(sense8.Hvo);

            fSenseDeleted = sense6.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 6: sense should not be deleted");
            fSenseDeleted = sense7.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 7: sense should be deleted");
            fSenseDeleted = sense8.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 8: sense should be deleted");

            Assert.IsTrue(IsRealLexEntry(le6));
            Assert.IsFalse(IsRealLexEntry(le7));
            Assert.IsFalse(IsRealLexEntry(le8));
            Assert.AreEqual(1, le6.SensesOS.Count, "one sense survives merge");
        }
Ejemplo n.º 38
0
		/// <summary>
		/// Don't count references to Semantic Domains from other Semantic Domains.
		/// The user only cares about how many times in the lexicon the Semantic Domain is used.
		/// </summary>
		/// <param name="domain"></param>
		/// <returns></returns>
		public static int SenseReferenceCount(ICmSemanticDomain domain)
		{
			int count = 0;
			if (domain.ReferringObjects != null)
				count = (from item in domain.ReferringObjects
						 where item is ILexSense
						 select item).Count();
			return count;
		}
Ejemplo n.º 39
0
		private void ReadDomainQFromXml(XmlReader xrdrSub, ICmSemanticDomain semdom)
		{
			try
			{
				Dictionary<string, ICmDomainQ> mapQuest2Obj = new Dictionary<string, ICmDomainQ>();
				foreach (var dq in semdom.QuestionsOS)
				{
					ITsString tssQuest = dq.Question.get_String(m_wsEn);
					if (tssQuest == null)
						continue;
					string quest = tssQuest.Text;
					if (String.IsNullOrEmpty(quest))
						continue;
					if (!mapQuest2Obj.ContainsKey(quest))
						mapQuest2Obj.Add(quest, dq);
				}
				ICmDomainQ cdq = null;
				string wordsXml = null;
				string sentencesXml = null;
				while (xrdrSub.Read())
				{
					if (xrdrSub.NodeType == XmlNodeType.Element)
					{
						switch (xrdrSub.Name)
						{
							case "CmDomainQ":
								break;
							case "Question":
								cdq = FindQuestionAndSetIt(xrdrSub, mapQuest2Obj);
								if (!String.IsNullOrEmpty(wordsXml))
								{
									using (var srdr = new StringReader(wordsXml))
									{
										using (var xrdrWords = XmlReader.Create(srdr))
										{
									SetMultiUnicodeFromXml(xrdrWords, cdq.ExampleWords);
									xrdrWords.Close();
									wordsXml = null;
								}
									}
								}
								if (!String.IsNullOrEmpty(sentencesXml))
								{
									using (var srdr = new StringReader(sentencesXml))
									{
										using (var xrdrSentences = XmlReader.Create(srdr))
										{
									SetMultiStringFromXml(xrdrSentences, cdq.ExampleSentences);
									xrdrSentences.Close();
									wordsXml = null;
								}
									}
								}
								break;
							case "ExampleWords":
								if (cdq == null)
									wordsXml = GetXmlOfElement(xrdrSub);
								else
									SetMultiUnicodeFromXml(xrdrSub, cdq.ExampleWords);
								break;
							case "ExampleSentences":
								if (cdq == null)
									sentencesXml = GetXmlOfElement(xrdrSub);
								else
									SetMultiStringFromXml(xrdrSub, cdq.ExampleSentences);
								break;
							default:
								StoreOrReportUnexpectedElement(cdq, xrdrSub, "CmSemanticDomain/Questions/CmDomainQ");
								break;
						}
					}
				}
			}
			finally
			{
				xrdrSub.Close();
			}
		}
 /// <summary>
 /// Get the text from a Semantic Domain's Name field.
 /// This version uses AnalysisDefault ws which may not always have a value
 /// (i.e. be prepared for a null return value).
 /// </summary>
 /// <param name="domain"></param>
 /// <returns></returns>
 protected override string GetDomainNameString(ICmSemanticDomain domain)
 {
     return(domain.Name.get_String(CurrentWs).Text);
 }
Ejemplo n.º 41
0
        public void RdeMerge_ExtraFields()
        {
            ICmSemanticDomainFactory factSemDom = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>();
            ICmSemanticDomain        semDom1    = factSemDom.Create();

            Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(semDom1);
            ICmSemanticDomain semDom2 = factSemDom.Create();

            Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(semDom2);
            ICmSemanticDomain semDom3 = factSemDom.Create();

            Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(semDom3);
            List <XmlNode> columns = new List <XmlNode>();

            // Create a LexEntry LE1 (cf "red" gloss "rot" in D1, with bibliographic data).
            // Attempt to merge it and verify that it survives.

            ILexEntry red = MakeLexEntry("red", "", "rot", "", semDom1);

            // After creating similar entry in another domain with same info, should merge.
            var red2 = MakeLexEntry("red", "", "rot", "", semDom2);

            red2.Bibliography.set_String(Cache.DefaultAnalWs, "found in my dictionary");
            red2.SensesOS[0].SemanticsNote.set_String(Cache.DefaultVernWs, "color of a stop light");
            red2.SensesOS[0].ScientificName = MakeAnalysisString("R=255,G=0,B=0");
            var ex1 = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>().Create();

            red2.SensesOS[0].ExamplesOS.Add(ex1);
            bool fSenseDeleted = RunMergeSense(columns, red2);

            Assert.IsTrue(fSenseDeleted, "Merging red/rot with matching lf/gloss should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red2), "Merging with red/rot with matching lf/gloss should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should add new semantic domain");
            Assert.That(red.Bibliography.AnalysisDefaultWritingSystem.Text, Is.EqualTo("found in my dictionary"), "merge should copy bibliography");
            Assert.That(red.SensesOS[0].SemanticsNote.VernacularDefaultWritingSystem.Text, Is.EqualTo("color of a stop light"), "merge should copy semantics note");
            Assert.That(red.SensesOS[0].ScientificName.Text, Is.EqualTo("R=255,G=0,B=0"), "merge should copy scientific name");
            Assert.That(red.SensesOS[0].ExamplesOS, Has.Member(ex1), "merge should move example");

            // Another similar entry should merge, adding to the bibliography.
            var red3 = MakeLexEntry("red", "", "rot", "", semDom3);

            red3.Bibliography.set_String(Cache.DefaultAnalWs, "learned at mother's knee");
            red3.SensesOS[0].SemanticsNote.set_String(Cache.DefaultVernWs, "color of danger");
            red3.SensesOS[0].ScientificName = MakeAnalysisString("C=0, M=100, Y=100, K=0");
            var ex2 = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>().Create();

            red3.SensesOS[0].ExamplesOS.Add(ex2);
            fSenseDeleted = RunMergeSense(columns, red3);
            Assert.IsTrue(fSenseDeleted,
                          "Merging red/rot with matching lf/gloss and new defn should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red3), "Merging with red/rot with matching lf/gloss and new defn should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom3), "Merging should add new semantic domain");
            Assert.That(red.Bibliography.AnalysisDefaultWritingSystem.Text, Is.EqualTo("found in my dictionary; learned at mother's knee"), "merge should append bibliography");
            Assert.That(red.SensesOS[0].SemanticsNote.VernacularDefaultWritingSystem.Text, Is.EqualTo("color of a stop light; color of danger"), "merge should append semantics note");
            Assert.That(red.SensesOS[0].ScientificName.Text, Is.EqualTo("R=255,G=0,B=0; C=0, M=100, Y=100, K=0"), "merge should append scientific name");
            Assert.That(red.SensesOS[0].ExamplesOS, Has.Member(ex1), "merge should leave original example");
            Assert.That(red.SensesOS[0].ExamplesOS, Has.Member(ex2), "merge should move second example");
        }
Ejemplo n.º 42
0
        private void ReadDomainQFromXml(XmlReader xrdrSub, ICmSemanticDomain semdom)
        {
            try
            {
                Dictionary <string, ICmDomainQ> mapQuest2Obj = new Dictionary <string, ICmDomainQ>();
                foreach (var dq in semdom.QuestionsOS)
                {
                    ITsString tssQuest = dq.Question.get_String(m_wsEn);
                    if (tssQuest == null)
                    {
                        continue;
                    }
                    string quest = tssQuest.Text;
                    if (String.IsNullOrEmpty(quest))
                    {
                        continue;
                    }
                    if (!mapQuest2Obj.ContainsKey(quest))
                    {
                        mapQuest2Obj.Add(quest, dq);
                    }
                }
                ICmDomainQ cdq          = null;
                string     wordsXml     = null;
                string     sentencesXml = null;
                while (xrdrSub.Read())
                {
                    if (xrdrSub.NodeType == XmlNodeType.Element)
                    {
                        switch (xrdrSub.Name)
                        {
                        case "CmDomainQ":
                            break;

                        case "Question":
                            cdq = FindQuestionAndSetIt(xrdrSub, mapQuest2Obj);
                            if (!String.IsNullOrEmpty(wordsXml))
                            {
                                using (var srdr = new StringReader(wordsXml))
                                {
                                    using (var xrdrWords = XmlReader.Create(srdr))
                                    {
                                        SetMultiUnicodeFromXml(xrdrWords, cdq.ExampleWords);
                                        xrdrWords.Close();
                                        wordsXml = null;
                                    }
                                }
                            }
                            if (!String.IsNullOrEmpty(sentencesXml))
                            {
                                using (var srdr = new StringReader(sentencesXml))
                                {
                                    using (var xrdrSentences = XmlReader.Create(srdr))
                                    {
                                        SetMultiStringFromXml(xrdrSentences, cdq.ExampleSentences);
                                        xrdrSentences.Close();
                                        wordsXml = null;
                                    }
                                }
                            }
                            break;

                        case "ExampleWords":
                            if (cdq == null)
                            {
                                wordsXml = GetXmlOfElement(xrdrSub);
                            }
                            else
                            {
                                SetMultiUnicodeFromXml(xrdrSub, cdq.ExampleWords);
                            }
                            break;

                        case "ExampleSentences":
                            if (cdq == null)
                            {
                                sentencesXml = GetXmlOfElement(xrdrSub);
                            }
                            else
                            {
                                SetMultiStringFromXml(xrdrSub, cdq.ExampleSentences);
                            }
                            break;

                        default:
                            StoreOrReportUnexpectedElement(cdq, xrdrSub, "CmSemanticDomain/Questions/CmDomainQ");
                            break;
                        }
                    }
                }
            }
            finally
            {
                xrdrSub.Close();
            }
        }
Ejemplo n.º 43
0
        public void RdeMerge_GlossAndCf()
        {
            if (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
            {
                ICmSemanticDomainFactory factSemDom = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>();
                while (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
                {
                    ICmSemanticDomain sem = factSemDom.Create();
                    Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(sem);
                }
            }
            IFdoOwningSequence <ICmPossibility> seqSemDom = Cache.LangProject.SemanticDomainListOA.PossibilitiesOS;
            ICmSemanticDomain semDom1 = seqSemDom[0] as ICmSemanticDomain;
            ICmSemanticDomain semDom2 = seqSemDom[1] as ICmSemanticDomain;
            ICmSemanticDomain semDom3 = seqSemDom[2] as ICmSemanticDomain;
            ICmSemanticDomain semDom4 = seqSemDom[4] as ICmSemanticDomain;

            // Create a LexEntry LE1 (cf "red" gloss "rot" in D1).
            // Attempt to merge it and verify that it survives.

            ILexEntry red      = MakeLexEntry("red", "", "rot", "", semDom1);
            Set <int> newItems = new Set <int>();
            ILexSense sense1   = red.SensesOS[0];

            newItems.Add(sense1.Hvo);
            List <XmlNode> columns       = new List <XmlNode>();
            bool           fSenseDeleted = RunMergeSense(columns, red);

            Assert.IsFalse(fSenseDeleted, "Merging red when there is no similar item should not delete sense");
            Assert.IsTrue(IsRealLexEntry(red), "Merging with no similar entry should not delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove semantic domain");

            // After creating similar entry in another domain with same info, should merge.
            var red2 = MakeLexEntry("red", "", "rot", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, red2);
            Assert.IsTrue(fSenseDeleted, "Merging red/rot with matching lf/gloss should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red2), "Merging with red/rot with matching lf/gloss should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should add new semantic domain");

            // Another similar entry should merge, adding definition.
            var red3 = MakeLexEntry("red", "", "rot", "rot2", semDom3);

            fSenseDeleted = RunMergeSense(columns, red3);
            Assert.IsTrue(fSenseDeleted, "Merging red/rot with matching lf/gloss and new defn should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red3), "Merging with red/rot with matching lf/gloss and new defn should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom3), "Merging should add new semantic domain");
            Assert.That(red.SensesOS[0].Definition.AnalysisDefaultWritingSystem.Text, Is.EqualTo("rot2"));

            // Similarly we should be able to start with a matching definition, and add a gloss.
            var blue  = MakeLexEntry("blue", "", "", "blau", semDom1);
            var blue2 = MakeLexEntry("blue", "", "blauG", "blau", semDom2);

            fSenseDeleted = RunMergeSense(columns, blue2);
            Assert.IsTrue(fSenseDeleted, "Merging blue/blau with matching lf/defn and new gloss should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(blue2), "Merging blue/blau with matching lf/defn and new gloss should delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should add new semantic domain");
            Assert.That(blue.SensesOS[0].Gloss.AnalysisDefaultWritingSystem.Text, Is.EqualTo("blauG"));

            // Conflicts in another writing system should prevent merging
            var blue3 = MakeLexEntry("blue", "", "blauG", "blau", semDom3);
            var wsEs  = Cache.WritingSystemFactory.GetWsFromStr("es");

            blue.SensesOS[0].Gloss.set_String(wsEs, "blueS");
            blue3.SensesOS[0].Gloss.set_String(wsEs, "blueS3");
            fSenseDeleted = RunMergeSense(columns, blue3);
            Assert.IsFalse(fSenseDeleted, "Merging blue/blau with matching lf/defn/gloss but different gloss in spanish should not delete sense");
            Assert.IsFalse(IsRealLexEntry(blue3), "Merging blue/blau with matching lf/defn/gloss but different gloss in spanish should delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[1].SemanticDomainsRC.Contains(semDom3), "Merging should not remove old semantic domain");

            // A conflicting lex entry, even though a homograph in the current relevant writing system, should prevent merging,
            // even though the sense data all matches
            blue.CitationForm.set_String(Cache.DefaultVernWs, "blueCf");
            var blue4 = MakeLexEntry("blueForm2", "blueCf", "blauG", "blau", semDom4);

            fSenseDeleted = RunMergeSense(columns, blue4);
            Assert.IsFalse(fSenseDeleted, "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete sense");
            Assert.IsTrue(IsRealLexEntry(blue4), "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue4.SensesOS[0].SemanticDomainsRC.Contains(semDom4), "Merging should not remove old semantic domain");

            // This case demonstrates that we can merge when the existing entry has no lexeme form, filling in the one we have.
            // We can also fill in other WS alternatives.
            var green  = MakeLexEntry("", "greenF", "grun", "color grun", semDom1);
            var green2 = MakeLexEntry("green", "greenF", "grun", "color grun", semDom2);

            green2.CitationForm.set_String(wsEs, "grunCfS");
            green2.LexemeFormOA.Form.set_String(wsEs, "grunS");
            fSenseDeleted = RunMergeSense(columns, green2);
            Assert.IsTrue(fSenseDeleted, "Merging green/grun with matching cf/defn/gloss and one missing LF should delete sense");
            Assert.IsFalse(IsRealLexEntry(green2), "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete entry");
            Assert.IsTrue(green.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(green.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.That(green.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text, Is.EqualTo("green"), "merge should fill in missing LF");
            Assert.That(green.LexemeFormOA.Form.get_String(wsEs).Text, Is.EqualTo("grunS"), "merge should fill in missing spanish LF");
            Assert.That(green.CitationForm.get_String(wsEs).Text, Is.EqualTo("grunCfS"), "merge should fill in missing spanish CF");

            // We should not merge when NO non-empty string matches.
            var brown  = MakeLexEntry("brown", "", "braun", "", semDom1);
            var brown2 = MakeLexEntry("brown", "", "", "braun color", semDom2);

            fSenseDeleted = RunMergeSense(columns, brown2);
            Assert.IsFalse(fSenseDeleted, "Merging two forms of brown with no overlap between gloss and defn should not delete sense");

            // But as a special case we can merge if definition of one matches gloss of other.
            var brown3 = MakeLexEntry("brown", "", "", "braun", semDom2);

            fSenseDeleted = RunMergeSense(columns, brown3);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of brown with no gloss of one equal to defn of other should delete sense");
            Assert.IsTrue(brown.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should combine semantic domains");
            Assert.That(brown.SensesOS[0].Definition.AnalysisDefaultWritingSystem.Text, Is.EqualTo("braun"), "Merging should copy definition");

            // We want to match entries that have the same LexemeForm even if they are not homographs.
            // This is possible if one of them has an empty CF in the homograph writing system.
            var orange  = MakeLexEntry("orange", "orangeCf", "orang", "", semDom1);
            var orange2 = MakeLexEntry("orange", "", "orang", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, orange2);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of orange with matching LF and new blank Cf should delete sense");

            var pink  = MakeLexEntry("pink", "", "rose", "", semDom1);
            var pink2 = MakeLexEntry("pink", "pinkCf", "rose", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, pink2);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of pink with matching LF and old blank Cf should delete sense");
            Assert.That(pink.CitationForm.VernacularDefaultWritingSystem.Text, Is.EqualTo("pinkCf"), "merge should fill in missing CF");

            // An inexact match that moves a sense should still fill in missing info on the chosen entry.
            var yellow  = MakeLexEntry("yellow", "", "flower", "", semDom1);
            var yellow2 = MakeLexEntry("yellow", "yellowCf", "floral", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, yellow2);
            Assert.IsFalse(fSenseDeleted, "Merging two forms of yellow with matching LF and old blank Cf should delete sense");
            Assert.That(yellow.CitationForm.VernacularDefaultWritingSystem.Text, Is.EqualTo("yellowCf"), "merge should fill in missing CF");
        }
Ejemplo n.º 44
0
		private void CacheDomain(ICmSemanticDomain domain)
		{
			// Check for whole word matches in Name and ExampleWords
			CacheWordsIn(GetDomainNameString(domain), domain);
			CacheWordsIn(GetExampleWordsString(domain.QuestionsOS), domain);
		}
Ejemplo n.º 45
0
		private void ReadDomainQuestion(XmlReader xrdrSub, ICmSemanticDomain dom)
		{
			try
			{
				ICmDomainQ domQ = null;
				while (xrdrSub.Read())
				{
					if (xrdrSub.NodeType == XmlNodeType.Element)
					{
						switch (xrdrSub.Name)
						{
							case "ExampleSentences":
								if (domQ == null)
								{
									domQ = m_factCmDomainQ.Create();
									dom.QuestionsOS.Add(domQ);
								}
								SetMultiStringFromXml(xrdrSub, domQ.ExampleSentences);
								break;
							case "ExampleWords":
								if (domQ == null)
								{
									domQ = m_factCmDomainQ.Create();
									dom.QuestionsOS.Add(domQ);
								}
								SetMultiUnicodeFromXml(xrdrSub, domQ.ExampleWords);
								break;
							case "Question":
								if (domQ == null)
								{
									domQ = m_factCmDomainQ.Create();
									dom.QuestionsOS.Add(domQ);
								}
								SetMultiUnicodeFromXml(xrdrSub, domQ.Question);
								break;
						}
					}
				}
			}
			finally
			{
				xrdrSub.Close();
			}
		}
Ejemplo n.º 46
0
		private ILexEntry MakeLexEntry(string lf, string cf, string gloss, string defn, ICmSemanticDomain domain)
		{
			var le = MakeLexEntry(cf, defn, domain);
			var morph = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create();
			le.LexemeFormOA = morph;
			morph.Form.set_String(Cache.DefaultVernWs, lf);
			le.SensesOS[0].Gloss.set_String(Cache.DefaultAnalWs, gloss);
			return le;
		}
Ejemplo n.º 47
0
 private void CacheDomain(ICmSemanticDomain domain)
 {
     // Check for whole word matches in Name and ExampleWords
     CacheWordsIn(GetDomainNameString(domain), domain);
     CacheWordsIn(GetExampleWordsString(domain.QuestionsOS), domain);
 }
		private void SearchInAbbreviationForMatches(ICmSemanticDomain domain)
		{
			if (domain.Abbreviation.BestAnalysisAlternative.Text.StartsWith(m_searchString))
				SearchResults.AddResultToBucketX(0, domain);
		}
Ejemplo n.º 49
0
		/// <summary>
		/// Get the text from a Semantic Domain's Name field.
		/// </summary>
		/// <param name="domain"></param>
		/// <returns>an array of Tuples, where each Tuple has a ws handle and a name string</returns>
		private static Tuple<int, string>[] GetDomainNameString(ICmSemanticDomain domain)
		{
			var name = domain.Name;
			return name.AvailableWritingSystemIds.Select(ws => new Tuple<int, string>(
				ws, name.get_String(ws).Text)).Where(tuple => !String.IsNullOrEmpty(tuple.Item2)).ToArray();
		}
Ejemplo n.º 50
0
		ICmSemanticDomain ICmSemanticDomainFactory.Create(Guid guid, ICmSemanticDomain owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();
			int flid = m_cache.MetaDataCache.GetFieldId("CmPossibility", "SubPossibilities", false);

			var retval = new CmSemanticDomain(m_cache, hvo, guid);
			owner.SubPossibilitiesOS.Add(retval);
			return retval;
		}
Ejemplo n.º 51
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="cf"></param>
		/// <param name="defn"></param>
		/// <param name="domain">May be null.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private ILexEntry MakeLexEntry(string cf, string defn, ICmSemanticDomain domain)
		{
			var servLoc = Cache.ServiceLocator;
			var le = servLoc.GetInstance<ILexEntryFactory>().Create();

			var ws = Cache.DefaultVernWs;
			le.CitationForm.set_String(ws, Cache.TsStrFactory.MakeString(cf, ws));
			AddLexSense(le, defn, domain, null);
			return le;
		}
Ejemplo n.º 52
0
		private void AddSemanticDomainToSense(ILexSense understand, ICmSemanticDomain oilSemDom)
		{
			NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor,
				() => understand.SemanticDomainsRC.Add(oilSemDom));
		}