示例#1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds the specified annotations.
 /// </summary>
 /// <param name="annotations">The annotations.</param>
 /// ------------------------------------------------------------------------------------
 public void Add(FdoObjectSet <IScrScriptureNote> annotations)
 {
     foreach (IScrScriptureNote ann in annotations)
     {
         Annotations.Add(new XmlScrNote(ann, m_cache.DefaultAnalWs, m_lgwsf));
     }
 }
示例#2
0
        public void ValidatePhEnvironment_StringRepresentation()
        {
            CheckDisposed();

            ConstraintFailure failure           = null;
            FdoObjectSet <ICmBaseAnnotation> os = null;
            int           strRepFlid            = (int)PhEnvironment.PhEnvironmentTags.kflidStringRepresentation;
            PhEnvironment env = (PhEnvironment)m_fdoCache.LangProject.PhonologicalDataOA.EnvironmentsOS.Append(new PhEnvironment());

            os = CmBaseAnnotation.AnnotationsForObject(m_fdoCache, env.Hvo);
            Assert.AreEqual(0, os.Count, "Wrong starting count of annotations.");

            env.StringRepresentation.Text = @"/ [BADCLASS] _";
            Assert.IsFalse(env.CheckConstraints(strRepFlid, out failure));
            Assert.IsNotNull(failure, "Didn't get an object back from the CheckConstraints method.");
            //Assert.IsTrue(obj is CmBaseAnnotation, "Didn't get a CmBaseAnnotation back from the Validate call.");
            os = CmBaseAnnotation.AnnotationsForObject(m_fdoCache, env.Hvo);
            Assert.AreEqual(1, os.Count, "Wrong invalid count of annotations.");

            env.StringRepresentation.Text = @"/ d _";
            Assert.IsTrue(env.CheckConstraints(strRepFlid, out failure));
            Assert.IsNull(failure, "Got an object back from the CheckConstraints method.");
            os = CmBaseAnnotation.AnnotationsForObject(m_fdoCache, env.Hvo);
            Assert.AreEqual(0, os.Count, "Wrong valid count of annotations.");
        }
示例#3
0
        public void AssignObjects(LangProject lp)
        {
            //assign an atomic reference attribute
            FdoObjectSet os = (FdoObjectSet)lp.ResearchNotebookOA.RecordsOC.GetEnumerator();

            os.MoveNext();
            RnGenericRec record = (RnGenericRec)os.Current;

            record.ConfidenceRA = (CmPossibility)lp.ConfidenceLevelsOA.PossibilitiesOS[0];
        }
示例#4
0
        public void ObjectSetThatIsEmpty()
        {
            CheckDisposed();

            FdoObjectSet <ICmObject> os = GetEmptySet();

            Assert.AreEqual(0, os.Count);
            IEnumerator <ICmObject> v = os.GetEnumerator();

            v.Reset();                  // Should throw an exception for the generic enumerator.
        }
示例#5
0
        public void GetFirstItemOfObjectSet()
        {
            CheckDisposed();

            //test an empty set
            Assert.IsNull(GetEmptySet().FirstItem);

            //test a non-empty set
            FdoObjectSet <ICmPossibility> objects = this.GetNonEmptySet();

            Assert.IsNotNull(objects.FirstItem);            //Enhance: just a smoke test
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hvos"></param>
        /// <param name="v"></param>
        protected void AssertMatchingCountAndOrder(int[] hvos, FdoObjectSet <ICmObject> v)
        {
            Assert.AreEqual(hvos.Length, v.Count, "Count was not preserved.");

            int i = 0;

            foreach (ICmObject o in v)
            {
                Assert.AreEqual(hvos[i], o.Hvo, "Order was not preserved.");
                i++;
            }
        }
示例#7
0
        public void JustLoadAllOfType()
        {
            CheckDisposed();

            //select all of the objects which of type CmPossibility or subclasses
            string sqlQuery = "select ID, Class$ from CmPossibility_ order by Class$";
            FdoObjectSet <ICmPossibility> v1 = new FdoObjectSet <ICmPossibility>(m_fdoCache, sqlQuery, false, // No ord column
                                                                                 false);                      // that where clause specify each individual object's hvo
            FdoObjectSet <ICmPossibility> v2 = new FdoObjectSet <ICmPossibility>(m_fdoCache, sqlQuery, false, // No ord column
                                                                                 true);                       //just load all of this type (leave out the where clause)

            Assert.IsTrue(v1.Count == v2.Count);
        }
示例#8
0
		public void ArbitraryEnumerator()
		{
			CheckDisposed();

			//select all of the objects which of type CmPossibility or subclasses
			string sqlQuery = "select ID, Class$ from CmPossibility_ order by Class$";
			FdoObjectSet<ICmPossibility> v = new FdoObjectSet<ICmPossibility>(m_fdoCache, sqlQuery, false);	// No ord column

			//select all of the objects which are not of type CmPossibility, but rather subclasses
			sqlQuery = "select ID, class$ from CmPossibility_ where class$ != 7 order by Class$";
			v = new FdoObjectSet<ICmPossibility>(m_fdoCache, sqlQuery, false);	// no ord column

			//now test an ordered set of objects
			int hvo = m_fdoCache.LangProject.AnthroListOA.Hvo;
			//construct the query so that everything is ordered backwards, for testing.
			sqlQuery = string.Format("select ID, Class$, OwnOrd$ from CmPossibility_ " +
				"where owner$={0} order by Class$, ID desc", hvo);
			v = new FdoObjectSet<ICmPossibility>(m_fdoCache, sqlQuery, true);	// Has ord column, but not a real one.
		}
示例#9
0
        public void ArbitraryEnumerator()
        {
            CheckDisposed();

            //select all of the objects which of type CmPossibility or subclasses
            string sqlQuery = "select ID, Class$ from CmPossibility_ order by Class$";
            FdoObjectSet <ICmPossibility> v = new FdoObjectSet <ICmPossibility>(m_fdoCache, sqlQuery, false);           // No ord column

            //select all of the objects which are not of type CmPossibility, but rather subclasses
            sqlQuery = "select ID, class$ from CmPossibility_ where class$ != 7 order by Class$";
            v        = new FdoObjectSet <ICmPossibility>(m_fdoCache, sqlQuery, false);          // no ord column

            //now test an ordered set of objects
            int hvo = m_fdoCache.LangProject.AnthroListOA.Hvo;

            //construct the query so that everything is ordered backwards, for testing.
            sqlQuery = string.Format("select ID, Class$, OwnOrd$ from CmPossibility_ " +
                                     "where owner$={0} order by Class$, ID desc", hvo);
            v = new FdoObjectSet <ICmPossibility>(m_fdoCache, sqlQuery, true);                  // Has ord column, but not a real one.
        }
示例#10
0
        public void PreserveHvoCountAndOrder()
        {
            CheckDisposed();

            int[] hvos = GetHvosForFirstNObjectsOfClass(m_fdoCache.LangProject.PeopleOA.PossibilitiesOS.HvoArray, CmPerson.kClassId, 5);

            //mess with the order
            int h = hvos[0];

            hvos[0] = hvos[3];
            hvos[3] = h;

            // duplicate that last one to check for preserving duplicates (which is necessary for reference sequence attrs)
            hvos[4] = h;

            FdoObjectSet <ICmObject> v = new FdoObjectSet <ICmObject>(m_fdoCache, hvos, true);

            AssertMatchingCountAndOrder(hvos, v);

            // test when we give the signature, too
            v = new FdoObjectSet <ICmObject>(m_fdoCache, hvos, true, typeof(CmPerson));
            AssertMatchingCountAndOrder(hvos, v);
        }
示例#11
0
		public void JustLoadAllOfType()
		{
			CheckDisposed();

			//select all of the objects which of type CmPossibility or subclasses
			string sqlQuery = "select ID, Class$ from CmPossibility_ order by Class$";
			FdoObjectSet<ICmPossibility> v1 = new FdoObjectSet<ICmPossibility>(m_fdoCache, sqlQuery, false, // No ord column
				false);// that where clause specify each individual object's hvo
			FdoObjectSet<ICmPossibility> v2 = new FdoObjectSet<ICmPossibility>(m_fdoCache, sqlQuery, false, // No ord column
				true);	//just load all of this type (leave out the where clause)
			Assert.IsTrue(v1.Count == v2.Count);
		}
示例#12
0
			/// <summary>
			/// </summary>
			/// <param name="cbaSegTargetHvo"></param>
			/// <param name="cbaSegSrcHvo"></param>
			/// <param name="segmentFFCommentsBeforeSegBreakEdit_begin"></param>
			/// <param name="segmentFFCommentsBeforeSegBreakEdit_end"></param>
			/// <param name="segmentFFsAfterMerge"></param>
			private void ValidateMergedFreeformAnnotations(int cbaSegTargetHvo, int cbaSegSrcHvo,
				List<int> segmentFFCommentsBeforeMerge_target,
				List<int> segmentFFCommentsBeforeMerge_src,
				FdoObjectSet<ICmIndirectAnnotation> segmentFFsAfterMerge)
			{
				int segDefn_note = Cache.GetIdFromGuid(LangProject.kguidAnnNote);
				Dictionary<int, List<ICmIndirectAnnotation>> typeToAnnBeforeMergeBegin =
					AnnotationAdjuster.MakeAnnTypeToAnnDictionary(Cache, segmentFFCommentsBeforeMerge_target);
				Dictionary<int, List<ICmIndirectAnnotation>> typeToAnnAfterMerge =
					AnnotationAdjuster.MakeAnnTypeToAnnDictionary(segmentFFsAfterMerge);
				List<ICmIndirectAnnotation> srcNotes = new List<ICmIndirectAnnotation>();
				foreach (int srcFreeformAnnHvo in segmentFFCommentsBeforeMerge_src)
				{
					ICmIndirectAnnotation srcFreeformAnn = new CmIndirectAnnotation(Cache, srcFreeformAnnHvo) as ICmIndirectAnnotation;
					ICmIndirectAnnotation realSrcFreeformAnn = new CmIndirectAnnotation(Cache, ffsClonedToReal[srcFreeformAnn.Hvo]);
					List<ICmIndirectAnnotation> targetAnns;
					List<ICmIndirectAnnotation> mergedAnns;
					Assert.IsTrue(typeToAnnAfterMerge.TryGetValue(srcFreeformAnn.AnnotationTypeRAHvo, out mergedAnns),
							"Expected src ff annotation to be in the merged set.");
					// see if we can find the annotation on the target segment matching the same type.
					// if so, we should have merged into its comment.
					if (srcFreeformAnn.AnnotationTypeRAHvo != segDefn_note &&
						typeToAnnBeforeMergeBegin.TryGetValue(srcFreeformAnn.AnnotationTypeRAHvo, out targetAnns))
					{
						Assert.IsFalse(realSrcFreeformAnn.IsRealObject, "Expected merged ff to have been deleted.");
						Assert.AreEqual(1, targetAnns.Count, "We only expect to have one annotation of this type.");
						int hvoTargetFF = targetAnns[0].Hvo;
						// see if we can find src comment in the same ws as the target.
						ICmIndirectAnnotation targetFreeformAnn = new CmIndirectAnnotation(Cache, hvoTargetFF) as ICmIndirectAnnotation;
						foreach (int wsTarget in Cache.LangProject.CurrentAnalysisAndVernWss)
						{
							// assume that the first ws-run indicates the ws of this multistring.
							ITsString tssTargetComment = targetFreeformAnn.Comment.GetAlternativeTss(wsTarget);
							ITsString tssSrcComment = srcFreeformAnn.Comment.GetAlternativeTss(wsTarget);
							string sTarget = "";
							string sSrc = "";
							if (tssTargetComment.Length > 0)
							{
								sTarget = tssTargetComment.Text + " ";
							}
							if (tssSrcComment.Length > 0)
							{
								sSrc = tssSrcComment.Text;
							}
							if (tssTargetComment.Text == null && tssSrcComment.Text == null)
							{
								Assert.AreEqual(null,
									typeToAnnAfterMerge[srcFreeformAnn.AnnotationTypeRAHvo][0].Comment.GetAlternativeTss(wsTarget).Text,
									"Expected annotation comments to be merged.");
							}
							else
							{
								Assert.AreEqual(sTarget + sSrc,
									typeToAnnAfterMerge[srcFreeformAnn.AnnotationTypeRAHvo][0].Comment.GetAlternativeTss(wsTarget).Text,
									"Expected annotation comments to be merged.");
							}
						}
					}
					else
					{
						Assert.IsTrue(mergedAnns.IndexOf(realSrcFreeformAnn) != -1);
						Assert.IsTrue(realSrcFreeformAnn.IsRealObject, "Expected merged ff to have been deleted.");
						if (srcFreeformAnn.AnnotationTypeRAHvo == segDefn_note)
						{
							srcNotes.Add(srcFreeformAnn);
							// find this Note in the merged list
						}
						foreach (int wsSrc in Cache.LangProject.CurrentAnalysisAndVernWss)
						{
							// assume that the first ws-run indicates the ws of this multistring.
							ITsString tssSrcComment = srcFreeformAnn.Comment.GetAlternativeTss(wsSrc);
							ITsString tssMovedComment = realSrcFreeformAnn.Comment.GetAlternativeTss(wsSrc);
							Assert.IsNotNull(tssMovedComment);
							Assert.AreEqual(tssSrcComment.Text, tssMovedComment.Text,
								"Expected annotation comments to be identical.");
						}
					}
				}
				// make sure all the merged ff annotations point to the target and none point to the old src segment
				// it's a note or not found on the target, just move the AppliesToRC item to the target.
				// make sure it's not pointing to the old segment.
				foreach (ICmIndirectAnnotation ciaMergedFF in segmentFFsAfterMerge)
				{
					Assert.IsFalse(ciaMergedFF.AppliesToRS.Contains(cbaSegSrcHvo),
						"Expected freeform annotation to no longer reference a merged annotation.");
					// make sure it's pointing to the new segment.
					Assert.IsTrue(ciaMergedFF.AppliesToRS.Contains(cbaSegTargetHvo),
						"Expected freeform annotation to reference target annotation.");
				}
				// make sure we have the expected number of notes.
				List<ICmIndirectAnnotation> mergedNotes;
				if (!typeToAnnAfterMerge.TryGetValue(segDefn_note, out mergedNotes))
					mergedNotes = new List<ICmIndirectAnnotation>();
				List<ICmIndirectAnnotation> targetNotes;
				if (!typeToAnnBeforeMergeBegin.TryGetValue(segDefn_note, out targetNotes))
					targetNotes = new List<ICmIndirectAnnotation>();
				Assert.AreEqual(targetNotes.Count + srcNotes.Count, mergedNotes.Count,
					"Expected the same number of freeform annotations.");
			}
示例#13
0
			private void ValidateMatchingFreeformAnnotations(FdoObjectSet<ICmIndirectAnnotation> segmentFFs_a,
			FdoObjectSet<ICmIndirectAnnotation> segmentFFs_b)
			{
				List<ICmIndirectAnnotation> segFFs_a = segmentFFs_a.ToList();
				Assert.AreEqual(segmentFFs_a.Count, segmentFFs_b.Count, "Expected segments to have matching number of indirect annotations.");
				foreach (ICmIndirectAnnotation ann_b in segmentFFs_b)
				{
					int index = segFFs_a.IndexOf(ann_b);
					Assert.IsTrue(index >= 0, "Expected segment to have matching hvos for indirect annotations");
					// make sure the content hasn't changed.
					foreach (int ws in ann_b.Cache.LangProject.AnalysisWssRC.HvoArray)
					{
						Assert.AreEqual(segFFs_a[index].Comment.GetAlternativeTss(ws),
							ann_b.Comment.GetAlternativeTss(ws),
							"Expected indirect annotations to have same comment content.");
					}
				}
			}
示例#14
0
			/// <summary>
			/// </summary>
			/// <param name="segmentFFs"></param>
			/// <returns></returns>
			internal List<int> CaptureFFComments(FdoObjectSet<ICmIndirectAnnotation> segmentFFs)
			{
				List<int> ffsClonedWithComments = new List<int>();
				foreach (CmIndirectAnnotation cia in segmentFFs)
				{
					int hvoCloned = cia.CloneIntoDummy();
					ffsClonedWithComments.Add(hvoCloned);
					ffsClonedToReal.Add(hvoCloned, cia.Hvo);
				}
				return ffsClonedWithComments;
			}
示例#15
0
		private static FdoObjectSet<ICmIndirectAnnotation> GetFreeformAnnotations(ICmBaseAnnotation cba)
		{
			List<int> freeformAnnHvos = new List<int>();
			foreach (LinkedObjectInfo loi in cba.LinkedObjects)
			{
				if (loi.RelObjClass == CmIndirectAnnotation.kClassId)
				{
					freeformAnnHvos.Add(loi.RelObjId);
				}
			}
			FdoObjectSet<ICmIndirectAnnotation> freeformAnns = new FdoObjectSet<ICmIndirectAnnotation>(cba.Cache,
																									   freeformAnnHvos.ToArray(), false, typeof(CmIndirectAnnotation));
			return freeformAnns;
		}
示例#16
0
		/// <summary>
		/// create a dictionary for indirect annotations, keyed by annotation type
		/// </summary>
		/// <param name="anns"></param>
		/// <returns></returns>
		public static Dictionary<int, List<ICmIndirectAnnotation>> MakeAnnTypeToAnnDictionary(FdoObjectSet<ICmIndirectAnnotation> anns)
		{
			Dictionary<int, List<ICmIndirectAnnotation>> targetTypeToAnn = new Dictionary<int, List<ICmIndirectAnnotation>>();
			foreach (ICmIndirectAnnotation targetFreeformAnn in anns)
			{
				List<ICmIndirectAnnotation> targetAnns;
				if (targetTypeToAnn.TryGetValue(targetFreeformAnn.AnnotationTypeRAHvo, out targetAnns))
				{
					targetAnns.Add(targetFreeformAnn);
				}
				else
				{
					targetTypeToAnn.Add(targetFreeformAnn.AnnotationTypeRAHvo,
										new List<ICmIndirectAnnotation>(new ICmIndirectAnnotation[] { targetFreeformAnn }));
				}
			}
			return targetTypeToAnn;
		}
示例#17
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // Get the checked twfics;
            List <int> twfics = m_rbv.CheckedItems;

            if (twfics == null || twfics.Count == 0)
            {
                // do nothing.
                return;
            }
            List <int> twficSegments  = StTxtPara.TwficSegments(m_cache, twfics);
            Set <int>  uniqueSegments = new Set <int>(twficSegments);
            FdoObjectSet <CmBaseAnnotation> cbaSegments = new FdoObjectSet <CmBaseAnnotation>(m_cache, uniqueSegments.ToArray(), true);
            int insertIndex = m_owningSense.ExamplesOS.Count;             // by default, insert at the end.
            int sourceIndex = -1;

            if (m_les != null)
            {
                // we were given a LexExampleSentence, so set our insertion index after the given one.
                List <int> examples = new List <int>(m_owningSense.ExamplesOS.HvoArray);
                sourceIndex = examples.IndexOf(m_les.Hvo);
                insertIndex = sourceIndex + 1;
            }

            // Load all the annotations for these twfics.
            int       tagSegFF     = StTxtPara.SegmentFreeformAnnotationsFlid(m_cache);
            Set <int> allAnalWsIds = new Set <int>(m_cache.LangProject.AnalysisWssRC.HvoArray);

            StTxtPara.LoadSegmentFreeformAnnotationData(m_cache, uniqueSegments, allAnalWsIds);

            bool fBoolModifiedExisting               = false;
            List <ILexExampleSentence> newExamples   = new List <ILexExampleSentence>();         // keep track of how many new objects we created.
            ILexExampleSentence        newLexExample = null;

            // delay prop changes until all the new examples are added.
            using (new IgnorePropChanged(m_cache, PropChangedHandling.SuppressView))
            {
                foreach (CmBaseAnnotation cbaSegment in cbaSegments)
                {
                    if (newExamples.Count == 0 && m_les != null && m_les.Example.BestVernacularAlternative.Text == "***" &&
                        (m_les.TranslationsOC == null || m_les.TranslationsOC.Count == 0) &&
                        m_les.Reference.Length == 0)
                    {
                        // we were given an empty LexExampleSentence, so use this one for our first new Example.
                        newLexExample         = m_les;
                        fBoolModifiedExisting = true;
                    }
                    else
                    {
                        // create a new example sentence.
                        newLexExample = m_owningSense.ExamplesOS.InsertAt(new LexExampleSentence(), insertIndex + newExamples.Count);
                        newExamples.Add(newLexExample);
                    }
                    // copy the segment string into the new LexExampleSentence
                    // Enhance: bold the relevant twfic(s).
                    newLexExample.Example.SetVernacularDefaultWritingSystem(StTxtPara.TssSubstring(cbaSegment).Text);

                    int segDefn_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
                    int segDefn_freeTranslation    = m_cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);

                    int hvoTransType_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidTranLiteralTranslation);
                    int hvoTransType_freeTranslation    = m_cache.GetIdFromGuid(LangProject.kguidTranFreeTranslation);

                    // copy the translation information
                    List <ICmTranslation> newTranslations = new List <ICmTranslation>();
                    foreach (int freeFormAnnotationId in m_cache.GetVectorProperty(cbaSegment.Hvo, tagSegFF, true))
                    {
                        int hvoAnnType = m_cache.MainCacheAccessor.get_ObjectProp(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType);

                        // map annotation type to translation type.
                        int hvoTranslationType = 0;
                        if (hvoAnnType == segDefn_literalTranslation)
                        {
                            hvoTranslationType = hvoTransType_literalTranslation;
                        }
                        else if (hvoAnnType == segDefn_freeTranslation)
                        {
                            hvoTranslationType = hvoTransType_freeTranslation;
                        }
                        else
                        {
                            continue;                             // skip unsupported translation type.
                        }

                        ICmTranslation newTranslation = newLexExample.TranslationsOC.Add(new CmTranslation());
                        newTranslations.Add(newTranslation);
                        newTranslation.TypeRAHvo = hvoTranslationType;
                        foreach (int analWs in allAnalWsIds)
                        {
                            ITsString tssComment = m_cache.GetMultiStringAlt(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidComment, analWs);
                            if (tssComment.Length > 0)
                            {
                                newTranslation.Translation.SetAlternative(tssComment, analWs);
                            }
                        }
                    }

                    // copy the reference.
                    // Enhance: get the ws from the 'Reference' column spec?
                    // Enhance: AnnotationRefHandler can also m_cache the reference directly to the segment.
                    int iTwfic = twficSegments.IndexOf(cbaSegment.Hvo);
                    newLexExample.Reference.UnderlyingTsString = m_cache.GetTsStringProperty(twfics[iTwfic], m_virtFlidReference);
                    // Need to correctly add Translations (or ghost if none).
                }
            }
            if (fBoolModifiedExisting)
            {
                m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
                                    (int)LexExampleSentence.LexExampleSentenceTags.kflidExample, 0, 1, 1);
                m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
                                    (int)LexExampleSentence.LexExampleSentenceTags.kflidReference, 0, 1, 1);
                //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
                //	(int)LexExampleSentence.LexExampleSentenceTags.kflidTranslations, 0, 1, 1);
                //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo,
                //	(int)LexSense.LexSenseTags.kflidExamples, sourceIndex, 1, 1);
            }
            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo,
                                (int)LexSense.LexSenseTags.kflidExamples, insertIndex, newExamples.Count, 0);
        }
示例#18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the specified annotations.
		/// </summary>
		/// <param name="annotations">The annotations.</param>
		/// ------------------------------------------------------------------------------------
		public void Add(FdoObjectSet<IScrScriptureNote> annotations)
		{
			foreach (IScrScriptureNote ann in annotations)
				Annotations.Add(new XmlScrNote(ann, m_cache.DefaultAnalWs, m_lgwsf));
		}
示例#19
0
		private void btnAdd_Click(object sender, EventArgs e)
		{
			// Get the checked twfics;
			List<int> twfics = m_rbv.CheckedItems;
			if (twfics == null || twfics.Count == 0)
			{
				// do nothing.
				return;
			}
			List<int> twficSegments = StTxtPara.TwficSegments(m_cache, twfics);
			Set<int> uniqueSegments = new Set<int>(twficSegments);
			FdoObjectSet<CmBaseAnnotation> cbaSegments = new FdoObjectSet<CmBaseAnnotation>(m_cache, uniqueSegments.ToArray(), true);
			int insertIndex = m_owningSense.ExamplesOS.Count; // by default, insert at the end.
			int sourceIndex = -1;
			if (m_les != null)
			{
				// we were given a LexExampleSentence, so set our insertion index after the given one.
				List<int> examples = new List<int>(m_owningSense.ExamplesOS.HvoArray);
				sourceIndex = examples.IndexOf(m_les.Hvo);
				insertIndex = sourceIndex + 1;
			}

			// Load all the annotations for these twfics.
			int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(m_cache);
			Set<int> allAnalWsIds = new Set<int>(m_cache.LangProject.AnalysisWssRC.HvoArray);
			StTxtPara.LoadSegmentFreeformAnnotationData(m_cache, uniqueSegments, allAnalWsIds);

			bool fBoolModifiedExisting = false;
			List<ILexExampleSentence> newExamples = new List<ILexExampleSentence>(); // keep track of how many new objects we created.
			ILexExampleSentence newLexExample = null;
			// delay prop changes until all the new examples are added.
			using (new IgnorePropChanged(m_cache, PropChangedHandling.SuppressView))
			{
				foreach (CmBaseAnnotation cbaSegment in cbaSegments)
				{
					if (newExamples.Count == 0 && m_les != null && m_les.Example.BestVernacularAlternative.Text == "***" &&
						(m_les.TranslationsOC == null || m_les.TranslationsOC.Count == 0) &&
						m_les.Reference.Length == 0)
					{
						// we were given an empty LexExampleSentence, so use this one for our first new Example.
						newLexExample = m_les;
						fBoolModifiedExisting = true;
					}
					else
					{
						// create a new example sentence.
						newLexExample = m_owningSense.ExamplesOS.InsertAt(new LexExampleSentence(), insertIndex + newExamples.Count);
						newExamples.Add(newLexExample);
					}
					// copy the segment string into the new LexExampleSentence
					// Enhance: bold the relevant twfic(s).
					newLexExample.Example.SetVernacularDefaultWritingSystem(StTxtPara.TssSubstring(cbaSegment).Text);

					int segDefn_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
					int segDefn_freeTranslation = m_cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);

					int hvoTransType_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidTranLiteralTranslation);
					int hvoTransType_freeTranslation = m_cache.GetIdFromGuid(LangProject.kguidTranFreeTranslation);

					// copy the translation information
					List<ICmTranslation> newTranslations = new List<ICmTranslation>();
					foreach (int freeFormAnnotationId in m_cache.GetVectorProperty(cbaSegment.Hvo, tagSegFF, true))
					{
						int hvoAnnType = m_cache.MainCacheAccessor.get_ObjectProp(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType);

						// map annotation type to translation type.
						int hvoTranslationType = 0;
						if (hvoAnnType == segDefn_literalTranslation)
						{
							hvoTranslationType = hvoTransType_literalTranslation;
						}
						else if (hvoAnnType == segDefn_freeTranslation)
						{
							hvoTranslationType = hvoTransType_freeTranslation;
						}
						else
						{
							continue; // skip unsupported translation type.
						}

						ICmTranslation newTranslation = newLexExample.TranslationsOC.Add(new CmTranslation());
						newTranslations.Add(newTranslation);
						newTranslation.TypeRAHvo = hvoTranslationType;
						foreach (int analWs in allAnalWsIds)
						{
							ITsString tssComment = m_cache.GetMultiStringAlt(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidComment, analWs);
							if (tssComment.Length > 0)
							{
								newTranslation.Translation.SetAlternative(tssComment, analWs);
							}
						}
					}

					// copy the reference.
					// Enhance: get the ws from the 'Reference' column spec?
					// Enhance: AnnotationRefHandler can also m_cache the reference directly to the segment.
					int iTwfic = twficSegments.IndexOf(cbaSegment.Hvo);
					newLexExample.Reference.UnderlyingTsString = m_cache.GetTsStringProperty(twfics[iTwfic], m_virtFlidReference);
					// Need to correctly add Translations (or ghost if none).
				}
			}
			if (fBoolModifiedExisting)
			{
				m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
					(int)LexExampleSentence.LexExampleSentenceTags.kflidExample, 0, 1, 1);
				m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
					(int)LexExampleSentence.LexExampleSentenceTags.kflidReference, 0, 1, 1);
				//m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo,
				//	(int)LexExampleSentence.LexExampleSentenceTags.kflidTranslations, 0, 1, 1);
				//m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo,
				//	(int)LexSense.LexSenseTags.kflidExamples, sourceIndex, 1, 1);
			}
			m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo,
				(int)LexSense.LexSenseTags.kflidExamples, insertIndex, newExamples.Count, 0);
		}
示例#20
0
		protected override FdoObjectSet<ICmObject> GetObjectSet()
		{
			BaseVirtualHandler handler = VirtualHandler;
			if (handler != null)
			{
				FdoObjectSet<ICmObject> fdoObjs = null;
				// Original code won't work for virtual property (or anything else that isn't owning), so do
				// this instead.
				// Force the handler to (re)load the property.
				Debug.WriteLine("GetObjectSet: " + handler.ClassName + ", " + handler.FieldName +
					"(" + handler.Tag.ToString() + ") owningObject.Hvo: " + m_owningObject.Hvo.ToString());
				// Assume we're reloading everything, so invalidate anything pending queue requests.
				// Enhance, we only need to invalidate our queue requests if a dummy item becomes invalid.
				m_requestedDummiesToConvertQueue.Clear();
				m_dummiesToConvertRequestsMap.Clear();
				m_dummyToRealDict.Clear();		// we'll be recreating our dummy list.
				using (ProgressState progress = FwXWindow.CreateMilestoneProgressState(m_mediator))
				{
					// give it a new ProgressBar.
					if (handler is BaseFDOPropertyVirtualHandler)
						(handler as BaseFDOPropertyVirtualHandler).Progress = progress;
					if (NeedToReloadVirtualProperty)
					{
						ForceReloadVirtualProperty(handler);
						NeedToReloadVirtualProperty = false;
					}
					int[] items = m_cache.GetVectorProperty(m_owningObject.Hvo, m_flid, true);

					// Identify all remaining dummy items
					if (m_fConvertRemainingDummiesOnIdle)
					{
						m_remainingDummiesToConvertOnIdle.Clear();
						for (int i = 0; i < items.Length; ++i)
						{
							if (m_cache.IsDummyObject(items[i]))
								m_remainingDummiesToConvertOnIdle.Add(items[i]);
						}
					}
					fdoObjs = new FdoObjectSet<ICmObject>(m_cache, items, false);
				}
				if (handler is BaseFDOPropertyVirtualHandler)
					(handler as BaseFDOPropertyVirtualHandler).Progress = null;
				return fdoObjs;
			}
			return null;
		}
示例#21
0
		/// <summary>
		/// Get an agent's evaluation of this Wordform.
		/// </summary>
		/// <param name="hvoAgent"></param>
		/// <returns></returns>
		public ICmAgentEvaluation GetEvaluationFromAgent (int hvoAgent)
		{
			string query = string.Format("select id, class$ from CmAgentEvaluation_ " +
				"where target={0} and owner$={1}", m_hvo, hvoAgent);

			FdoObjectSet<ICmAgentEvaluation> evaluations = new FdoObjectSet<ICmAgentEvaluation>(m_cache, query, false);
			Debug.Assert( evaluations.Count < 2,  "program error: there should not be more than one evaluation on this Wordform from this agent.");
			return evaluations.FirstItem;


		}
示例#22
0
		/// <summary>
		///
		/// </summary>
		/// <param name="hvos"></param>
		/// <param name="v"></param>
		protected void AssertMatchingCountAndOrder(int[] hvos, FdoObjectSet<ICmObject> v)
		{
			Assert.AreEqual(hvos.Length, v.Count, "Count was not preserved.");

			int i = 0;
			foreach(ICmObject o in v)
			{
				Assert.AreEqual(hvos[i], o.Hvo, "Order was not preserved.");
				i++;
			}

		}
示例#23
0
		public void PreserveHvoCountAndOrder ()
		{
			CheckDisposed();

			int[] hvos = GetHvosForFirstNObjectsOfClass(m_fdoCache.LangProject.PeopleOA.PossibilitiesOS.HvoArray, CmPerson.kClassId, 5);

			//mess with the order
			int h = hvos[0];
			hvos[0] = hvos[3];
			hvos[3] = h;

			// duplicate that last one to check for preserving duplicates (which is necessary for reference sequence attrs)
			hvos[4] = h;

			FdoObjectSet<ICmObject> v = new FdoObjectSet<ICmObject>(m_fdoCache, hvos, true);
			AssertMatchingCountAndOrder(hvos, v);

			// test when we give the signature, too
			v = new FdoObjectSet<ICmObject>(m_fdoCache, hvos, true, typeof(CmPerson));
			AssertMatchingCountAndOrder(hvos, v);
		}
示例#24
0
		// This finds all the lex entries that match in either citation form or lexeme form.
		// That's too many, but not by much, compared to a previous version that loaded the
		// whole collection!
		internal static List<ILexEntry> GetHomographList(FdoCache cache, string sForm)
		{
			List<ILexEntry> entries = new List<ILexEntry>();
			if (cache.DatabaseName == null || cache.DatabaseName == string.Empty)
			{
				// running tests...don't have a real database connection, so can't do SQL optimization.
				// Note that the main tests involving homographs use a real connection, but there
				// is at least one test involving them (RDEMerge) where that is not the focus of the test.
				// Just use all the entries in this case.
				entries.AddRange(cache.LangProject.LexDbOA.EntriesOC.ToArray());
				return entries;
			}

			string sql = "declare @sForm NCHAR(4000)"
				+ " set @sForm = ?"
				+ " select co.id, co.class$ from CmObject co "
				+ " join (select obj from LexEntry_CitationForm where Txt= @sForm"
				+ " union select lelf.Src as obj from LexEntry_LexemeForm lelf "
				+ " join MoForm_Form mff on lelf.Dst = mff.Obj and mff.Txt=@sForm) as objects on co.id = objects.obj";

			FdoObjectSet<ILexEntry> homographs = new FdoObjectSet<ILexEntry>(cache, sql, sForm);
			foreach (ILexEntry entry in homographs)
				entries.Add(entry);
			return entries;
		}
示例#25
0
		protected ArrayList MakeSortItemsFor(int[] hvos)
		{
			FdoObjectSet<ICmObject> newObjs = new FdoObjectSet<ICmObject>(m_cache, hvos, false);
			ArrayList newSortedObjects = new ArrayList(newObjs.Count);
			foreach (ICmObject obj in newObjs)
			{
				MakeItemsFor(newSortedObjects, obj);
			}
			return newSortedObjects;
		}