コード例 #1
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();
            }
        }
コード例 #2
0
        private ICmDomainQ FindQuestionAndSetIt(XmlReader xrdr,
                                                Dictionary <string, ICmDomainQ> mapQuest2Obj)
        {
            if (xrdr.IsEmptyElement)
            {
                xrdr.Read();
                return(null);
            }
            ICmDomainQ domq = null;

            if (xrdr.ReadToDescendant("AUni"))
            {
                Dictionary <int, string> mapWsValue = new Dictionary <int, string>();
                do
                {
                    string sWs  = xrdr.GetAttribute("ws");
                    string sVal = xrdr.ReadString();
                    if (sWs == "en")
                    {
                        // Use the English value to look up the CmDomainQ.
                        mapQuest2Obj.TryGetValue(sVal, out domq);
                        continue;                                       // don't overwrite the English string
                    }
                    int ws = GetWsFromStr(sWs);
                    mapWsValue.Add(ws, sVal);
                } while (xrdr.ReadToNextSibling("AUni"));
                if (domq != null)
                {
                    foreach (int ws in mapWsValue.Keys)
                    {
                        domq.Question.set_String(ws, mapWsValue[ws]);
                    }
                }
            }
            xrdr.Read();                // read the end tag.
            return(domq);
        }
コード例 #3
0
		/// <summary>
		/// For one Semantic Domain question, return the text of the Example Words field.
		/// </summary>
		/// <param name="questionObject"> </param>
		/// <returns>an array of Tuples, where each Tuple has a ws handle and a string of
		/// comma-deliminated (usually) words</returns>
		private static IEnumerable<Tuple<int, string>> GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
		{
			var wordsField = questionObject.ExampleWords;
			return wordsField.AvailableWritingSystemIds.Select(ws => new Tuple<int, string>(
				ws, wordsField.get_String(ws).Text)).Where(tuple => !String.IsNullOrEmpty(tuple.Item2)).ToArray();
		}
コード例 #4
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();
            }
        }
コード例 #5
0
 /// <summary>
 /// For one Semantic Domain question, return the text of the Example Words field.
 /// This baseclass version uses BestAnalysis, which always has a value, but a subclass
 /// might use a more specific writing system which could return a null value
 /// (i.e. be prepared to handle a null return value).
 /// </summary>
 /// <param name="questionObject"> </param>
 /// <returns>A string of comma-deliminated (usually) words</returns>
 protected virtual string GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
 {
     return(questionObject.ExampleWords.BestAnalysisAlternative.Text);
 }
コード例 #6
0
        /// <summary>
        /// For one Semantic Domain question, return the text of the Example Words field.
        /// </summary>
        /// <param name="questionObject"> </param>
        /// <returns>an array of Tuples, where each Tuple has a ws handle and a string of
        /// comma-deliminated (usually) words</returns>
        private static IEnumerable <Tuple <int, string> > GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
        {
            var wordsField = questionObject.ExampleWords;

            return(wordsField.AvailableWritingSystemIds.Select(ws => new Tuple <int, string>(
                                                                   ws, wordsField.get_String(ws).Text)).Where(tuple => !String.IsNullOrEmpty(tuple.Item2)).ToArray());
        }
コード例 #7
0
 /// <summary>
 /// For one Semantic Domain question, return the text of the Example Words field.
 /// This subclass version uses AnalysisDefault, which could have a null value
 /// (i.e. be prepared to handle a null return value).
 /// </summary>
 /// <param name="questionObject"> </param>
 /// <returns>A string of comma-deliminated (usually) words</returns>
 protected override string GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
 {
     return(questionObject.ExampleWords.get_String(CurrentWs).Text);
 }
コード例 #8
0
		/// <summary>
		/// For one Semantic Domain question, return the text of the Example Words field.
		/// This subclass version uses AnalysisDefault, which could have a null value
		/// (i.e. be prepared to handle a null return value).
		/// </summary>
		/// <param name="questionObject"> </param>
		/// <returns>A string of comma-deliminated (usually) words</returns>
		protected override string GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
		{
			return questionObject.ExampleWords.get_String(CurrentWs).Text;
		}
コード例 #9
0
		/// <summary>
		/// For one Semantic Domain question, return the text of the Example Words field.
		/// This baseclass version uses BestAnalysis, which always has a value, but a subclass
		/// might use a more specific writing system which could return a null value
		/// (i.e. be prepared to handle a null return value).
		/// </summary>
		/// <param name="questionObject"> </param>
		/// <returns>A string of comma-deliminated (usually) words</returns>
		protected virtual string GetExampleWordTextFromDomainQuestion(ICmDomainQ questionObject)
		{
			return questionObject.ExampleWords.BestAnalysisAlternative.Text;
		}